MSBuild¶
The MSBuild build helper is a wrapper around the command line invocation of MSBuild. It abstracts the
calls like msbuild "MyProject.sln" /p:Configuration=<conf> /p:Platform=<platform> into Python method ones.
This helper can be used like:
from conan import ConanFile
from conan.tools.microsoft import MSBuild
class App(ConanFile):
settings = "os", "arch", "compiler", "build_type"
def build(self):
msbuild = MSBuild(self)
msbuild.build("MyProject.sln")
The MSBuild.build() method internally implements a call to msbuild like:
$ <vcvars-cmd> && msbuild "MyProject.sln" /p:Configuration=<configuration> /p:Platform=<platform>
Where:
<vcvars-cmd>calls the Visual Studio prompt that matches the current recipesettings.configuration, typically Release, Debug, which will be obtained fromsettings.build_typebut this can be customized with thebuild_typeattribute.<platform>is the architecture, a mapping from thesettings.archto the common ‘x86’, ‘x64’, ‘ARM’, ‘ARM64’, ‘ARM64EC’. This can be customized with theplatformattribute.
Customization¶
attributes¶
You can customize the following attributes in case you need to change them:
build_type (default
settings.build_type): Value for the/p:Configuration.platform (default based on
settings.archto select one of these values: ('x86', 'x64', 'ARM', 'ARM64', 'ARM64EC'): Value for the/p:Platform.
Example:
from conan import ConanFile
from conan.tools.microsoft import MSBuild
class App(ConanFile):
settings = "os", "arch", "compiler", "build_type"
def build(self):
msbuild = MSBuild(self)
msbuild.build_type = "MyRelease"
msbuild.platform = "MyPlatform"
msbuild.build("MyProject.sln")
conf¶
MSBuild is affected by these [conf] variables:
tools.build:verbosityaccepts one ofquietorverboseto be passed to theMSBuild.build()call asmsbuild .... /verbosity:{Quiet,Detailed}.tools.microsoft.msbuild:max_cpu_countmaximum number of CPUs to be passed to theMSBuild.build()call asmsbuild .... /m:N. Ifmax_cpu_count=0, then it will use/mwithout arguments, which means use all available cpus.
Reference¶
- class MSBuild(conanfile)¶
MSBuild build helper class
- Parameters:
conanfile –
< ConanFile object >The current recipe object. Always useself.
- command(sln, targets=None)¶
Gets the
msbuildcommand line. For instance, msbuild.exe "MyProject.sln" -p:Configuration=<conf> -p:Platform=<platform>.- Parameters:
sln –
strname of Visual Studio*.slnfiletargets –
targetsis an optional argument, defaults toNone, and otherwise it is a list of targets to build
- Returns:
strmsbuild command line.
- build(sln, targets=None)¶
Runs the
msbuildcommand line obtained fromself.command(sln).- Parameters:
sln –
strname of Visual Studio*.slnfiletargets –
targetsis an optional argument, defaults toNone, and otherwise it is a list of targets to build