4

I am searching for a way to pass a property sheet (.props file) on the command line to MSBuild. MSBuild does not seem to have a specific switch for property sheets, but does have a /property command line switch, which you can use to override individual properties within the project.

Is there some way to either provide a property sheet on the command line, or, perhaps use the /property switch to apply the property sheet?

MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78

1 Answers1

2

In your project file add an Import like

<Import Project="$(CustomProps)" Condition="Exists($(CustomProps))" />

Just add it where the other imports are, or if you don't want to repeat yourself for each configuration/platform combination, add it either below the <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/> line (in which case other property sheets can override values from it) or above the <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/> line (so you can apply 'final' values with your custom property sheet).

Then on the commandline pass /p:CustomProps=/path/to/props

edit msbuild also has this functionality built-in, just figured this is sort of a duplicate of How to set PreProcessorDefinitions as a task propery for the msbuild task. Except there if you want to control where the import happens you'd have to choose between ForceImportBeforeCppTargets and ForceImportAfterCppTargets.

Community
  • 1
  • 1
stijn
  • 34,664
  • 13
  • 111
  • 163