dotnet / dotnet/aspnetcore

duplicated ProjectReferences to razor class libraries lead to builds failing because of FilterStaticWebAssetEndpoints

Open
#58,354 3 comments 1 reaction 0 assignees View on GitHub
area-ui-rendering
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

when upgrading my blazor website from .net8 to .net9 rc2, i moved a couple of shared ProjectReferences to razor class library projects into a Directory.build.props file, but forgot to delete those in all projects.
turns out, duplicated nodes are not a good thing, because the blazor tooling(i suspect) doesn't make them unique, properly.

this can be easily reproduced by just duplicating a node in the .csproj file. if that points to something not affected by the blazor tooling, it won't error. if it does, it will.
(maybe it's necessary for that razor class library to actually contain .razor.css files, but the binlog doesn't suggest that)

### Expected Behavior

either an error complaining about the duplicated ProjectReference in the .csproj or proper deduplication so it doesn't fail in the first place

### Steps To Reproduce

see this project:
https://github.com/AdmiralSnyder/ErrorRepros/tree/master/20241010_duplicated_projectreferences

repro workflow:
- create new blazor web app (i used .net9, but it might not matter)
- create a razor class library
- add a project reference to the web app
- go into the .csproj of the web app and duplicate the project reference
- --> the error appears.
- if you would instead have a "normal" class library referenced, and would duplicate that reference, there wouldn't be an error.

### Exceptions (if any)

C:\Program Files\dotnet\sdk\9.0.100-rc.1.24452.12\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.ScopedCss.targets(397,3): error MSB4018: The "FilterStaticWebAssetEndpoints" task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added. Key: D:\source\GVT\GVTShowcase\BlazorComponents\obj\Debug\net9.0\scopedcss\projectbundle\BlazorComponents.bundle.scp.css
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at System.Linq.Enumerable.SpanToDictionary[TSource,TKey,TElement](ReadOnlySpan`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Microsoft.AspNetCore.StaticWebAssets.Tasks.FilterStaticWebAssetEndpoints.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [D:\source\GVT\GVTShowcase\Contents\GVT\Contents.GVT\Contents.GVT.csproj]

### .NET Version

9.0.100-rc.1.24452.12

### Anything else?

If you want, i can add a binlog file to the repro repo.
Since this is circumvented easily, i can totally get if this issue isn't prioritized. a better error message would really be nice, though. Because _finding_ it required @davidwengier having a look at that binlog.

Thanks for looking into this ❤

here's the dotnet --info output:

dotnet --info
.NET SDK:
Version: 9.0.100-rc.1.24452.12
Commit: 81a714c6d3
Workload version: 9.0.100-manifests.67cd1eb6
MSBuild version: 17.12.0-preview-24422-09+d17ec720d

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100-rc.1.24452.12\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
[ios]
Installation Source: VS 17.12.35323.107
Manifest Version: 17.5.9270-net9-rc1/9.0.100-rc.1
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-rc.1\microsoft.net.sdk.ios\17.5.9270-net9-rc1\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 17.12.35323.107
Manifest Version: 35.0.0-rc.1.80/9.0.100-rc.1
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-rc.1\microsoft.net.sdk.android\35.0.0-rc.1.80\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 17.12.35323.107
Manifest Version: 9.0.0-rc.1.24453.9/9.0.100-rc.1
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-rc.1\microsoft.net.sdk.maui\9.0.0-rc.1.24453.9\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: VS 17.12.35323.107
Manifest Version: 17.5.9270-net9-rc1/9.0.100-rc.1
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-rc.1\microsoft.net.sdk.maccatalyst\17.5.9270-net9-rc1\WorkloadManifest.json
Install Type: Msi

Host:
Version: 9.0.0-rc.1.24431.7
Architecture: x64
Commit: static

.NET SDKs installed:
6.0.425 [C:\Program Files\dotnet\sdk]
7.0.410 [C:\Program Files\dotnet\sdk]
8.0.108 [C:\Program Files\dotnet\sdk]
9.0.100-rc.1.24452.12 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0-rc.1.24452.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0-rc.1.24431.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0-rc.1.24452.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.