How to write your own build script by using benefit from MSBuild environment variables configuration corresponding specified platform (C++)
The following XML enables to resolve this challenge. SetBuildDefaultEnvironmentVariables
is key of this.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="ManualBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PlatformToolset>v140</PlatformToolset> <!-- (Optional) only if want to explicitly specify platform toolset version -->
<TargetPlatformVersion>8.1</TargetPlatformVersion> <!-- (Optional) only if want to explicitly specify SDK version -->
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Target Name="ManualBuild">
<CallTarget Targets="SetBuildDefaultEnvironmentVariables" />
<Exec Command="echo %LIB%" />
</Target>
</Project>
Assumes the above XML is named as example.xml
, the following msbuild
command will print LIB
environment variable for linking x86 libraries no matter whether your machine is x64 or not.
msbuild example.xml /p:Platform=x86
On the other hand, the next one will print for ARM.
msbuild example.xml /p:Platform=arm