-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running the compilation and loading the referenced assemblies. #1
Labels
Comments
fiseni
added
enhancement
New feature or request
help wanted
Extra attention is needed
labels
Apr 4, 2021
Hi! Any news on this matter? Do you think the same problem will arise if I try to emit IL code inside my generator using System.Reflection.Emit? |
I don't see any solution to this. |
This was referenced Jun 6, 2022
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this project, we have a bit more complex scenario. We're not generating some simple "static" content. Just looking at the source code is not enough for us. We have to run portions of the code, make some decisions and then generate appropriate content. And that's an issue if you're using Visual Studio and you're consuming the library from
.NET 5
project.The general workflow is the following:
GeneratorExecutionContext
to the source generators.This would work in any environment, no problem here. But, in our case, during step 3, we do actually emit the compilation and load the temporary assembly so we can execute the fluent configurations. And that's where the issue is.
If you're doing
dotnet build
then it's all fine. But, if you're building it through VS, everything is being executed in VS runtime context. If you doAppDomain.CurrentDomain.GetAssemblies()
you'll notice that the runtime is.NET Framework
(not a surprise), or if you checkGetCurrentDirectory()
you'll see a VS app path (\Program Files...). So, in this case, executing the temp assembly will fail, since will fail to load NET5 runtime. It gets even more complicated if there is a need to load referenced assemblies. I tried all kinds of stuff, even considered manually parsing the syntax tree (that's just an insane idea, btw).There is an active issue on Roslyn here dotnet/roslyn#45060. Entity Framework team also has a similar scenario, and they need to run some code.
For now, this is my TypeResolver implementation.
I'd love it if anyone has a better solution to this, and any contribution is welcome. I'm far from an expert in this area, and I'm open to any suggestions.
The text was updated successfully, but these errors were encountered: