tags:

views:

699

answers:

3

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.

A: 

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.

workmad3
+3  A: 

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.

aku
You can choose to Load Project Normally and the next time the project will open without the warning. This is stored in the suo file.
smink
I know, but suo files usually not stored under source control.
aku
Yes, true. As they add no value to compilation.
smink
+7  A: 

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"&gt;
    ....
</Project>

project2.csproj

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    <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"&gt;
    <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.

smink