dotnet / dotnet/msbuild

[Feature Request]: RoslynCodeTaskFactory compiling against .net 8.0

Open
#9,854 2 comments 4 reactions 0 assignees View on GitHub
Feature Request gathering-feedback needs-design triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.