Martin
Martin

Reputation: 768

How to override project properties on the command line using msbuild

I'm trying to build a Visual Studio solution (C++) using msbuild

 msbuild.exe mysolution.sln /p:platform="ARM" /p:configuration="Release"

I'm getting this error

error : all paths through this function will call itself [-Werror,-Winfinite-recursion]

I just want to be able to turn off -Werror from the command line, instead of turning it off in Project Properties > Configuration Properties > C/C++ > Treat Warnings As Errors

Thanks!

Edit 1. There are also other project properties that I would like to set that can't be fixed in code, such as Configuration Properties > General > Platform Toolset and Configuration Properties > General > Use of STL. FWIW, I'm targeting the ARM platform as you can see from my command line above.

Upvotes: 1

Views: 4534

Answers (1)

Leo Liu
Leo Liu

Reputation: 76860

According to this post which also provided by stijn, we could not change the value of “TreatWarningAsError” by the MSBuild command line directly. Because the “TreatWarningAsError” is a ClCompile not PropertyGroup in the project file. You can add a target invoke MSBuild to pass an external parameter into the project file by MSBuild command line:

First, change the fixed values of “TreatWarningAsError” in the project file:

<ClCompile>
   ...
   <TreatWarningAsError>$(TWAESettings)</TreatWarningAsError>
</ClCompile>

Second, add a target in to the project file:

  <Target Name="TestBuild" Returns="@(ManagedTargetPath)">
    <MSBuild Projects="YourProjectName.vcxproj" Targets="NormalBuild" Properties="TWAESettings=true"/>
  </Target>

Third, use the MSBuild command line with the properties true or false:

msbuild /p:TWAESettings=false Or msbuild /p:TWAESettings=true

Update:

For Configuration Properties > General > Platform Toolset and Configuration Properties > General > Use of STL

You can change the Platform Toolset by the MSBuild command line directly:

msbuild /p:PlatformToolset=v140_xp

But I could not find "Use of STL", just "Use of ATL" instead. If "Use of STL" is a PropertyGroup in the project file, you can also change it by the MSBuild command line directly.

Upvotes: 2

Related Questions