Skip to content

Unable to build project using VS 18.2.1: “DiscoverPrecompressedAssets” task failed unexpectedly. An item with the same key has already been added #52647

Open

Description

@tlevey01

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

This is probably the same bug as: dotnet/aspnetcore#59625, which is closed. Or it could be part of this issue: #50483, but it's slightly different. Here's another one: #52089, and there was a debate where the bug should be discussed here: dotnet/aspnetcore#64512, but no resolution that works for me even though it's closed.

My solution has five projects that I'm trying to upgrade from .Net 8 to .Net 10. The main project builds, but two dependent projects fail to build with the error “DiscoverPrecompressedAssets” task failed unexpectedly. An item with the same key has already been added.

I've tried:

  • To delete the VS obj, bin and .vs folders before cleaning and rebuilding the solution/projects
  • Moving all the Top-level packages from the sub-projects to Transitive except Microsoft.AspNetCore.App.Internal.Assets, which has a note that reads: "Implicitly referenced by an SDK. To update the package, update the SDK to which it belongs." (so it can't be moved)
  • Cleaning/refreshing/updating/etc. the NuGet packages in the terminal (one error in the terminal pointed to blazor.web.js being duplicated, but I can't find where that might be)
  • Removing any duplicate files under the wwwroot folder
  • Adding a global.json file pointing to .Net 10
  • NuGet Package Source Mapping
  • Thought about migrating from packages.config to PackageReference, but decided it probably wouldn't help
  • Investigating the project.assets.json file (https://christosmonogios.com/2024/12/07/how-to-deal-with-the-nuget-hell-of-transitive-dependencies-in-your-dot-net-projects/)
  • The .NET Upgrade Assistant, which says there's an error but provides no usable guidance to correct it
  • Probably something else I can't recall

Nothing works. Can Microsoft fix this or is there a work-around that works? Thanks!

Expected Behavior

The projects should build. They're fine in .Net 8. The only thing that changed is migrating to .Net 10 and there does not appear to be any other underlying errors.

Steps To Reproduce

Reproducing this issue is simple:

  1. Create a new "Blazor Web App" (with or without authentication) using .Net 10 in Visual Studio 2026
  2. Add another Blazor Web App to the solution

Both projects build and start fine, but

  1. Add a Reference to the first project in the second project and the error above is generated and the second project won't build (the first one still builds)

Exceptions (if any)

N/A

.NET Version

10

Anything else?

No response

Activity

  1. transferred this issue fromdotnet/aspnetcoreon Jan 22, 2026
  2. tlevey01 commented on Jan 24, 2026

    @tlevey01
    Author

    Reproducing this issue is simple:

    1. Create a new "Blazor Web App" (with or without authentication) using .Net 10 in Visual Studio 2026
    2. Add another Blazor Web App to the solution

    Both projects build and start fine, but

    1. Add a Reference to the first project in the second project and the error above is generated and the second project won't build (the first one still builds)

    Seriously, is anyone at Microsoft trying to fix this?

    In .Net 8 and 9, you get an error that the assets in the wwwroot folder are duplicated, but both projects build and run if you remove the duplicate files in one of the projects.

    The problem file appears to be:

    .nuget\packages\microsoft.aspnetcore.app.internal.assets\10.0.2_framework\blazor.web.js

  3. dvdstelt commented on Jan 27, 2026

    @dvdstelt

    I have the same issue without Blazor, but with static websites.

    >Microsoft.NET.Sdk.StaticWebAssets.Compression.targets(289,5): Error MSB4018 : The "DiscoverPrecompressedAssets" task failed unexpectedly.
    System.ArgumentException: An item with the same key has already been added. Key: D:\Git\ToolsSite\wwwroot\css\announcement-generator.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](ReadOnlySpan`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
       at System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer)
       at Microsoft.AspNetCore.StaticWebAssets.Tasks.DiscoverPrecompressedAssets.Execute()
       at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
       at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
    0
    
  4. added
    Area-AspNetCoreRazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK
    and removed on Jan 27, 2026
  5. self-assigned this
    on Feb 9, 2026
  6. added this to the 10.0.1xx milestone on Feb 9, 2026
  7. added a commit that references this issue on Mar 6, 2026
    d09cdcb
  8. modified the milestones: 10.0.1xx, 11.0.1xx on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-AspNetCoreRazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions