NETSDK1152 发布 ASP.NET Core 6 时 _ViewImports.cshtml 文件出现多个输出文件错误
最近我将我的 asp.net core 3.1 Web 应用程序迁移到 NET6。在迁移之前,我没有遇到此类问题。我的网络应用程序有几个项目(DLL),其中一些项目由于要求而具有视图和控制器。我将这些项目标记为 Skd.Razor,如下所示:
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
我将 Startup 配置为使用应用程序部分来识别这些控制器和视图:
每个项目都有自己的 _ViewImports.cshtml ,包括主项目SicotX:
当我尝试发布应用程序时出现问题,编译生成以下错误
_ViewImports.cshtml 导致两个项目中的输出路径发生冲突,除了主要 SiotX 项目。
我需要在这些项目中使用 _ViewImports,所以我需要您的帮助或指导如何克服这个阻碍我的问题,或者是否可以使用独特的 _ViewImports.cshtml 并与所有项目共享?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 .NET SDK 6.0.100 中,如果来自不同源路径的文件被复制到发布输出中的同一文件路径,.NET SDK 会生成新错误 (NETSDK1152)。当项目及其项目引用包含与发布输出中包含的名称相同的文件时,可能会发生这种情况。
请访问生成重复文件错误在发布输出中获取详细信息。
我找到了一些可以帮助您解决此问题的建议。
将以下行添加到您的 common.props (位于解决方案的根目录中):
参考文献:
发布错误:发现多个具有相同相对路径的发布输出文件
_ViewImports.cshtml 文件出现 NETSDK1152 错误
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 the following lines to your common.props (located in the root directory of your solution):
References:
Publish error: Found multiple publish output files with the same relative path
NETSDK1152 Error for _ViewImports.cshtml files