Sadly this is not working for the latest Arduino-ESP32 2.0.2 core because ESP-IDF lags behind (they need a special v4.4 version, PIO has v.4.3.x). Only a much older version can be compiled succesfully that way (Latest (Arduino v2.0.1) ESP32 Arduino and IDF Build - #3 by valeros). The developers need to fix this.
(If this were working with the latest version, then yes, this would have been 100% the best way to do this. Seems I subconously evaded this because I know it was not working in the latest version ;))