[Feature Request]: RoslynCodeTaskFactory compiling against .net 8.0
Danielku15 opened this issue · comments
Summary
There should be a way to create MSBuild inline tasks targeting the .net runtime of the host msbuild currently executing (e.g. from .net 8.0). As RoslynCodeTaskFactory targets only netstandard2.0 it is not possible to use various new functionalities like:
- System.IO.Compression
- System.Formats.Tar
- System.Text.Json
Background and Motivation
As of today the RoslynCodeTaskFactory compiles against netstandard2.0 for to compatibility reasons. While this is good for some scenarios, it limits the use newer features for environments where its known that only the latest .net runtime is used (not NetFx MSBuild).
We write various (build) scripts in MsBuilds and have various targets and tasks. I now hit the problem that I cannot process some files due to the fact that I cannot add references to newer runtime libs.
Proposed Feature
A new CodeTaskFactory with a different name (e.g. RoslynCurrentRuntimeCodeTaskFactory
) should be added to $(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll
which will use the current .net SDK as target. e.g. a "dotnet msbuild" with .net 8 should target net8.0 and allow use of respective libraries and language features.
Alternative Designs
I'm not deeply into the internals of the CodeTaskFactories but from what I've seen there are already some base classes to differenciate between C# and VB compilation. With some new properties to trigger the compilers differently it should be possible to produce an inline task with the same target as the current execution environment.
https://github.com/dotnet/msbuild/blob/main/src/Tasks/RoslynCodeTaskFactory/RoslynCodeTaskFactory.cs
https://github.com/dotnet/msbuild/blob/main/src/Tasks/RoslynCodeTaskFactory/RoslynCodeTaskFactoryCompilers.cs
The alternative I need to target now is to create a mini csproj + program.cs and use "dotnet run" instead of an inline task from msbuild.