Search code examples
.netasp.net-coreassets

Conflicting assets with the same target path 'css/app.css' in .net projects


I have some projects in a .net solution, 2 of them are: Client (blazor) and Mobile (maui). Client project has wwwroot folder with css folder. Mobile project also has wwwroot folder with css folder. In the Mobile project I configured the dependency link to the Client project (has services). But from one moment to the next it generates an error and does not execute the project. It shows me an error which I detail in the following image:

conflicting assets css

I tried deleting the wwwroot folder of the Mobile project but it didn't work. I also tried deleting the wwwroot/css folder but that didn't work either. Please can someone help me solve this problem, thank you...


Solution

  • Conflicting assets with the same target path 'css/app.css' in .net projects. I tried deleting the wwwroot folder of the Mobile project but it didn't work. I also tried deleting the wwwroot/css folder but that didn't work either.

    Well, it would be nicer if you could share your reproducible sample or any to investigate further.

    However, accoriding to your description and error message the error "Conflicting assets with the same target path 'css/app.css'" suggests that both the Client and Mobile projects are trying to publish a file named app.css to the same location in the final output. This conflict prevents the build process from completing successfully.

    In order to resolve the issue, you can rename either the Client or Mobile project's app.css to a different name (e.g., mobile-app.css or client-app.css). Make sure to update any references to the renamed file in your respective project's Razor components or Maui views.

    In addition if appropriate, use preprocessor directives (e.g., #ifdef / #endif in C#) to selectively include different CSS snippets based on the build configuration (e.g., Client or Mobile). This allows you to maintain a single app.css file with conditional content.

    Apart from that, if the Mobile project doesn't actually need its own app.css file, you can configure the project to exclude it from publishing. In your Mobile project, open the .csproj file. Locate the <Content> element and find the entry for wwwroot/css/app.css. Add the Exclude="**" attribute to the entry. This tells the build process to not copy app.css to the output folder.

    After above changes, rebuild your project and check.

    Note: Please refer to this official document for file structure and static file content configiration.