.NET项目中实现多工程文件共用的方法

具体实现为:编辑 .csproj 文件,在<ItemGroup>中添加新的 <Content /> 或 <Compile /> 节点:
Include: 属性值为项目文件的相对引用路径
Link: 节点中放置要引用到当前项目中的位置

1.无需编译的静态资源文件等,使用 标签引入

引用当前工程内的文件

<ItemGroup> <Content Include="Views\_EmailOfficeCancelledEmail.cshtml"/> </ItemGroup>

引用外部项目工程中的文件

<ItemGroup> <Content Include="..\MvcDemo\MvcWeb\Views\_EmailOfficeCancelledEmail.cshtml"> <Link>Views\_EmailOfficeCancelledEmail.cshtml</Link> </Content> </ItemGroup> 2.需要编译的cs文件等,使用 标签引入

引用当前工程内的文件

<ItemGroup> <Compile Include="Controllers\CommonController.cs"/> </ItemGroup>

引用外部项目工程中的文件

<ItemGroup> <Compile Include="..\..\MvcDemo\MvcWeb\Controllers\CommonController.cs"> <Link>Controllers\HomeController.cs</Link> </Compile> </ItemGroup> 3.最终实现的引用效果

20191105172528.png

二、使用 Visual Studio 软件可视化操作 1.右键添加现有项

2.添加为链接

20191106172410.png

3.最终实现的效果

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpgzss.html