问题
Is it possible to split the information in a .csproj across more than one file? A bit like a project version of the partial class
feature.
回答1:
You can not have more than one master csproj. But because the underneath wiring of the csproj is done using msbuild you can simply have multiple partial csproj that import each other. The solution file would see the most derived csproj.
project1.csproj
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
....
</Project>
project2.csproj
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="project1.csproj" />
...
</Project>
project.csproj - this is the main project that is referred by the solution file.
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="project2.csproj" />
...
</Project>
Bottom line is that using msbuild Import feature you can have partial csproj files where each one would contain definitions that the main project (project.csproj in my example) would use.
Visual Studio will show a Security Warning for project dialog when you open your changed solution or project file. Choose the option Load Project Normally and press OK. When opening the solution again later the warning will not be shown because the configuration to Load Project Normally is stored in the suo file.
回答2:
Yes, you can split information across several files. You can use Import Element (MSBuild).
Note that Visual Studio will give you annoying security warning if you will try to open project file that includes other project files.
Useful linky from MSDN:
How to: Use the Same Target in Multiple Project Files
Note that external files have .targets extension by conventions.
回答3:
Well you can have multiple projects combined into one large solution, but I don't think that is quite what you had in mind as each project has to be a complete project in that case.
来源:https://stackoverflow.com/questions/157149/partial-csproj-files