Moving compiled elements in msbuild to a separate file?

This is probably a FAQ, but we could not find a solution even after a great search.

We have several msbuild files that work in one set of source files. (This is not particularly relevant, but they are compiled on completely different platforms.) To simplify the management of them, we would like to move the names of the source <Compile> files to a separate file and link to all msbuild files.

We tried to cut off the <ItemGroup> containing the <Compile> elements and paste it into a new file and surround it

<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

and then referring to this file from the original to

<Import Project="Common.files.csproj" />

but this will not work - the solution opens (with a warning, since we cracked the default configuration), but nothing is displayed in the solution explorer.

What are we doing wrong?

+7
source share
2 answers

Tried with Visual Studio 2010:

1) Create your external .proj file (or .target) and add your files (I used a different element name, but that doesn't matter)

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <ExternalCompile Include="Program.cs" /> <ExternalCompile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> </Project> 

2) Import your external .proj file to the top of the Visual Studio project file :

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="MyExternalSources.proj" /> <PropertyGroup> ... 

and change the Compile ItemGroup as follows:

 ... <ItemGroup> <Compile Include="@(ExternalCompile)" /> </ItemGroup> ... 

Warning: You will need to add new elements / files to your external .proj file - all elements / files added from Visual Studio will look like this:

 ... <ItemGroup> <Compile Include="@(ExternalCompile)" /> <Compile Include="MyNewClass.cs" /> </ItemGroup> ... 
+10
source

I have never seen include files work with MSBuild. Obviously, Targets files work this way, but I have not seen the partial msbuild file included in another. Is it possible to use a method, for example, illustrated on this?
http://msdn.microsoft.com/en-us/library/ms171454(VS.80).aspx

Using wildcards is how I have used this in the past.

0
source

All Articles