MSBuild.exe不接受/ p:DefineConstants或/ p:PreprocessorDefinitions [英] MSBuild.exe not accepting either /p:DefineConstants nor /p:PreprocessorDefinitions

查看:1174
本文介绍了MSBuild.exe不接受/ p:DefineConstants或/ p:PreprocessorDefinitions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经历了很多关于Stack Overflow的文章,回答了如何通过MSBuild命令行将预处理器定义传递给编译器的问题,他们都回应了一些变体:

  MSBuild.exe / p:DefineConstants = THING_TO_BE_DEFINED 

我尝试过每个变化,我可以想出:

  MSBuild.exe/ p :DefineConstants = THING_TO_BE_DEFINED
MSBuild.exe / p:DefineConstants =THING_TO_BE_DEFINED
MSBuild.exe/ p:DefineConstants = THING_TO_BE_DEFINED = 1
MSBuild.exe / p:DefineConstants = THING_TO_BE_DEFINED = 1

...和其他几十个。我也以类似的方式与重写PreprocessorDefinitions调情。所有人都触发了下面的#error:

  #includestdafx.h

#if !defined(THING_TO_BE_DEFINED)
#errorTHING_TO_BE_DEFINED未定义
#endif

int _tmain(int argc,_TCHAR * argv [])
{
return 0;
}

我一直在尝试这个简单的命令行应用程序以及一个巨大的游戏项目,我在这里。我只能猜测Visual Studio(我看到这与2005年和2008年)有一些默认设置深在其肠子,阻止我的命令行参数应用,但我没有发现没有证据支持这个假设。 / p>

有关如何让这个工作的任何想法?为什么以FSM的名义,他们没有坚持使用好的'-D THING_TO_BE_DEFINED?

解决方案

如果你打电话给MSBuild在命令行中不能指定DefineConstants的值。但是如果你正在构建一个.csproj或另一个MSBuild脚本,那么你可以指定它。如果创建一个msbuild文件来替换您的解决方案文件,那么您可以使用该文件在您构建项目时指定该值。例如:

 <?xml version =1.0encoding =utf-8?& 
< Project ToolsVersion =3.5DefaultTargets =Buildxmlns =http://schemas.microsoft.com/developer/msbuild/2003>
< PropertyGroup>
<! - 默认值here - >
< DefineConstants Condition ='$(DefineConstants)'==''> DEBUG; TRACE< / DefineConstants>
< / PropertyGroup>

< ItemGroup>
< Projects includeeone.csproj/>
< Projects includeetwo.csproj/>
< / ItemGroup>

< Target Name =Build>
< MSBuild Projects =@(Projects)
Properties =DefineConstants = $(DefineConstants)/>
< / Target>
< / Project>然后你可以使用 msbuild.exe buid.proj / p:DefineConstants =



< YourValue; Debug; Trace



注意命令行中引号的用法。



我已经在写了一篇关于这篇文章的博文http://sedodream.com/2008/05/07/MSBuildBuildingTheSameProjectMultipleTimes.aspx


I've been through quite a number of articles on Stack Overflow that answered the question "How do I pass preprocessor definitions to the compiler from the MSBuild command line," and they all responded with some variation of:

MSBuild.exe /p:DefineConstants=THING_TO_BE_DEFINED

I have tried every variation that I could come up with:

MSBuild.exe "/p:DefineConstants=THING_TO_BE_DEFINED"
MSBuild.exe /p:DefineConstants="THING_TO_BE_DEFINED"
MSBuild.exe "/p:DefineConstants=THING_TO_BE_DEFINED=1"
MSBuild.exe /p:DefineConstants="THING_TO_BE_DEFINED=1"

...and dozens of others. I've also flirted with overriding PreprocessorDefinitions in similar ways. All of them triggered the #error below:

#include "stdafx.h"

#if !defined(THING_TO_BE_DEFINED)
#error "THING_TO_BE_DEFINED is not defined"
#endif

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

I've been trying this with the simple command-line application above, as well as with a huge game project that I have here. I can only guess that Visual Studio (I'm seeing this with 2005 and 2008) has some default set deep in its bowels that is preventing my command line argument from being applied, but I've found no evidence to support this hypothesis.

Any ideas on how I can get this to work? Why in the name of FSM didn't they stick with good ol' -D THING_TO_BE_DEFINED?

解决方案

If you are calling MSBuild on the command line you cannot specify the value for DefineConstants. But if you are building a .csproj, or another MSBuild script, then you can specify it. If you create a msbuild file to "replace" your solution file then you can use that an specify the value for that when you build your projects. For 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 of the quotes on the command line.

I have written a blog post a while back about something related to this at http://sedodream.com/2008/05/07/MSBuildBuildingTheSameProjectMultipleTimes.aspx.

这篇关于MSBuild.exe不接受/ p:DefineConstants或/ p:PreprocessorDefinitions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆