error NETSDK1152: Found multiple publish output files with the same relative path
means two projects in the publish both want to put a file with the same name in the same
place, usually appsettings.json from the app and from a referenced library.
Stop the library from publishing its copy.
The message lists both source files. In the project that should not ship its copy, set
CopyToPublishDirectory="Never" on that item, and publish again.
The error
...
LibA -> ...\LibA\bin\Release\net10.0\LibA.dll
App -> ...\App\bin\Release\net10.0\App.dll
C:\Program Files\dotnet\sdk\10.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: ...\LibA\appsettings.json, ...\App\appsettings.json. [...\App\App.csproj]
The project paths are shortened; nothing else in the output was changed.
Why it happens
A publish collects the app's own files and the files that referenced projects mark for
publishing, and flattens them into one publish folder. Here both
App and the class library LibA had an
appsettings.json marked with CopyToPublishDirectory, so both
would land at publish\appsettings.json. The SDK stops and names both
source paths, so you can decide which one belongs in the output.
Notice that the build part succeeded: both -> lines print before the
error. A plain dotnet build of the same two projects, both files still
marked, succeeded with 0 warnings and 0 errors; only the publish failed. So a project that builds cleanly every day can still fail the first time
someone publishes it.
The fix
<None Update="appsettings.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
dotnet publish -c Release
With that line in LibA.csproj the publish finished, and
publish\appsettings.json held the app's content. If the library really
needs its settings at run time, rename its file (for example
liba.settings.json) so the two no longer collide. Either way, the change
goes in the referenced project, not in the app that you publish.
The SDK also has a switch. dotnet publish -c Release -p:ErrorOnDuplicatePublishOutputFiles=false
published without the error, and in this run the app's copy ended up in the folder. That
hides the collision instead of deciding it, so use it only when you have checked which
file wins.
How it was reproduced
A dotnet new console app and a dotnet new classlib library on
.NET SDK 10.0.403 (net10.0), the app referencing the library, each with its
own appsettings.json (different content) marked
CopyToPublishDirectory="PreserveNewest". dotnet publish -c Release
in the app folder failed as shown.
Frequently asked
- What does NETSDK1152 found multiple publish output files mean?
- Two projects in the publish both copy a file with the same name to the same place in the publish folder, often appsettings.json from the app and from a referenced library.
- How do I fix NETSDK1152 for appsettings.json?
- In the referenced project, set CopyToPublishDirectory to Never on its appsettings.json item, or rename that file so it no longer collides with the app's copy.
- What does ErrorOnDuplicatePublishOutputFiles=false do?
- It turns off the NETSDK1152 check so publish succeeds and one of the files ends up in the folder. It hides the collision, so check which copy you got.
More decoded errors in the Fixes category.