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

dotnet publish returns Error MSB4062 "Microsoft.Build.Tasks.SGen" task could not be loaded from the assembly #10255

Open
ghost opened this issue May 7, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented May 7, 2019

We have an ASP.NET Core 2.1 application using the full framework (4.7) that references a .NET 4.6 class library that make SOAP calls (WebReference). Since 2016 we've been able to run dotnet publish in our CI process with no issues with VS 2017. Once we installed VS2019 on the same host this stopped working.

We suspect it's a problem with the dotnet CLI deciding which version of MSBuild to run.

We understand that there are some work-arounds that seem to get past it such as setting <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> (which we don't want to do) and it seems that running MSBuild directly instead of dotnet publish works but we wanted to report this issue here.

Steps to reproduce

  • Use a windows machine with VS 2017 Pro (v15.9.11) and VS 2019 Pro (16.0.2) installed, both with web workloads
  • Create a solution with two projects:
    • ASP.NET Core 2.1 with .NET Framework 4.7 which references a...
    • .NET 4.6 Class Library Project
  • Add a Web Reference to the class library project (i.e.http://www.dneonline.com/calculator.asmx)
  • Run dotnet publish --configuration Release -out c:\temp\foo

Here is a repo with an example.

Expected behavior

The publish operation works

Actual behavior

This error is thrown:

c:\code\sandbox\PublishBugExample\PublishBugExample>dotnet publish --configuration Release -o c:\temp\bug-demo
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 65.03 ms for c:\code\sandbox\PublishBugExample\PublishBugExample\PublishBugExample.csproj.
C:\Program Files\dotnet\sdk\2.1.602\Microsoft.Common.CurrentVersion.targets(3541,5): error MSB4062: The "Microsoft.Build.Tasks.SGen" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [c:\code\sandbox\PublishBugExample\ExampleWebServiceLib\ExampleWebServiceLib.csproj]

More info

It seems that running MSBuild works however and the publish output is almost identical compared to when dotnet publish was ran in the past:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild" /t:Publish /p:Configuration=Release;Out-Dir=C:\temp\foo

According to our build logs, the last successful time dotnet publish ran (before VS 2019 was installed), it reported using Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core you'll notice in the output above it reports using 16.0.450+ga8dc7f1d34 for .NET Core.

If dotnet publish is not the recommended way of publishing such configurations please provide guidance.

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.602
 Commit:    04475eb7cf

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.602\

Host (useful for support):
  Version: 2.1.9
  Commit:  dcedc87d22

.NET Core SDKs installed:
  2.1.403 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
@james-novino
Copy link

We have a similar issue, where we are getting the following build error

C:\Program Files\dotnet\sdk\2.2.100\Microsoft.Common.CurrentVersion.targets(3533,5): error MSB4062: The "Microsoft.Build.Tasks.SGen" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.

We have a Console Application running on netcoreapp2.1 the uses a library project that does WCF for a SOAP service, this SOAP service requires an XMLSerializers.dll for operation. But when setting the <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies> property for the library project we get the issue posted above.

Environment data:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.100
 Commit:    b9f2fa0ca8

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.100\

Host (useful for support):
  Version: 2.2.0
  Commit:  1249f08fed

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.504 [C:\Program Files\dotnet\sdk]
  2.2.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download```

@LucidObscurity
Copy link

LucidObscurity commented Jan 18, 2020

This is occurring again in SDK 3.1.1. My co-worker has 3.0.1 as the latest on his machine and does not have this issue.
EDIT: nevermind. I installed SDK 3.0.100 on our TFS server and it did not resolve the issue. Not sure what is different on my co-workers machine.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@daniel-chambers
Copy link

We're having this issue with a dotnet build -c Release. In a release build, the SGen task is used to generate the XML serialization assembly, but not for Debug, so a Debug build succeeds, but a Release build fails.

However, if we build in Visual Studio 2019 instead of from the command line via dotnet, a Release build works.

We did some investigation and it seems the problem is that the version of the Microsoft.Build.Tasks.Core.dll that ships with .NET SDK does not contain the SGen task class at all, however, the same assembly included in Visual Studio 2019 does, which is why it builds in Visual Studio and not from the command line. This has to be a bug; surely they should be the same assemblies!

Version numbers for reference:

From Visual Studio 16.4.5:
image

From .NET SDK 3.1.102:
image

@quaz579
Copy link

quaz579 commented Mar 10, 2020

Has anyone figured out how to resolve this issue? We would really like to be able to build our code from a dotnet core sdk 3.1 docker container but this is preventing us from doing so.

@rainersigwald
Copy link
Member

If you want to use sgen.exe in your build, you must use MSBuild.exe (or Visual Studio), instead of dotnet build.

SGen.exe is part of the old .NET Framework SDK and hasn't been ported to .NET Core. The team that owns it does not plan to do so; the replacement is the Microsoft.XmlSerializer.Generator package.

The error message should be much clearer, though. I moved dotnet/msbuild#3583 into the next release; hopefully we can get that going soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants