msbuild: Linux, MSBuild does not support the task factory "CodeTaskFactory"

I got the below error message when I tried to build csproj file in coreclr project.

error MSB4801: The task factory "CodeTaskFactory" could not be loaded because this version of MSBuild does not support it. [/home/jyoung/git/dotnet/coreclr_buildtestsh/tests/src/GC/Regressions/v2.0-beta2/462651/462651.csproj]

The MSBuild.exe version is 14.1 and it is downloaded by init-tools.sh from nuget.

root@jyoung-Samsung-DeskTop-System:/home/jyoung/git/dotnet/coreclr_buildtestsh/Tools# ./corerun MSBuild.exe /version
Microsoft (R) Build Engine version 14.1.0.0
Copyright (C) Microsoft Corporation. All rights reserved.

14.1.0.0

CoreClr creates GenerateParamList in CLRTest.Execute.targets like below. But as I know, the latest version does not support Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll. Instead we can use Microsoft.Build.Tasks.Core.dll. So I changed it but it still failed and the error msg was the same.

<UsingTask                                                                    
    TaskName="GenerateParamList"                                                
    TaskFactory="CodeTaskFactory"                                               
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">          

What can I do to fix it ?

(I tired to build msbuild too, because it also uses UsingTask element. But it built successfully and there is no distinction btw init-tools.sh in coreclr and init-tools.sh in msbuild. I think this issue might be related to CoreCLR envrionment. But I couldn’t find it…)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (8 by maintainers)

Most upvoted comments

For those arriving from search, see also: https://github.com/jeffkl/RoslynCodeTaskFactory

Any chance CodeTaskFactory will work one day on Core without 3rd party packages?

@iskiselev There’s no good way to write a single task assembly that works on MSBuild 4 or 12 and on .NET Core MSBuild. I’d suggest shipping multiple assemblies, one compiled against an old MSBuild and one compiled against the 14.1 assemblies, and using two <UsingTask>s conditioned on $(MSBuildAssemblyVersion).

@jyoungyun You can always compile your own task assembly as a DLL and load it from there, instead of compiling the assembly at build time with CodeTaskFactory. The full-framework instructions at https://msdn.microsoft.com/en-us/library/t9883dzc.aspx look good, except that the project should a) target the CoreCLR/.NET Standard 1.3 and b) reference the CoreCLR, 14.1 versions of MSBuild assemblies.