Home > Blockchain >  NETSDK1152 Multiple output files error for _ViewImports.cshtml files when publishing ASP.NET Core 6
NETSDK1152 Multiple output files error for _ViewImports.cshtml files when publishing ASP.NET Core 6

Time:03-04

Recently I migrated my asp.net core 3.1 web app to NET6. Before migration, I didn't have this kind of problems. My web app has several projects (DLL) and some of them have Views and Controllers due to requirements. I marked those projects as Skd.Razor as shown below:

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
  </PropertyGroup>

I configured Startup to recognize those controllers and views by using application parts:

enter image description here

Each project has its own _ViewImports.cshtml including Main Project SicotX:

enter image description here enter image description here enter image description here

The problem comes out when I'm trying to publish the application, compilation is generating the following error

enter image description here

_ViewImports.cshtml is causing conflicts in the output path in both projects except the main SiotX project.

I need to use _ViewImports into those projects so I need your help or guide how to overcome this issue is blocking me, or maybe is it possible to use a unique _ViewImports.cshtml and share with all projects?

Thanks

CodePudding user response:

In .NET SDK 6.0.100, the .NET SDK 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.

Please visit Generate error for duplicate files in publish output to get detailed information.

I found some suggestions that could help you fix this issue.

  1. Add code below in *.csproj files to all of your projects.

<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>

  1. Exclude the problematic files from copying to the output folder.

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

<Content Remove="file_name"/>
<None Include="file_name">
  <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
  <CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>

References:

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

  2. NETSDK1152 Error for _ViewImports.cshtml files

  • Related