Question: How to write an MSBuild extension that is extensible
See original GitHub issueMoved from https://github.com/dotnet/sdk/issues/898 on behalf of @AArnott
I’m working to port my CodeGeneration.Roslyn MSBuild extension to .netstandard so that it works under dotnet build. The design is that folks can build on my SDK NuGet package to write their Roslyn-based code generator, and then the end user chains in my build-time NuGet package which “discovers” these code generation extensions and loads the code generator assemblies to do the work on my scaffolding.
In the conversion, I hit two major roadblocks from .netstandard limitations:
Assembly.LoadFileis missing. I understand this is coming in .netstandard 2.0 but is there any supported alternative in the meantime for an MSBuild Task to load some assembly based on its path? I mean, MSBuild Core itself can do it, so how is that done so I can emulate it?- No AppDomain support. This is super useful for two reasons: I can control the version of Roslyn assemblies that are loaded to the ones I was compiled against, thus avoiding assembly load failures. It also lets me unload these extension assemblies when I’m done with them so they don’t lock files on disk when the build is over (including VS in proc design-time builds). If MSBuild Core similarly keeps msbuild.exe processes running after a build, we have a significant problem, but if it doesn’t, I might omit AppDomain support from just the .netstandard build of this MSBuild Task, then cross my fingers and hope for the best about the Roslyn assembly versions.
Thoughts?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:20 (20 by maintainers)
Top Results From Across the Web
MSBuild Extension Pack simple tutorial
I am looking for a very simple example that shows what exactly is and how to use the MSBuild Extension Pack: http://msbuildextensionpack.
Read more >How MSBuild builds projects
Learn how MSBuild processes your project files, whether invoked from Visual Studio or from a command line or script.
Read more >Msbuild get directory name. props imported, or something ...
Your question has already been answered in another post here: MsBuild: Get ... The dotnet build and msbuild commands are equivalent when passing...
Read more >MSBuild Property Functions (2)
The project references a 64-bit assembly and you are using 32-bit MSBuild. Workaround: Make the library referred on the error target the AnyCPU...
Read more >Visual Studio Platform and Extensibility
We use simple .dll files (assemblies or native dynamic link libraries) for a few extension options. For example, we can add visualizers or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It seems to me that the use of ALC per task wouldn’t be blocked anymore since the CoreCLR bug has been fixed.
You can’t replace an assembly with another assembly in-place, other than doing EnC on the difference 😃. I think in a plugin system like msbuild the plugins need to be isolated in different ALCs and only msbuild assemblies that implement types used to communicate between the plugins be loaded in a default ALC. In such a model each ALC would only load assemblies that are known at build time of the plugin.
I’m bumping in to this myself: https://github.com/dotnet/sdk/issues/933