Blazor WASM - Build Error - "Static web asset has a conflicting web root path"

4.2k Views Asked by At

I have a Blazor WASM app running on .Net Standard 2.1 which has suddenly started showing the following error whenever I try to build the app.

The static web asset 'C:\MyProject\wwwroot\appsettings.json' has a conflicting web root path '/wwwroot/appsettings.json' with the project file 'wwwroot\appsettings.json'.

Double-clicking the build error takes me to the following section in the file:

C:\Program Files\dotnet\sdk\5.0.201\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets

    <ValidateStaticWebAssetsUniquePaths
      StaticWebAssets="@(_ReferencedStaticWebAssets)"
      WebRootFiles="@(_WebRootFiles)" />

I have been developing the app over the last several weeks, and have never had this build error before.

Nothing has changed with regards to the client-side appsettings.json file.

I've tried deleting the bin and obj folders, cleaning the project, and doing a full rebuild - all to no effect.

Some articles I've found (e.g. https://docs.telerik.com/blazor-ui/knowledge-base/static-asset-conflicting-root-path ) suggest deleting the "_content" folder, but I have no such folder.

I've come to a grinding halt.

Does anyone have any suggestions that I might try?

Many thanks.

4

There are 4 best solutions below

4
Albert Gromek On BEST ANSWER

It's hard to solve this error without seeing your project and file structure, but one thing you can look for is whether you have an appsettings.json file at the same directory in both Server and Client projects. (For ASP.NET Core hosted Blazor)

0
daddybacon On

Sounds like you have two appsettings.json files and it's causing a build issue. I'd suggest doing a search in your project for appsettings.json and see if there is a duplicate. (Can be in both projects like the answer above.)

2
Taylor C. White On

I ran into this recently. The solution for me was to remove the bootstrap library on the server project. (wwwroot/lib/bootstrap/). Basically what you're likely hitting is that the Client project has a file with the same name as a file in the matching directory on the server project. Since they all get packed together and served as static web files, this creates a conflict that needs to be resolved. Deleting either will work.

0
Taylan Yuksel On

To those who may have a similar issue regarding a file/package I just removed that file and build the project. Then I put it back in its location and rebuild it.

Maybe doesn't sound so clever but I had the same problem suddenly with no change and this helped me to get rid of it.