Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override property sheet on the command line

Tags:

msbuild

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?

like image 750
MuertoExcobito Avatar asked Oct 19 '25 05:10

MuertoExcobito


1 Answers

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.

like image 100
stijn Avatar answered Oct 22 '25 03:10

stijn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!