msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Create a .NET TaskHost so that .NET Framework MSBuild can consume .NET Tasks

Open rainersigwald opened this issue 6 years ago โ€ข 15 comments

Task declaration supports a Runtime attribute that allows MSBuild-running-on-.NET-4 to call tasks that support only .NET 3.5 (by spawning an MSBuildTaskHost.exe that runs on .NET 3.5 and communicates with the rest of the build via IPC).

Similar support could be used to support running .NET Core (or .NET Standard 2.1+) tasks from Visual Studio with Runtime="NET" (or something like that).

rainersigwald avatar Oct 21 '19 14:10 rainersigwald

A more immediate solution would be to allow Visual Studio to run the entire build on .NET Core.

That could be complemented by failing if .NET Framework-based MSBuild attempted to run a task marked with Runtime="Core".

teo-tsirpanis avatar Feb 05 '21 16:02 teo-tsirpanis

Is this on the roadmap?

john-larson avatar Apr 18 '21 12:04 john-larson

@john-larson "yes" in the sense "we still think this is a good idea worth doing sometime hopefully soon", but "no" in the "we have a planned time to work on this".

rainersigwald avatar May 05 '21 17:05 rainersigwald

@rainersigwald, just wondering if there are any ways to run the code in a newer runtime? I am looking for workarounds.

Denis535 avatar Sep 10 '21 08:09 Denis535

@Denis535 the best option at the moment to run code during a .NET Framework/Visual Studio-driven build is to use an executable; then you can use anything that will run on the machine.

rainersigwald avatar Sep 10 '21 08:09 rainersigwald

Similar support could be used to support running .NET Core (or .NET Standard 2.1+) tasks from Visual Studio withย Runtime="Core"

OR vice-versa, i.e. running full framework tasks from Core MSBuild via Runtime="CLR2/CLR4"

Nirmal4G avatar Sep 10 '21 08:09 Nirmal4G

OR vice-versa, i.e. running full framework tasks from Core MSBuild via Runtime="CLR2/CLR4"

@Nirmal4G that's #711

rainersigwald avatar Sep 10 '21 09:09 rainersigwald

Yeah, it seems I'm the one marked the issue but forgot entirely. Silly me ๐Ÿ˜œ๐Ÿ™ƒ

Nirmal4G avatar Sep 10 '21 09:09 Nirmal4G

I am particularly interested in seeing this implemented. Is there a way for a community member to help?

teo-tsirpanis avatar Oct 23 '22 15:10 teo-tsirpanis

@teo-tsirpanis Unfortunately, I think most of the work for this is

  • building consensus on direction with VS partners
  • deciding on some VS-specific implementation details
  • making VSIX authoring changes that can only be tested by triggering internal VS test builds

which makes it pretty hard to help externally.

Can you expand on your desire for the feature though? Having clear use cases can help us prioritize it internally.

rainersigwald avatar Oct 25 '22 15:10 rainersigwald

I have an MSBuild task that runs after compilation and executes code from the compiled assembly using AssemblyLoadContext, necessiating targeting modern .NET. To support the .NET Framework edition of MSBuild Visual Studio runs I tried to do the same with AppDomains but gave up; I could not make it load the assembly's dependencies, and the complete object isolation of app domains would affect the structure of my code.

So what I did is run the task out-of-process on modern .NET when we build on .NET Framework, but this presents its own challenges. The out-of-process tool has to be installed separately (to avoid increasing package size for everyone), sending logging messages requires additional ceremony ~~, and there are issues around targeting frameworks greater than the tool (the tool runs on .NET 6 and cannot load .NET 7 assemblies, while the in-process task runs on the same framework as the SDK and does not have this problem)~~.

Implementing this would reduce complexity in my code and improve the user experience.

teo-tsirpanis avatar Oct 25 '22 18:10 teo-tsirpanis

Is this feature coming in .Net 8?

Jinjinov avatar Aug 03 '23 20:08 Jinjinov

No, it's not planned for the .NET 8 GA release this fall.

baronfel avatar Aug 03 '23 20:08 baronfel

This feature is a part of net10 & VS2026. Please give it a try!

YuliiaKovalova avatar Nov 20 '25 10:11 YuliiaKovalova

Great news! (I was just going to tag @ViktorHofer (for runtime repo) but saw he has already reacted ๐Ÿ˜‰)

am11 avatar Nov 20 '25 10:11 am11