question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET Core 6 Found multiple publish output files with the same relative path

See original GitHub issue

Describe the bug

On .NET Core 6 where when publishing with Web Deploy via Visual Studio 2022. I’m receiving the following error:

Error Found multiple publish output files with the same relative path: C:\Work\MySolution\A\appsettings.json, C:\Work\MySolution\B\appsettings.json, C:\Work\MySolution\A\appsettings.Staging.json, C:\Work\MySolution\B\appsettings.Staging.json, , C:\Work\MySolution\A\appsettings.Development.json, C:\Work\MySolution\B\appsettings.Development.json

There is no issues when building, just publishing.

I have two ASP.NET Core 6 projects. Project “A” references project “B” (I know B should really be a class library, but go with me).

I am aware that this is expected functionality in .NET Core 6 (https://docs.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/duplicate-files-in-output). However, I cannot seem to tell project “A” to ignore project “B” appsettings files. Previously ignoring the files worked. I am aware of the ErrorOnDuplicatePublishOutputFiles property I can set, but I’m trying to strictly tell it not to include project B’s appsetting files.

I’ve tried various other combos of the following, but none of it seems to work. Not sure if there is an issue with VS2022 with new and/or deprecated directives that I am unaware of that is also contributing.

To Reproduce

Example 1: Tried typical content update approach (supposedly does not work after VS 15.3). Also tried with absolute paths.

A.csproj

...

<ItemGroup>
  <ProjectReference Include="..\B\B.csproj">
    <PrivateAssets>all</PrivateAssets>
  </ProjectReference>
</ItemGroup>
  
<ItemGroup>    
  <Content Update="..\B\appsettings.json" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" />
  <Content Update="..\B\appsettings.*.json" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" />
</ItemGroup>

...

Example 2: Tried typical content remove approach. Also tried with absolute paths.

A.csproj`

...

<ItemGroup>
  <ProjectReference Include="..\B\B.csproj">
    <PrivateAssets>all</PrivateAssets>
  </ProjectReference>
</ItemGroup>
  
<ItemGroup>    
  <Content Remove="..\B\appsettings.json" />
  <Content Remove="..\B\appsettings.*.json" />
</ItemGroup>

<ItemGroup>    
  <None Include="..\B\appsettings.json" />
  <None Include="..\B\appsettings.*.json" />
</ItemGroup>

...

Example 3: I tried using the GeneratePathProperty path to make sure it was directly ignoring project B’s files.

A.csproj

...

<ItemGroup>
  <ProjectReference Include="..\B\B.csproj" GeneratePathProperty="true">
    <PrivateAssets>all</PrivateAssets>
  </ProjectReference>
</ItemGroup>
  
<ItemGroup>    
  <Content Update="$(PkgB)\appsettings.json" CopyToPublishDirectory="Never" />
  <Content Update="$(PkgB)\appsettings.*.json" CopyToPublishDirectory="Never" />
</ItemGroup>

...

Example 4: Modified pubxml to ignore specific files. Tried with absolute paths too.

A.pubxml

...

<ExcludeFilesFromDeployment>..\B\appsettings.json;..\B\appsettings.Staging.json;...</ExcludeFilesFromDeployment> 

...

Example 5: Modified pubxml file to explicity ignore project B files. Tried absolute paths as well.

A.pubxml

...

<ItemGroup>
  <ResolvedFileToPublish Include="..\B\appsettings.json">
    <CopyToPublishDirectory>Never</CopyToPublishDirectory>
  </ResolvedFileToPublish>
  <ResolvedFileToPublish Include="..\B\appsettings.Staging.json">
    <CopyToPublishDirectory>Never</CopyToPublishDirectory>
  </ResolvedFileToPublish>
  <ResolvedFileToPublish Include="..\B\appsettings.Development.json">
    <CopyToPublishDirectory>Never</CopyToPublishDirectory>
  </ResolvedFileToPublish>
  <ResolvedFileToPublish Include="..\B\appsettings.Backup.json">
    <CopyToPublishDirectory>Never</CopyToPublishDirectory>
  </ResolvedFileToPublish>
</ItemGroup>

...

Exceptions (if any)

Further technical details

  • ASP.NET Core version: 6.0.0
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version: VS 2022
  • Include the output of dotnet --info:
dotnet --info Output
.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100\

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:21
  • Comments:31 (5 by maintainers)

github_iconTop GitHub Comments

24reactions
Defriacommented, Dec 23, 2021

set this in your project.csproj file

  <PropertyGroup>
      ....
      <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
  </PropertyGroup>
20reactions
seanamoscommented, Nov 23, 2021

The behavior is quite unexpected, it seems even more unexpected given: https://github.com/dotnet/sdk/issues/3871

➜ dotnet --version    
6.0.100
MySln.sln
|
|-->ProjectA.csproj (net6.0/Microsoft.NET.Sdk)
|        |
|        |-->file.txt (CopyToOutputDirectory="PreserveNewest")
|
|-->ProjectB.csproj (net6.0/Microsoft.NET.Sdk, references ProjectA.csproj)
         |
         |-->file.txt (CopyToOutputDirectory="PreserveNewest")
dotnet publish ProjectB

/usr/share/dotnet/sdk/6.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: /xxx/file.txt, /xxx/file.txt. [xxx/ProjectB.csproj]
NETSdkError: /usr/share/dotnet/sdk/6.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: /xxx/file.txt, /xxx/file.txt.

There is <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>, but that exhibits the same “undefined” overwriting behavior that was supposed to be addressed here: https://github.com/dotnet/sdk/issues/3871

I’m pretty sure the desired behavior is to be able to reference a project and optionally not copy/publish any/specific content files from that project.

appSettings.json is the originally given example, but this obviously happens with any file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Found multiple publish output files with the same relative ...
Issue: The issue raises after .NET 6 migration. There's a new feature that blocks multiple files from being copied to the same target ......
Read more >
Found multiple publish output files with the same relative ...
NET 6 to stop duplicate files being included in publish artifacts. So how do we get around it, well it turns out it's...
Read more >
Generate error for duplicate files in publish output - .NET
NET 6 where the .NET SDK generates an error when files from different source paths would be copied to the same location in...
Read more >
Found multiple publish output files with the same relative ...
I have an asp.net core Web API project with an appsettings.json file. This project in turn references an MS Graph project which has...
Read more >
Found multiple publish output files with the same relative path ...
Issue: The issue raises after . NET 6 migration. There's a new feature that blocks multiple files to be copied to the same...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found