Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build project using VS 17.12.3: “DiscoverPrecompressedAssets” task failed unexpectedly #59625

Open
1 task done
fltrierweiler opened this issue Dec 23, 2024 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components investigate
Milestone

Comments

@fltrierweiler
Copy link

fltrierweiler commented Dec 23, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I've found a similar issue, but the exception there isn't the same (System.ArgumentException there and System.InvalidOperationException here) and that issue was closed without an answer, so I've decided to create a new one.

Basically, I'm unable to build an existing project that uses Blazor.BrowserExtension.Template. It used to work fine with version 17.11.35219.272.

Expected Behavior

Simply put, the project build should work without errors, as it used to do.

Steps To Reproduce

I've created a minimalistic project to showcase the issue. To reproduce the error, all that has to be done is to build the project.

Exceptions (if any)

Here's the error I get whenever I try to build the project using VS 17.12.3:

The "DiscoverPrecompressedAssets" task failed unexpectedly.
System.InvalidOperationException: Fingerprint for '...\ExtensionTest\ExtensionTest\obj\Debug\net8.0\browserextension\build\BackgroundWorker.js' is not defined.
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.Validate()
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.StaticWebAsset.FromTaskItem(ITaskItem item)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.AspNetCore.StaticWebAssets.Tasks.DiscoverPrecompressedAssets.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

.NET Version

9.0.101

Anything else?

UPDATE: If I use SDK 8.0.404 and specify the version by adding a global.json to the solution folder, it actually works. Still no way to work with 9.0.101, though.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Dec 23, 2024
@MarcoMedrano
Copy link

MarcoMedrano commented Dec 24, 2024

I have the same issue building my maui app, your workaround is working (as I did not update my projects to dotnet 9):

global.json at root directory:

{
  "sdk": {
    "version": "8.0.206"
  }
}

@javiercn javiercn added this to the 9.0.x milestone Jan 7, 2025
@lofcz
Copy link
Contributor

lofcz commented Jan 10, 2025

Hitting a similar error after upgrading from 8 to 9:

Error MSB4018 : The "DiscoverPrecompressedAssets" task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added. Key: [path]\wwwroot\app.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)

In csproj, I have several files linked as:

<Content Include="..\[path]\wwwroot\**\app.scss">
    <Link>wwwroot\%(RecursiveDir)%(Filename)%(Extension)</Link>
    <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

If I remove these links, the app builds but I can't use assets from the web project in the sln. This works as expected on 8.0.X

This is caused by:
https://github.com/dotnet/sdk/blob/1d3bf3b00bd92bc9eef62d56e97072425ea8d87f/src/StaticWebAssetsSdk/Tasks/Compression/DiscoverPrecompressedAssets.cs#L35C9-L35C106

ToDictionary() crashes if source contains duplicate keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components investigate
Projects
None yet
Development

No branches or pull requests

4 participants