https://github.com/Microsoft/msbuild/issues/2158 was closed in favor of https://github.com/Microsoft/msbuild/issues/304, the latter was closed in favor of Jeff's RoslynCodeTaskFactory.
This issue is to get the answer whether we will have CodeTaskFactory in MSBuild.
We do not have any plans to do so in the near future, since RoslynCodeTaskFactory enables the functionality in a cross-platform way.
I assume you're asking because you want it. Can you elaborate about your use case? You might be able to persuade us to consider it again.
CodeTaskFactory is documented in UsingTask docs for users to write code fragments in project or targets files that runs at (pre/post) build time. It is an extremely useful and flexible tech in automation scenarios, where we aren't required to precompile the build tool. Its absence in MSBuild for .NET Core is a big minus for me as we have used the ootb UsingTask with code fragment heavily in past with .NET Framework projects.
RoslynCodeTaskFactory as interesting as it sounds has unfortunately not been a drop-in replacement of CodeTaskFactory for my existing code. After some digging, I was able to run some parts of my existing code to work with RCTF, but the experience is ... not quite there yet.
Many people have and will hit this issue and waste hours fixing/updating the legacy code if RCTF is the only way forward. Please reconsider to bring it back.
I recently needed a Zip task written in C# for a general-purpose "master" MSBuild project file that builds several projects and packs their generated output together into an application archive for deployment. The project file itself is language-agnostic without a target framework by design; it basically only defines some properties, runs some MSBuild tasks on application project files and packs the generated artefacts. It basically acts as some sort of platform-independent shell script replacement. Following the documentation for _MSBuild Inline Tasks_ I used the CodeTaskFactory for the C# zip fragment, but then also ran into the issue that .NET Core doesn't ship with any.
An external RoslynCodeTaskFactory is not helpful, as the project file shouldn't have any dependencies (requiring a restore target leading to issues with a missing target framework definition and so on).
In the end I added a RoslynCodeTaskFactory dependency to one of the application projects and defined a Zip proxy target in the application project that my build&pack project file invokes. This works for now, but is rather dirty and having a natively shipped CodeTaskFactory would certainly have simplified things, especially since it's probably one of MSBuild's most powerful features that painlessly allow one to quickly write tasks for missing functionality without resorting to external dependencies or adding another project for a compiled task extension.
@takerukoushirou the RoslynCodeTaskFactory can also be used as a project sdk instead of a nuget dependency:
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="RoslynCodeTaskFactory" Version="1.2.6" />
…
</Project>
There already is an ask for first-party in-box zip tasks at https://github.com/Microsoft/msbuild/issues/1781
@dasMulli thank you very much for the hints on using RoslynCodeTaskFactory as a project SDK (& your PR to enable that) and that Zip tasks may be added in the future.
I still ran into some issues with the required restore, but ultimately found a way that works for now without the need for any proxy targets.
Having an out-of-the-box working code task factory would–in my opinion–still be very useful due to the flexibility it adds for using MSBuild as a general-purpose building tool without having to worry about restoring the project first (especially if a .proj file is used as a platform-independent replacement for a shell script).
@dasMulli, I was actually having issues with RoslynCodeTaskFactory; as much as it sounds like a drop-in replacement of CodeTaskFactory, it is not. It produces errors due to missing in-box assemblies/namespaces (like basic stuff; System.IO.Path etc.). If the official CodeTaskFactory is discontinued, it makes me (and probably some other devs) sad, but still good to have a final decision. We can always create our custom msbuild task project and hook into build pipeline (but that requires manual compilation, whereas CodeTaskFactory is more like a c# script compiled on-the-fly by msbuild).
@kasper3 please open issues if you're having problems with RoslynCodeTaskFactory so I can fix them.
@jeffkl Where are the docs for RoslynCodeTaskFactory?
@binki, there are some good directions in the readme https://github.com/jeffkl/RoslynCodeTaskFactory/blob/master/README.md.
@jeffkl, I have the latest release and it is pretty stable. Thank you 💓
In its current form, could it be made as part of MSBuild by dropping Roslyn from the name, so we don't have to specify dependency in project?
@jeffkl can this be closed now since RoslynCodeTaskFactory has now shipped as built-in part of msbuild 15.8?
Do we need additional docs or change docs? probably soft-deprecating (changing the guidance in docs) CodeTaskFactory for RoslynCodeTaskFactory seems possible now.
@dasMulli yes, this can be closed.
More info on the RoslynCodeTaskFactory is available at: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-roslyncodetaskfactory?view=vs-2017
Most helpful comment
@dasMulli yes, this can be closed.
More info on the RoslynCodeTaskFactory is available at: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-roslyncodetaskfactory?view=vs-2017