dotnet / dotnet/sdk

The "DiscoverPrecompressedAssets" task failed unexpectedly

Open
#52,089 9 comments 0 reactions 0 assignees View on GitHub
Area-AspNetCore StaticWebAssets
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Existing issues
For .Net 10 there is [#64512](https://github.com/dotnet/aspnetcore/issues/64512) with a similar problem but the OP didn't reopen since he solved his problem in another way.

[#49180](https://github.com/dotnet/sdk/issues/49180) was fixed in 9.0.301, i can't tell if my problem is the same or not. The msbuild workaround in that issue doesn't get my build working.

### Describe the bug
After upgrading a Blazor project (referencing another Blazor project) from .Net 8 to .Net 10 I get the following error when building (build works in .Net 8):
```
dotnet build .\BlazorApp\BlazorApp.csproj
Restore complete (1,1s)
BlazorPlugin net10.0 succeeded (3,1s) → BlazorPlugin\bin\Debug\net10.0\BlazorPlugin.dll
BlazorApp net10.0 failed with 1 error(s) (1,0s)
C:\Program Files\dotnet\sdk\10.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.Compression.targets(297,5): error MSB4018:
The "DiscoverPrecompressedAssets" task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added. Key: C:\Users\daniel\.nuget\packages\m
icrosoft.aspnetcore.app.internal.assets\10.0.0\_framework\blazor.web.js
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at System.Linq.Enumerable.SpanToDictionary[TSource,TKey](ReadOnlySpan`1 source, Func`2 keySelector, IEqualityCo
mparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityCompare
r`1 comparer)
at Microsoft.AspNetCore.StaticWebAssets.Tasks.DiscoverPrecompressedAssets.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLogging
Context taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

Build failed with 1 error(s) in 5,8s
```

### To Reproduce
Minimal repo to reproduce here:
https://github.com/DanielSundberg/DiscoverPrecompressedAssets

What I did to get this error
* In an empty dir created global.json with version 8.0.100
* dotnet new blazor --use-program-main -o BlazorApp
* dotnet new blazor --use-program-main -o BlazorPlugin
* dotnet add .\BlazorApp\BlazorApp.csproj reference .\BlazorPlugin\BlazorPlugin.csproj
* dotnet build .\BlazorApp\BlazorApp.csproj

Successful build (first commit in linked repo)

* dotnet clean
* Manual delete of obj and bin directories
* Change global.json to use version 10.0.100
* Change projects to target net10.0
* dotnet build .\BlazorApp\BlazorApp.csproj

Now I get the build error above (second commit in linked repo).

### Further technical details
```
dotnet --info
.NET SDK:
Version: 10.0.100
Commit: b0f34d51fc
Workload version: 10.0.100-manifests.4c0ca8ba
MSBuild version: 18.0.2+b0f34d51f

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.0
Architecture: x64
Commit: b0f34d51fc

.NET SDKs installed:
8.0.100 [C:\Program Files\dotnet\sdk]
10.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
DOTNET_CLI_TELEMETRY_OPTOUT [1]

global.json file:
C:\code\DiscoverPrecompressedAssets\global.json

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.