RoslynCodeTaskFactory: The task factory "CodeTaskFactory" could not be loaded from the assembly
See original GitHub issueSteps to reproduce
VS2019 win10 .net core console project v3.1 dotnet --version: 3.1.400-preview-015178
error MSB4175: The task factory “CodeTaskFactory” could not be loaded from the assembly “C:\Users\xx.nuget\packages\roslyncodetaskfactory\1.2.6\build\netstandard1.5\RoslynCodeTaskFactory.dll”. Method not found: ‘System.Xml.XmlNodeType System.Xml.Linq.XObject.get_NodeType()’.
Project file
<UsingTask
TaskName="CustumCodeTask"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(RoslynCodeTaskFactory)"
Condition=" '$(RoslynCodeTaskFactory)' != '' ">
<ParameterGroup />
<Task>
<Reference Include="System.Xml" />
<Using Namespace="System" />
<Using Namespace="System.Collections.Generic" />
<Using Namespace="System.Xml" />
<Using Namespace="System.Xml.Linq" />
<Code Type="Fragment" Language="cs">
<![CDATA[
<!--public static void ScriptMain() {-->
List<string> list = new List<string>();
list.Add("Happy");
list.Add("New");
list.Add("Year");
Console.WriteLine("Hello MSBuild Community Scripting World.");
foreach(string s in list)
{
Console.WriteLine(s);
}
<!--}-->
]]>
</Code>
</Task>
</UsingTask>
Command line
dotnet msbuild -v:d -t:CustumCodeTask
Expected behavior
see the messages
Actual behavior
error MSB4175: The task factory “CodeTaskFactory” could not be loaded from the assembly “C:\Users\xx.nuget\packages\roslyncodetaskfactory\1.2.6\build\netstandard1.5\RoslynCodeTaskFactory.dll”. Method not found: ‘System.Xml.XmlNodeType System.Xml.Linq.XObject.get_NodeType()’.
Environment data
msbuild /version output:
Microsoft ® Build Engine version 16.6.0+5ff7b0c9e for .NET Framework
16.6.0.22303
OS info: win 10 x64 If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):
dev console for VS2019 win10 .net core console project v3.1 (VS2019) dotnet --version: 3.1.400-preview-015178
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Related StackOverflow Question
The RoslynCodeTaskFactory that you’re using is technically from here: https://github.com/jeffkl/RoslynCodeTaskFactory/
I’ve since built it into MSBuild so you don’t need to reference it as a package.
I think you just need to change the name of the task factory to RoslynCodeTaskFactory. The below sample works great:
Ok, it works when I use: