dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

Clearer message that running .NET Framework MSBuild in a .NET process is unsupported #10574

Open maridematte opened 2 months ago

maridematte commented 2 months ago

Originating from https://github.com/dotnet/msbuild/pull/10175 discussion.

The scenario of running .NET Framework MSBuild in a .NET process is unsupported, but it worked until a recent change. Since there is some confusion around this, identifying and breaking this scenario with a specific message would be ideal.

rainersigwald commented 2 months ago

A wrinkle here is that our API has a lot of entry points. However an exception in the evaluator would probably catch almost everything.

KalleOlaviNiemitalo commented 2 months ago

Can ModuleInitializerAttribute be used for this? It would cause the exception to be wrapped in TypeInitializationException, though.

.NET Framework does not provide the System.Runtime.CompilerServices.ModuleInitializerAttribute type, but if you define a similar one as internal in MSBuild, then I think Roslyn will recognize it and set up the <Module>::.cctor method that the runtime will then call.