2

After upgrading my WebApp from NET5 to NET6, when trying to push my WebApp to the Azure AppService, I get the NETSDK1152 error:

Found multiple publish output files with the same relative path: C:...\src\ProjA_ViewImports.cshtml, C:...\src\ProjB_ViewImports.cshtml, C:...\src\ProjC_ViewImports.cshtml

The projects in Question are Razor Class Libraries (Project Sdk="Microsoft.NET.Sdk.Razor"), which all get referenced by a regular Web App (). The files in question are _ViewImport.cshtml files to contain common usings/imports for my Views. They only have their standard properties which never got changed by me (Action -> Content, Copy to Output Directory -> Do not Copy).

Before updating to NET6, everything worked flawlessly, both on my local machine as well as on Azure (both publishing and running the application). After my upgrade to .NET6, I started receiving the error mentioned above.

However, this ONLY occurs when I use the publish functionality (or when the CI/CD is triggered by pushing to the remote git repo). If I use dotnet publish locally, everything seems to be published just fine.

Trying the usual recommendation, of turning off the error (as proposed, for instance, here), did not solve anything for me.

Apart from either getting rid of the _ViewImport.cshtml files altogether, or restructuring the project, I am lost with regards how to potentially solve this issue while keeping the structure as is.

1 Answers1

0

The .NET SDK (6.0.100 Preview 1) generates a new error (NETSDK1152) in cases where files from different source paths would be copied to the same file path in the publish output. This can happen when a project and its project references include a file with the same name that's included in the publish output.

Old Behavior

Both files were copied to the same destination. The second file to be copied overwrote the first file, and which file "won" was mostly arbitrary.

In some cases, the build failed. For example, when trying to create a single-file app, the bundler failed with an ArgumentException, as shown in the following build output:

C:\Program Files\dotnet\sdk\5.0.100-preview.5.20258.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(962,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [C:\repro\repro.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.5.20258.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(962,5): error MSB4018: System.ArgumentException: Invalid input specification: Found multiple entries with the same BundleRelativePath [C:\repro\repro.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.5.20258.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(962,5): error MSB4018: at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [C:\repro\repro.csproj]

New behavior

Starting in .NET 6, MSBuild removes duplicate files that are copied to the publish folder if both the source and destination are the same. If there are any remaining duplicates, a NETSDK1152 error is generated and lists the files that are duplicated.

Reason for change

Duplicate files in the publish output sometimes caused build breaks or unpredictable behavior.

Recommended action

  • Ideally, you should update your project to avoid situations where multiple files with the same name are copied to the publish output. The error message includes the name of the duplicate file. Some causes for duplicate files include:

    • An ASP.NET Core project that references an ASP.NET Core web service, and each has its own appsettings.json file.
    • A project item where CopyToOutputDirectory is unnecessarily set to Always.

    Binary log files can be useful for finding the cause of the duplicated files.

  • Alternatively, you can set the ErrorOnDuplicatePublishOutputFiles property to false.