在我的C#
文件中,我想要有一个预处理条件,如下所示:
#if DEMO
ShowSplash();
#endif
我正在从命令行运行此命令:
MSBuild MySolution.sln /p:Configuration=Release /p:Platform="Any CPU" /p:DEMO=1
然后,在 MyProject.csproj
文件中,我有以下内容:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineConstants>TRACE;DEMO=$(DEMO)</DefineConstants>
</PropertyGroup>
但是预处理器似乎跳过了我的闪屏代码。(我知道"Any CPU"和"AnyCPU"的区别,我从未改动过它,所以我非常确定Visual Studio不会关心空格。)
DEMO
未定义?相同的结构似乎在其他项目类型(例如.wixproj
)中有效。我错过了什么?
.csproj
文件后进行清理/重建项目吗? - Bassiewarning MSB3052: 编译器的参数无效,'/define:DEMO=1'
。 - l33t<DefineConstants>TRACE</DefineConstants> <DefineConstants Condition=" $(DEMO) == 1 ">$(DefineConstants);DEMO</DefineConstants>
- user4003407MSBuild MySolution.sln /p:Configuration=Release /p:Platform="Any CPU" /p:Conditionals=DEMO
。然后在你的项目中使用<DefineConstants>TRACE;$(Conditionals)</DefineConstants>
。(可能有效,也可能无效;我没有测试过...) - user2819245#if X=1
。将这些内容放在答案中,我会接受的。 - l33t