.NET Core 6 Found multiple publish output files with the same relative path
See original GitHub issueDescribe 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:
- Created 2 years ago
- Reactions:21
- Comments:31 (5 by maintainers)
Top GitHub Comments
set this in your project.csproj file
The behavior is quite unexpected, it seems even more unexpected given: https://github.com/dotnet/sdk/issues/3871
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/3871I’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.