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:
Each project has its own _ViewImports.cshtml including Main Project SicotX:
The problem comes out when I'm trying to publish the application, compilation is generating the following error
_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.
- Add code below in *.csproj files to all of your projects.
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
- 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: