unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.93k stars 725 forks source link

Uno.UI.SourceGenerators generates duplicate values with .NET SDK 6.0.302 (enabled by global.json) #9304

Closed inforithmics closed 2 years ago

inforithmics commented 2 years ago

Current behavior

Uno.UI.SourceGenerators generates duplicate values (for example Duplicate 'System.Runtime.CompilerServices.CompilerGeneratedAttribute)

Expected behavior

Does not duplicate values and works.

How to reproduce it (as minimally and precisely as possible)

Make Uno Default Project

1) dotnet new uno unoapp-uwp-net6 Mapsui.Samples.Uno 2) add global.json does not work

{
  "sdk": {
    "allowPrerelease": false,
    "version": "6.0.302"    
  },
  "tools": {
    "dotnet": "6.0.302"
  }
}

3) Open with Visual Studio 2022 Preview Mapsui.Samples.Uno.sln 4) Build Mapsui.Samples.Uno.Skia.Wpf

Workaround

Workaround is to add following global.json

{
  "sdk": {
    "allowPrerelease": false,
    "version": "6.0.301"    
  },
  "tools": {
    "dotnet": "6.0.301"
  }
}

or set a sdk version not 6.0.302

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

4.4.13

Affected platforms

Skia (WPF)

IDE

Visual Studio 2022

IDE version

17.3 (Preview)

Relevant plugins

Resharper Version 2022.2

Anything else we need to know?

I looked at this, but didn't find something yet.

https://platform.uno/docs/articles/uno-development/troubleshooting-source-generation.html

This project uses nuget Central Package Management. Scripts\DisableCentralPackageManagement.ps1 can be used to disable CentralPackageManage-ment (The error still occours).

It seems that all Generated Code is generated more than 1 Time causing this duplicate messages. But I checked annd the Shared Project is only referenced once. I also removed the shared project and added it again still no success.

Sample Error Messages

image

Enabeling <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>

Produces valid c# Files

inforithmics commented 2 years ago

Here the Binlog Output Uno.Skia.Wpf.binlog.zip It seems an msbuild problem because csc compiler and sourcegenerator seem to work.

inforithmics commented 2 years ago

1) Steps tried Disabling Resharper, stll does not work. Changing Microsoft.Net.Compilers.Toolset Version still does not work (newer Prerelease or older Release Version) Using Visual Studio 2022 (instead of Preview) still does not work.

inforithmics commented 2 years ago

I found out the Reason and a Minimal Repro. The reason is that Uno.Skia.Wpf is not compatible with .NET SDK 6.0.302 with .NET SDK 6.0.301 it works.

Steps to reproduce.

Make Uno Default Project 1) dotnet new uno unoapp-uwp-net6 Bug 2) add global.json does not work

{
  "sdk": {
    "allowPrerelease": false,
    "version": "6.0.302"    
  },
  "tools": {
    "dotnet": "6.0.302"
  }
}

3) add global.json does work

{
  "sdk": {
    "allowPrerelease": false,
    "version": "6.0.301"    
  },
  "tools": {
    "dotnet": "6.0.301"
  }
}

So the Workaround is using .NET SDK 6.0.301 which works and .NET SDK 6.0.302 does not work.

jeromelaban commented 2 years ago

Thanks for the investigation! There may be a unknown breaking between SDK versions. We'll see what we can find.

jeromelaban commented 2 years ago

This issue is caused by https://github.com/dotnet/wpf/pull/6534, tracked in https://github.com/dotnet/wpf/issues/6792. See https://github.com/dotnet/wpf/issues/6792#issuecomment-1183471065 for the resolution.