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.9k stars 721 forks source link

Building with the .NET 8 SDK forces Uno.SourceGenerators to run #12862

Closed jeromelaban closed 1 year ago

jeromelaban commented 1 year ago

Good day, Uno Platform team. I notice that Uno Platform .Net 8 is not build without <UnoUIUseRoslynSourceGenerators>true</UnoUIUseRoslynSourceGenerators> parameter.

If I will change the UnoUIUseRoslynSourceGenerators parameter to false, I will catch following compilation error:

1>MSBUILD : error : Generation failed: System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Generation failed for Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator. System.AggregateException: One or more errors occurred. ---> System.Exception: Processing failed for file C:\Users\mykyt\OneDrive\Робочий стіл\UnoAppNetEight\UnoAppNetEight\Presentation\Shell.xaml (System.ArgumentException: An item with the same key has already been added.
1>MSBUILD : error :    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
1>MSBUILD : error :    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
1>MSBUILD : error :    at Uno.UI.SourceGenerators.XamlGenerator.GenerationRunFileInfo.SetAppliedTypes(Dictionary`2 appliedTypes) in /home/vsts/work/1/s/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationRunFileInfo.cs:line 19
1>MSBUILD : error :    at Uno.UI.SourceGenerators.XamlGenerator.XamlFileGenerator.InnerGenerateFile() in /home/vsts/work/1/s/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:line 354
1>MSBUILD : error :    at Uno.UI.SourceGenerators.XamlGenerator.XamlFileGenerator.GenerateFile() in /home/vsts/work/1/s/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:line 315) ---> System.ArgumentException: An item with the same key has already been added.
1>MSBUILD : error :    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
1>MSBUILD : error :    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
1>MSBUILD : error :    at Uno.UI.SourceGenerators.XamlGenerator.GenerationRunFileInfo.SetAppliedTypes(Dictionary`2 appliedTypes) in /home/vsts/work/1/s/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationRunFileInfo.cs:line 19
1>MSBUILD : error :    at Uno.UI.SourceGenerators.XamlGenerator.XamlFileGenerator.InnerGenerateFile() in /home/vsts/work/1/s/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:line 490
1>MSBUILD : error :    at Uno.UI.SourceGenerators.XamlGenerator.XamlFileGenerator.GenerateFile() in /home/vsts/work/1/s/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:line 315
1>MSBUILD : error :    --- End of inner exception stack trace ---
1>MSBUILD : error :    at Uno.UI.SourceGenerators.XamlGenerator.XamlFileGenerator.GenerateFile() in /home/vsts/work/1/s/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:line 323
1>MSBUILD : error :    at Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGeneration.<>c__DisplayClass178_0.<Generate>b__2(XamlFileDefinition file) in /home/vsts/work/1/s/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlCodeGeneration.cs:line 444
1>MSBUILD : error :    at System.Linq.Parallel.PartitionedDataSource`1.ListContiguousIndexRangeEnumerator.MoveNext(T& currentElement, Int32& currentKey)
1>MSBUILD : error :    at System.Linq.Parallel.StopAndGoSpoolingTask`2.SpoolingWork()
1>MSBUILD : error :    at System.Linq.Parallel.SpoolingTaskBase.Work()
1>MSBUILD : error :    at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
1>MSBUILD : error :    at System.Threading.Tasks.Task.Execute()

I have a proposition to add this parameter as default with Uno Platform .Net 8 creating project.

Visual Studio: 17.7.0 Preview 2.0 Uno Platform: 4.9.17.18 Dotnet sdk-list:

7.0.400-preview.23274.1 [C:\Program Files\dotnet\sdk]
8.0.100-preview.2.23157.25 [C:\Program Files\dotnet\sdk]

Summary of project creating:

build output uno platform net 8.txt

Originally posted by @limeniye in https://github.com/unoplatform/uno/discussions/12848

jeromelaban commented 1 year ago

This issue happens because LangVersion is not defined anymore when running under the .NET 8 SDK. This is not an issue anymore with master directly, since embedded Roslyn generators are used, but this needs to be fixed in 4.x.

limeniye commented 1 year ago

The steps to thow this issue:

Create new Uno Platform Application with following parameters:

Try to build your shared project.

Expectation: build should be successed Result: Xaml generation error

After that try to use the following steps:

Result: rebuild will be successfull.

https://github.com/unoplatform/uno/assets/69314237/34434e11-b223-4c60-b4e7-206c58630847