How to: Modify C++ project properties and targets without changing the project file
You can override project properties and targets from the MSBuild command prompt without changing the project file. This is useful when you want to apply some properties temporarily or occasionally. It assumes some knowledge of MSBuild. For more information, see MSBuild.
Important
You can use the XML Editor in Visual Studio, or any text editor, to create the .props or .targets file. Don't use the Property Manager in this scenario because it adds the properties to the project file.
To override project properties:
Create a
.props
file that specifies the properties you want to override.From the command prompt:
set ForceImportBeforeCppTargets="C:\sources\my_props.props"
To override project targets:
Create a
.targets
file with their implementation or a particular targetFrom the command prompt:
set ForceImportAfterCppTargets ="C:\sources\my_target.targets"
You can also set either option on the msbuild command line by using the /p:
option:
msbuild myproject.sln /p:ForceImportBeforeCppTargets="C:\sources\my_props.props"
msbuild myproject.sln /p:ForceImportAfterCppTargets="C:\sources\my_target.targets"
Overriding properties and targets in this way is equivalent to adding the following imports to all .vcxproj
files in the solution:
<Import Project="C:\sources\my_props.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="C:\sources\my_target.targets" />