sdk icon indicating copy to clipboard operation
sdk copied to clipboard

The "DiscoverPrecompressedAssets" task failed unexpectedly

Open DanielSundberg opened this issue 2 weeks ago • 1 comments

Existing issues

For .Net 10 there is #64512 with a similar problem but the OP didn't reopen since he solved his problem in another way.

#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

DanielSundberg avatar Dec 09 '25 17:12 DanielSundberg

@javiercn does this ring a bell? Seems like there's also continued activity on https://github.com/dotnet/aspnetcore/issues/64512 which was closed.

MackinnonBuck avatar Dec 10 '25 18:12 MackinnonBuck

Also reproducing this, the key seems to be a Microsoft.NET.Sdk.Web project referencing another Microsoft.NET.Sdk.Web project - which I am due to my integration test project using Microsoft.NET.Sdk.Web.

Sebazzz avatar Dec 15 '25 11:12 Sebazzz

For my case, this temporary workaround sufficed:

<html><body>
<!--StartFragment-->
<Target Name="FixNetSdkDiscoverAssetsBug" BeforeTargets="ResolveBuildCompressedStaticWebAssetsConfiguration">
--
  | <!-- Workaround for:
  | The "DiscoverPrecompressedAssets" task failed unexpectedly.
  | System.ArgumentException: An item with the same key has already been added. Key: C:\Users\[user]\.nuget\packages\microsoft.aspnetcore.app.internal.assets\10.0.0\_framework\blazor.web.js
  |  
  | https://github.com/dotnet/sdk/issues/52089
  |  
  | This is caused by a Microsoft.NET.Sdk.Web project (like this) referencing another project that also uses Microsoft.NET.Sdk.Web.
  | It appears to be a .NET SDK bug, and we're not the only one hitting it.
  | -->
  |  
  | <ItemGroup>
  | <!-- Remove any duplicate StaticWebAsset and StaticWebAssetEndpoint items -->
  | <_StaticWebAsset Include="@(StaticWebAsset)" />
  | <StaticWebAsset Remove="@(StaticWebAsset)" />
  | <StaticWebAsset Include="@(_StaticWebAsset->Distinct())" />
  | </ItemGroup>
  | </Target>

<!--EndFragment-->
</body>
</html>

Sebazzz avatar Dec 16 '25 06:12 Sebazzz

For my case, this temporary workaround sufficed:

-- | | | | | <_staticwebasset include="@(StaticWebAsset)"> | | | |

Still doesn't build for me with the above msbuild snippet in my directory.build.props:

>dotnet build .\BlazorApp\BlazorApp.csproj

Restore complete (0,4s)
  BlazorPlugin net10.0 succeeded (4,9s) → BlazorPlugin\bin\Debug\net10.0\BlazorPlugin.dll
  BlazorApp net10.0 failed with 1 error(s) (1,4s)
    C:\Program Files\dotnet\sdk\10.0.100\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.NET.Sdk.StaticWebAssets.targets(618,5): 
error Conflicting assets with the same target path 'bootstrap/bootstrap.min.css#[.{fingerprint=8inm30yfxf}]?.map.gz'. 
For assets 'Identity: C:\code\DiscoverPrecompressedAssets\BlazorApp\obj\Debug\net10.0\compressed\8qkwa52ezv-{0}-8inm30yfxf-8inm30yfxf.gz, 
SourceType: Discovered, SourceId: BlazorApp, ContentRoot: C:\code\DiscoverPrecompressedAssets\BlazorApp\obj\Debug\net10.0\compressed\, 
BasePath: /, 
RelativePath: bootstrap/bootstrap.min.css#[.{fingerprint=8inm30yfxf}]?.map.gz, 
AssetKind: All, 
AssetMode: All, 
AssetRole: Alternative, 
AssetRole: , AssetRole: , 
RelatedAsset: C:\code\DiscoverPrecompressedAssets\BlazorApp\wwwroot\bootstrap\bootstrap.min.css.map, 
AssetTraitName: Content-Encoding, AssetTraitValue: gzip, Fingerprint: vhplv2fb6t, Integrity: U+unDV0au6R0diQNcEupHyJsbjJTqlVY4S8arnj+BrQ=, 
FileLength: 74664, 
LastWriteTime: 2025-12-16 17:30:41 +00:00, 
CopyToOutputDirectory: Never, 
CopyToPublishDirectory: PreserveNewest, 
OriginalItemSpec: C:\code\DiscoverPrecompressedAssets\BlazorApp\wwwroot\bootstrap\bootstrap.min.css.map' 
and 'Identity: C:\code\DiscoverPrecompressedAssets\BlazorPlugin\obj\Debug\net10.0\compressed\i8a4iwivx8-{0}-8inm30yfxf-8inm30yfxf.gz, 
SourceType: Project, 
SourceId: BlazorPlugin, 
ContentRoot: C:\code\DiscoverPrecompressedAssets\BlazorPlugin\obj\Debug\net10.0\compressed\, 
BasePath: /, RelativePath: bootstrap/bootstrap.min.css#[.{fingerprint=8inm30yfxf}]?.map.gz, 
AssetKind: All, 
AssetMode: All, 
AssetRole: Alternative, 
AssetRole: , AssetRole: , 
RelatedAsset: C:\code\DiscoverPrecompressedAssets\BlazorPlugin\wwwroot\bootstrap\bootstrap.min.css.map, 
AssetTraitName: Content-Encoding, 
AssetTraitValue: gzip, 
Fingerprint: vhplv2fb6t, Integrity: U+unDV0au6R0diQNcEupHyJsbjJTqlVY4S8arnj+BrQ=, 
FileLength: 74664, 
LastWriteTime: 2025-12-02 20:07:32 +00:00, 
CopyToOutputDirectory: Never, 
CopyToPublishDirectory: PreserveNewest, 
OriginalItemSpec: C:\code\DiscoverPrecompressedAssets\BlazorPlugin\wwwroot\bootstrap\bootstrap.min.css.map' from different projects.

Build failed with 1 error(s) in 7,6s

DanielSundberg avatar Dec 16 '25 17:12 DanielSundberg