3

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 .

  • Does not seem to be a lot of documentation on this error, the way my project is setup I want to keep the files in both project, did you find a way to work around this error? – Huggster Jun 23 '22 at 09:44
  • same problem [here](https://stackoverflow.com/questions/76673639/visual-studio-2022-v-17-6-5-link-installed-nuget-package-css-file-in-layout)...Visual Studio 2022 - v.17.6.5 – sTx Jul 18 '23 at 18:25

2 Answers2

5

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.

FromHighHills
  • 151
  • 2
  • 8
-1

I had the same problem after updating from .net5.0 to .net6.0. The error happened because I had this command in the project file:

<Content Include="$(ProjectDir)\wwwroot\**\*.*" CopyToPublishDirectory="PreserveNewest" />

After removing it I was finally able to build the project, because in .NET 6 the copying is automatically done and it will try to copy the files twice with this command

  • Thats not really a solution. I want to keep this while still compiling – myst1c Jan 26 '23 at 09:41
  • We encountered the same problem. Looks like in .net 6 it already copies stuff to the output folder even without that extra statement in the project file. So that extra statement may copy it for the second time causing the error? – Johan t Hart Jan 26 '23 at 12:22
  • @JohantHart you are correct – real_villain Jan 27 '23 at 08:57