Default or specify msbuild properties in an external file

msbuild

Solution

First of all - I would recommend you to use msbuild scripts to build your solutions, instead of direct building sln file using command line. E.g. use something like this:

msbuild SolutionName.Build.proj

and inside this Solution1.Build.proj you can put anything as simple as

<Project ToolsVersion="4.0" DefaultTargets="BuildMe" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="BuildMe">
        <MSBuild Projects="SolutionName.sln" Properties="property1=value1;property2=value2;"/>
    </Target>
</Project>

After this step, which adds flexibility to your build process, you can start leverage AdditionalProperties metadata for MSBuild task.

Then you can use `<Import` construction to store your list of shared properties in a separate file and item metadata for passing property values:

<Project ToolsVersion="4.0" DefaultTargets="BuildMe" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="MySharedProperies.props" />
    <ItemGroup>
      <ProjectToBuild Include="SolutionName.sln">
        <AdditionalProperties>SomeProjectSpecificProperty</AdditionalProperties>
      </ProjectToBuild>
    </ItemGroup>

    <Target Name="BuildMe">
        <MSBuild Projects="@(ProjectToBuild)" Properties="@(MySharedProperies)"/>
    </Target>
</Project>

You can check this post for more details about properties and additional properties metadata or this original MSDN reference (scroll to Properties Metadata section)

This is the base idea how to do it, if you have any questions - feel free to ask.

Problem

Ok, so I have a few dozen solutions all built using the exact same command line. msbuild SolutionName.sln /p:property1=value1;property2=value2;etc etc etc. Except the number of properties just grows and grows. Is there a way to specify an external file some how so I don't end up with a 10 line msbuild command? (Think property 100, property 101, etc). I'm aware of .wpp.target files. However, having to copy them into each project folder really... is my last resort. And no, I'm not modifying any default MSBuild targets/files whatsoever.

Original source