Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial .csproj Files

Tags:

c#

csproj

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.

like image 272
Richard Nagle Avatar asked Oct 01 '08 11:10

Richard Nagle


2 Answers

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.

like image 71
Jorge Ferreira Avatar answered Sep 22 '22 18:09

Jorge Ferreira


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.

like image 21
aku Avatar answered Sep 22 '22 18:09

aku