dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.39k stars 10k forks source link

Blazor dotnet publish error Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.GroupExistingStaticWebAssets #39000

Closed DjeeBay closed 2 years ago

DjeeBay commented 2 years ago

I have a Blazor project recently upgraded from .NET 3.1 to 6.0 that cannot be published anymore due to the following error when publishing :

System.ArgumentException: An item with the same key has already been added Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.GroupExistingStaticWebAssets

The binlog shows that the problem comes from referenced assemblies (.dll) that I have in the Shared project. If I remove those assemblies the project can be published.

A simple repro can be done on a brand new Blazor wasm project, referencing a simple .dll that does nothing in the shared project. With .Net 6.0 publishing won't work, but with 5.0 it will.

Any chances that this will be fixed soon, or is there a workaround to manage to publish ?

TanayParikh commented 2 years ago

Hello @DjeeBay, thanks for reaching out. Can you confirm if you did a full project clean before attempting to publish in .NET 6? Please try deleting the bin & obj folders as well.

ghost commented 2 years ago

Hi @DjeeBay. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

DjeeBay commented 2 years ago

Hello @DjeeBay, thanks for reaching out. Can you confirm if you did a full project clean before attempting to publish in .NET 6? Please try deleting the bin & obj folders as well.

Hi @TanayParikh, yes I did and like I said I can reproduce on a brand new project to confirm this behavior with .NET 5.0 against .NET 6.0.

MariovanZeist commented 2 years ago

@DjeeBay I had a similar problem, it turned out there were 2 projects with the same content. Both projects had a "package.json" with their Build action set to content. setting the Build action to none fixed it for me.

DjeeBay commented 2 years ago

@MariovanZeist yes I saw that in some projects there are some identical filename issues (#38186, #37610, #35633) but not in my case. The build action didn't change anything either.

Just try to create a new Blazor wasm project, then create elsewhere a new standard 2.0 project, then add a reference of the standard 2.0 .dll into the Blazor Shared project.

You won't be able to publish with .NET 6.0, but with .NET 5.0 you will. (don't forget to use your dll, in WeatherForecast.cs for instance)

MariovanZeist commented 2 years ago

@DjeeBay Could you create a minimal repro? using your instructions ended up working for me, so possibly I didn't understand your instructions exactly.

DjeeBay commented 2 years ago

@MariovanZeist here we go : https://github.com/DjeeBay/BlazorNET6WontPublish

The "HelloStandard.dll" referenced in the Shared project does nothing, it's just a new standard 2.0 project.

MariovanZeist commented 2 years ago

@DjeeBay Thank you for the repo. I am able to reproduce your problem. But I don't know a solution.

TanayParikh commented 2 years ago

Hello @DjeeBay, I believe this issue may have been resolved in the most recent patch .NET 6.0.1, which will be coming out today. Could you please give that a try once it's available.

DjeeBay commented 2 years ago

Hello @TanayParikh, it works as expected now with .NET 6.0.101.

Great job !

TanayParikh commented 2 years ago

Great to hear, thanks for checking!