msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

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

Open maridematte opened this issue 1 year ago • 2 comments

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.

maridematte avatar Aug 27 '24 15:08 maridematte

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

rainersigwald avatar Aug 27 '24 19:08 rainersigwald

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.

KalleOlaviNiemitalo avatar Aug 27 '24 20:08 KalleOlaviNiemitalo