'Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(442,5): error : Two assets found targeting the same path with incompatible asset kinds

C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(442,5): error : Two assets found targeting the same path with incompatible asset kinds: [D:\Migration\XXXXXX\XXXX.App\XXXX.csproj] C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(442,5): error : ‘D:\Migration\XXXXXX\XXXX.App\wwwroot\assets\images\AAA.png’ with kind ‘All’ [X:\Migration\XXXXXX\XXXX.App\XXXX.csproj] C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(442,5): error : ‘X:\Migration\XXXXXX\XXXX.App\wwwroot\assets\images\AAA.png’ with kind ‘All’ [D:\Migration\XXXXXX\XXXX.App\XXXX.csproj] C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(442,5): error : for path ‘assets/images/Cancel.png’ [D:\Migration\XXXXXX\XXXX.App\XXXX.csproj] 0 Warning(s) 1 Error(s)

Error occurs while building the Solution. Not sure why this error is happening in .NET 6, the same copy of wwwroot folder content to output directory works fine in .Netcore3.1. But giving error in .Net 6.

Did initial research on any other alterative for this problem. It only builds if content of wwwroot folder are deleted each time in the project directory location. hence works fine on the first time of clean workspace.

Background: basically need to copy the icons and images used in client to wwwroot folder and also copying this to output directory using

Sample mini project is in git https://github.com/Shruthi1984/StaticWebAssestscopyissue .



Solution 1:[1]

After upgrading to .NET 6 the same error occurred in my project. What fixed it was the following entry in my entry-point .csproj:

<EnableDefaultContentItems>true</EnableDefaultContentItems>
<PublishSingleFile>false</PublishSingleFile>

After this point, the copy of wwwroot worked.

Solution 2:[2]

Similar error propped up in our project after upgrading to net6.0

Project had a .nuget package reference to said static asset(i.e bootstrap), and also files under wwwroot folder. The duplication made the project to throw error. We removed the reference to package. And that solved the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 r0-
Solution 2 FromHighHills