Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish error: Found multiple publish output files with the same relative path

When I publish my ABP project I get the following error:

C:\Program Files\dotnet\sdk\6.0.100-rc.1.21458.32\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: 

D:\Github\volo\abp\lepton-theme\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Lepton\compilerconfig.json,
D:\Github\volo\abp\bookstore\src\Acme.BookStore.Theme\compilerconfig.json, 

D:\Github\volo\abp\lepton-theme\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Lepton\package.json, 
D:\Github\volo\abp\bookstore\src\Acme.BookStore.Web\package.json. 

D:\Github\volo\abp\bookstore\src\Acme.BookStore.Web\Acme.BookStore.Web.csproj
like image 678
Nader Gharibian Fard Avatar asked Nov 10 '21 20:11

Nader Gharibian Fard


Video Answer


3 Answers

Issue:

The issue raises after .NET 6 migration. There's a new feature that blocks multiple files from being copied to the same target directory with the same file name. See https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/duplicate-files-in-output

Solution #1 (workaround):

You can add the following build property to all your publishable (*.Web) projects' *.csproj files. This property will bypass this check and works as previously, in .NET5.

<PropertyGroup><ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles></PropertyGroup>

Solution #2:

Exclude the problematic files to be copied to the output folder. In this example we'll exclude these files: compilerconfig.json and package.json.

Add the following lines to your common.props (located in the root directory of your solution):

<Content Remove="compilerconfig.json;package.json"/>
<None Include="compilerconfig.json;package.json">
  <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
  <CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
like image 73
Nader Gharibian Fard Avatar answered Oct 09 '22 02:10

Nader Gharibian Fard


The above answers led me to my solution. My case is a self-building Entity Framework library project that was now copying over its appsettings.json when building the website that used it.

My solution was to let it copy to output folder (when I am doing migration actions in VS**) but prevent it from publishing using the "Never" value because it is only ever published as a library under a website or web service.

<ItemGroup>
<Content Include="appsettings.json">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    <CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>

** My EF library project builds itself according to the pattern in this data-seeding article.

Thus do I eat my cake and keep it.

like image 17
cherry Avatar answered Oct 09 '22 04:10

cherry


If you are getting this in a azure devops pipleline you can add the following task to specify the SDK version for your build

- task: UseDotNet@2
  displayName: 'Install .Net SDK version'
  inputs:
    packageType: sdk
    version: x.x.xxx //example (3.1.416)
    installationPath: $(Agent.ToolsDirectory)/dotnet

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/dotnet-core-tool-installer?view=azure-devops

like image 11
JCisar Avatar answered Oct 09 '22 03:10

JCisar