By default, or specify msbuild properties in an external file

Ok, so I have dozens of solutions built using the same command line.

msbuild SolutionName.sln / p: property1 = value1; property2 = value2; etc etc etc.

Except that the number of properties is only growing and growing.

Is there a way to specify an external file in some way, so that I don't get the 10-line msbuild command? (Think of property 100, property 101, etc.).

I know the .wpp.target files. However, to copy them to each project folder, actually ... this is my last resort.

And no, I do not change any default MSBuild targets / files.

+6
source share
3 answers

First of all, I would recommend using msbuild scripts to create your solutions instead of directly creating a sln file using the command line. For instance. use something like this:

msbuild SolutionName.Build.proj 

and inside this Solution1.Build.proj you can put everything 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 begin to use the additional property metadata for the MSBuild task.

Then you can use the <Import construct to store the list of common properties in a separate file and item metadata to pass 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 information on properties and additional property metadata or this original MSDN link (highlight the "Metadata Properties" section)

This is the basic idea of ​​how to do this, if you have any questions - feel free to ask.

+6
source

To answer the original question, yes, you can specify the properties in an external file. These are called MSBuild response files.

 msbuild somesolution.sln @PathToResponseFile.rsp 

Inside the answer file, you can put your properties, one per line.

 /verbosity:detailed /target:build /platform:AnyCPU /configuration=Release 

Some links to better understand: http://dailytechlearnings.wordpress.com/2011/08/24/msbuild-response-file/ http://msdn.microsoft.com/en-us/library/vstudio/ms404301.aspx

However, using the msbuild file to create your solutions and projects is the best solution. You can create global goals that will do what you need. You can create your own Clean and Build targets, which will then create / clean your solutions.

+6
source

I use the import file for things that are common to different projects.

  <Import Project="CommonBuildProperties.proj"/> 

This file contains a PropertyGroup that has what I want to have the same value in build projects. There is also a conditional instruction that sets specific folder names depending on the name of the computer on which it is running. At runtime, if I need to override anything on the command line, I do this.

I also have import files for specific projects (one of our collections is a Powerbuilder application with its own set of tools and peccallillo); the import order ensures that they require different values ​​for the same element name. I get what I want.

My command lines are not terrible unless I do something weird that requires everything that everything is overridden. The only thing I need to convey is the version number and type of assembly (release or debugging).

+1
source

Source: https://habr.com/ru/post/959436/


All Articles