[ACCEPTED]-MSBuild.exe not accepting either /p:DefineConstants nor /p:PreprocessorDefinitions-c-preprocessor
If you are calling MSBuild on the command 10 line you cannot specify the value for DefineConstants. But 9 if you are building a .csproj, or another 8 MSBuild script, then you can specify it. If 7 you create a msbuild file to "replace" your 6 solution file then you can use that an specify 5 the value for that when you build your projects. For 4 example:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Default value here -->
<DefineConstants Condition=" '$(DefineConstants)'==''" >DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Projects Include="one.csproj" />
<Projects Include="two.csproj" />
</ItemGroup>
<Target Name="Build">
<MSBuild Projects="@(Projects)"
Properties="DefineConstants=$(DefineConstants)"/>
</Target>
</Project>
Then you can use msbuild.exe buid.proj /p:DefineConstants="YourValue;Debug;Trace"
Note the usage 3 of the quotes on the command line.
I have 2 written a blog post a while back about something 1 related to this at http://sedodream.com/2008/05/07/MSBuildBuildingTheSameProjectMultipleTimes.aspx.
If you want to define TRACE & DEBUG 1 Constants this should work:
msbuild mysln.sln /t:Rebuild /p:Configuration=Release /p:DefineConstants="DEBUG;TRACE"
The below are needed modification to the 7 vcxproj for the /p to work.
put <DefineConstants>< /DefineConstants>
under 6 the <PropertyGroup Label=Globals >
<PreprocessorDefinitions>$(DefineConstants);WIN32;_DEBUG;_CONSOLE;UNIT_TEST_SIM;%(PreprocessorDefinitions)
This 5 way MSBuild will know that for the preprocessor 4 it needs to use the values from the DefineConstants 3 which come from the Globals PropertyGroup 2 unless provided from the command line by 1 the /p:DefineConstants="MY_DEFINE"
For completeness, this is what I found worked 2 when I wanted THING_TO_BE_DEFINED="VALUE WANTED"
, for VB.NET, and msbuild 1 version 3.5.30729.1, in a batch file:
@msbuild /t:Rebuild /p:Configuration=Release;Platform="Any CPU";
DefineConstants="THING_TO_BE_DEFINED=\"VALUE WANTED\"" mysln.sln
(all on one line of course)
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.