roslyn-sdk
roslyn-sdk copied to clipboard
Does Source Generator allow to reference a file from web?
Like we do in F# type providers. For example http://fsprojects.github.io/SwaggerProvider/#/#getting-started
You can run any .netstandard 2.0 code in a source generator. ~~This includes web requests.~~ You I would recommend using local files if you can so you do not make web requests every time someone types.
While a source generator might still execute if it performs I/O, the behavior of the output is undefined if the generator reads data from any location which is not part of the Compilation
passed to its initialization. For example:
- Source generators must not read files directly from disk (or the output is undefined)
- Source generators must not read data from web requests (or the output is undefined)
- Source generators must not read environment variables at the time of execution (or the output is undefined)
If you need access to data from one of these sources, it must be provided by modifying the build to obtain the items before compilation, and add the data to the compilation (e.g. by downloading at item from the web and including it through <AdditionalFiles>
). Any targets used for this need to adhere to the MSBuild rules for up-to-date checks (beyond the scope of this answer).
/cc @jaredpar