Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure using 15.8 RoslynCodeTaskFactory #3726

Closed
dasMulli opened this issue Sep 10, 2018 · 13 comments

Comments

@dasMulli
Copy link
Contributor

commented Sep 10, 2018

While trying to migrate off the NuGet package to the 15.8 RoslynCodeTask factory, I'm encountering issues getting the most basic tasks to work.

E.g. copying from the documentation https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-roslyncodetaskfactory?view=vs-2017#hello-world to a test.proj:

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
  <!-- This simple inline task displays "Hello, world!" -->  
  <UsingTask  
    TaskName="HelloWorld"  
    TaskFactory="RoslynCodeTaskFactory"  
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >  
    <ParameterGroup />  
    <Task>  
      <Reference Include="System.Xml"/>
      <Using Namespace="System"/>  
      <Using Namespace="System.IO"/>  
      <Code Type="Fragment" Language="cs">  
<![CDATA[  
// Display "Hello, world!"  
Log.LogError("Hello, world!");  
]]>  
      </Code>  
    </Task>  
  </UsingTask>  
    <Target Name="Hello">  
    <HelloWorld />  
  </Target>  
</Project>

Windows full framework (15.8.3):

"C:\Users\martin.ullrich\Downloads\testproj\test.proj" (Hello target) (1) ->
(Hello target) ->
  C:\Users\martin.ullrich\Downloads\testproj\test.proj(21,5): error MSB3755: Could not find reference "System.Xml". If this reference is required by your code, you may
 get compilation errors.
  C:\Users\martin.ullrich\Downloads\testproj\test.proj(21,5): error MSB4175: The task factory "RoslynCodeTaskFactory" could not be loaded from the assembly "C:\Program
 Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\Microsoft.Build.Tasks.Core.dll". The task factory must return a value for the "TaskType" property
.

MacOS dotnet 2.1.401:

/Users/martin/tmp/testsln/test.proj/test.proj(21,5): error MSB3755: Could not find reference "System.Xml". If this reference is required by your code, you may get compilation errors.
/Users/martin/tmp/testsln/test.proj/test.proj(21,5): error MSB3755: Could not find reference "mscorlib". If this reference is required by your code, you may get compilation errors.
/Users/martin/tmp/testsln/test.proj/test.proj(21,5): error MSB3755: Could not find reference "netstandard". If this reference is required by your code, you may get compilation errors.
/Users/martin/tmp/testsln/test.proj/test.proj(21,5): error MSB4175: The task factory "RoslynCodeTaskFactory" could not be loaded from the assembly "/usr/local/share/dotnet/sdk/2.1.401/Microsoft.Build.Tasks.Core.dll". The task factory must return a value for the "TaskType" property.

cc @jeffkl

@dasMulli dasMulli changed the title Failure using 5 Failure using 15.8 RoslynCodeTaksFactory Sep 10, 2018

@nathansoz

This comment has been minimized.

Copy link

commented Sep 21, 2018

I was also seeing this behavior with the same error message.

@dasMulli

This comment has been minimized.

Copy link
Contributor Author

commented Oct 5, 2018

@jeffkl or @rainersigwald, @cdmihai could you please take a look?

@dasMulli

This comment has been minimized.

Copy link
Contributor Author

commented Oct 6, 2018

It should be noted that the same code just works using the RoslynCodeTaskFactory NuGet package from https://github.com/jeffkl/RoslynCodeTaskFactory

@Cyrus-d

This comment has been minimized.

Copy link

commented Nov 2, 2018

I have the same problem, the project builds fine when using visual studio, but it will throw error when running cli 'dotnet build'.

@jeffkl

This comment has been minimized.

Copy link
Contributor

commented Nov 20, 2018

The root cause of the bug is that the Microsoft.Build.Tasks project is copying the ref assemblies to its target framework output folder (net46 and netstandard2.0). The MSBuild project is then including them in the NuGet package for its target frameworks (net46, netcoreapp2.0, and netcoreapp2.1). So the files are in the correct place but aren't being included in the NuGet package.

So an easy workaround is to copy the ref folder from the full framework location ( the files are the same ) and we can look into fixing this for the next release of .NET Core.

@jeffkl jeffkl added the bug label Nov 20, 2018

@jeffkl jeffkl changed the title Failure using 15.8 RoslynCodeTaksFactory Failure using 15.8 RoslynCodeTaskFactory Nov 20, 2018

rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Nov 20, 2018
Pack ref assemblies with all TFs
RoslynCodeTaskFactory fails on .NET Core because it can't find a local
copy of netstandard.dll to compile against. It was not packed because
Microsoft.Build.Tasks.csproj binplaced it into TFM folders for its own
TFs, which don't match MSBuild.csproj's, which were used for the
packaging logic.

Fixes microsoft#3726.
@octaviobffernandes

This comment has been minimized.

Copy link

commented Jan 8, 2019

I am using msbuild version 15.9.20+g88f5fadfbe with .netcore 2.1 and I am still experiencing error below. Any idea when it is being fixed?

error MSB4175: The task factory "RoslynCodeTaskFactory" could not be loaded from the assembly "C:\Program
Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\Microsoft.Build.Tasks.Core.dll". The task factory must return a value for the "TaskType" property.

For now, my workaround is still to reference external dependency from https://github.com/jeffkl/RoslynCodeTaskFactory

@mhutch

This comment has been minimized.

Copy link
Member

commented Jan 10, 2019

@radical I'm also seeing this in the msbuild 16.0.42-preview+g804bde742b bundled with Mono 5.18.0.234

@rainersigwald rainersigwald added this to the MSBuild 16.0 milestone Feb 8, 2019

@Daniel15

This comment has been minimized.

Copy link

commented Feb 17, 2019

Until the fix is released, is there a workaround for this?

@DanVicarel

This comment has been minimized.

Copy link

commented Apr 8, 2019

Argh, still seeing this issue in VS 2019 (16.0.0). Any System.* <Reference>s that I try to add to an inline task in my .NET Standard project are yielding:

Could not find reference "System.*". If this reference is required by your code, you may get compilation errors.

@jeffkl @rainersigwald Are there other reports of a regression with this?

@dasMulli

This comment has been minimized.

Copy link
Contributor Author

commented Apr 8, 2019

Do you need these references? They shouldn’t be necessary since all the surface area should be covered by netstandard.dll and mscorlib.dll

@thomasvdb

This comment has been minimized.

Copy link

commented Apr 17, 2019

@dasMulli Having the same issue as @DanVicarel but on macOS.
It also throws errors on mscorlib and netstandard hence the error of RoslynCodeTaskFactory.

error MSB3755: Could not find reference "mscorlib". If this reference is required by your code, you may get compilation errors]
error MSB3755: Could not find reference "netstandard". If this reference is required by your code, you may get compilation errors.
error MSB4175: The task factory "RoslynCodeTaskFactory" could not be loaded from the assembly "/usr/local/share/dotnet/sdk/2.2.103/Microsoft.Build.Tasks.Core.dll". The task factory must return a value for the "TaskType" property.
@rainersigwald

This comment has been minimized.

Copy link
Contributor

commented Apr 17, 2019

@thomasvdb SDK 2.2.103 includes MSBuild 15.9, but this was fixed only in MSBuild 16.0 (in SDK 2.2.200 and higher).

@couven92

This comment has been minimized.

Copy link

commented May 22, 2019

I am still getting this problem using MSBuild bundled with the latest .NET Core release (downloaded using dotnet-install.ps1) using MSBuild (.NET Core) version 16.1.19!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.