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

SGen on .NET Core should point to Microsoft.XmlSerializer.Generator package #3583

Closed
rainersigwald opened this issue Aug 6, 2018 · 6 comments · Fixed by #5212
Closed

SGen on .NET Core should point to Microsoft.XmlSerializer.Generator package #3583

rainersigwald opened this issue Aug 6, 2018 · 6 comments · Fixed by #5212
Assignees
Labels
Area: Tasks Issues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll. .NET Core triaged

Comments

@rainersigwald
Copy link
Member

In the early days of .NET Core there was no sgen, and we didn't port the sgen task.

There's a new .NET Core serializer generator: https://github.com/dotnet/corefx/issues/25138. Docs at https://github.com/dotnet/core/blob/master/samples/xmlserializergenerator-instructions.md.

We should promote that when someone attempts to use the SGen task on .NET Core. Probably just emit an error pointing to an aka.ms link to those docs?

cc @huanwu in case there's a better thing to do.

@rainersigwald
Copy link
Member Author

New docs at https://docs.microsoft.com/dotnet/core/additional-tools/xml-serializer-generator

The fix for this will probably look like #3987, which did the same thing (nicer error for a task that doesn't exist on Core) for a different task.

@donJoseLuis, this might be a good starter issue for you.

@donJoseLuis
Copy link

To reproduce:

  1. Create a class library project
  2. Add the following to the project file...
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
    </PropertyGroup>
  3. OR in VS set properties\build\Generate serialization assembly to On
  4. attempt to build

Outcome:

C:...\3.1.101\Microsoft.Common.CurrentVersion.targets(3544,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 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:\tmp\tmp.csproj]
0 Warning(s)
1 Error(s)

@ladipro ladipro self-assigned this Mar 27, 2020
@ladipro
Copy link
Member

ladipro commented Mar 27, 2020

I see SGen failing in these scenarios:

  1. The .NET Core version of MSBuild is unable to execute the SGen task:
    a. When building a project targeting .NET Core.
    b. When building a project targeting .NET Framework.
  2. The .NET Framework version of MSBuild is unable to execute the SGen task when building a project targeting .NET Core.

@donJoseLuis, @rainersigwald , am I right in assuming that we want to point the developer to the new Microsoft.XmlSerializer.Generator in 2. and 1a. but not in 1b.? For 1b. we just tell them that this is not supported on the .NET Core version of MSBuild. In other words, we need to detect the platform both at our build time and at run time.

@rainersigwald
Copy link
Member Author

  • The .NET Core version of MSBuild is unable to execute the SGen task:
    a. When building a project targeting .NET Core.
    b. When building a project targeting .NET Framework.

Correct--the task is currently just not built on Core at all.

2. The .NET Framework version of MSBuild is unable to execute the SGen task when building a project targeting .NET Core.

I think this actually works? But ideally yes we should emit the message there, too. I was envisioning that as out of scope for this work item, but if you wanted to be ambitious about it feel free :)

@ladipro
Copy link
Member

ladipro commented Mar 27, 2020

I'm afraid 2. is also failing, although it seems to be coming from SGen itself:

SGEN : error : An attempt was made to load an assembly with an incorrect format: C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\Microsoft.VisualBasic.Core.dll. [C:\src\_test\MyApp\MyApp.csproj]

Arguably, this error is even less user friendly than what you get on Core and my understanding is that this is a fairly common scenario as well since building a Core project in VS gets you here. Let's get ambitious :)

@ladipro
Copy link
Member

ladipro commented Mar 31, 2020

I have opened a PR to implement an empty SGen task on Core. The other issue where SGen is failing when invoked by the Framework version of MSBuild when building a Core project is being discussed in dotnet/core#2716.

ladipro added a commit that referenced this issue Apr 3, 2020
The SGen task has not been implemented on .NET Core and building a project with `<GenerateSerializationAssemblies>` is failing with what looks like an infrastructure error.

This PR is adding an empty implementation of the task which throws a nicer error pointing the user to the build-time serialization mechanism supported on .NET Core - Microsoft.XmlSerializer.Generator. The changes here are analogous to how the ResolveComReference task has been implemented to allow erroring out on Core.

Fixes #3583
sfoslund pushed a commit to sfoslund/msbuild that referenced this issue May 15, 2020
The SGen task has not been implemented on .NET Core and building a project with `<GenerateSerializationAssemblies>` is failing with what looks like an infrastructure error.

This PR is adding an empty implementation of the task which throws a nicer error pointing the user to the build-time serialization mechanism supported on .NET Core - Microsoft.XmlSerializer.Generator. The changes here are analogous to how the ResolveComReference task has been implemented to allow erroring out on Core.

Fixes dotnet#3583
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Tasks Issues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll. .NET Core triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants