在解决方案.NET中存储可用于不同项目的文件 [英] Storing files that available to different projects in solution .NET
问题描述
我有一个解决方案,其中包含2个.NET MVC项目和一些类库项目.我也有一些xml文件.我需要将这些xml文件放在一个地方,并可以从这2个.NET MVC项目中访问它们.这些文件也需要发布.我可以在类库项目中创建App_Data文件夹并将这些xml文件放在那里并使用它们吗?还是与.NET MVC项目相关的App_Data文件夹?
I have one solution with 2 .NET MVC projects and some class library projects. Also I have some xml files. I need to put these xml files in one place and have access to them from these 2 .NET MVC projects. These files need also be published. Can I create App_Data folder in class library project and put these xml files there and use them? Or App_Data folder just related to .NET MVC projects?
如何解决我的问题?
推荐答案
第1步.创建共享文件夹(不包含在您的项目中)并将所有共享文件复制到此处.第2步.更改 .csproj 文件并描述构建前的操作,该操作只会将所有需要的文件从共享文件夹复制到您的项目中.像这样:
Step 1. Create shared folder (that does not included into your projects) and copy all shared files there. Step 2. Change .csproj file and describe pre-build action, that just will copy all needed files from shared folder into your project. Something like this:
<Target Name="CodeAnalysisRuleset" BeforeTargets="PreBuildEvent" Condition="$(ConfigurationName) == Debug">
<Exec Command="xcopy /Y "$(SolutionDir)\SharedCodingRules\codeAnalysis.ruleset" "$(ProjectDir)"" />
</Target>
第3步.将新文件明确包含到您的项目中(再次更改您的.csproj文件)
Step 3. Explicitly include new files into your project (again change you .csproj file)
<ItemGroup>
<Content Remove="stylecop.json" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
完成这三个步骤后,您将可以在不同项目中使用共享文件(配置,rullset等).
After those 3 steps you will be able use shared files (configurations, rullsets etc.) in differnt projects.
这篇关于在解决方案.NET中存储可用于不同项目的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!