相关疑难解决方法(0)

如何将条件编译符号(DefineConstants)传递给msbuild

所以,这个这个都很清楚.简单地通过/p:DefineConstants="SYMBOL"

它对我来说根本不起作用,即使在测试项目中也是如此.我期望传递/ p:DefineConstants ="SYMBOL"将覆盖csproj中定义的任何条件编译常量.不是这样的......

完整代码列表如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DefineConstants
{
    class Program
    {
        static void Main(string[] args)
        {
#if DEV
            Console.WriteLine("DEV");
#elif UAT 
            Console.WriteLine("UAT");
#else
            Console.WriteLine("No environment provided");
#endif
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

.csproj文件是:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{57A2E870-0547-475C-B0EB-66CF9A2FE417}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>DefineConstants</RootNamespace>
    <AssemblyName>DefineConstants</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> …
Run Code Online (Sandbox Code Playgroud)

c# msbuild visual-studio

21
推荐指数
1
解决办法
3万
查看次数

MSBuild.exe不接受/ p:DefineConstants和/ p:PreprocessorDefinitions

我已经阅读了很多关于Stack Overflow的文章,这些文章回答了"如何从MSBuild命令行向编译器传递预处理器定义"的问题,并且他们都回复了一些变体:

MSBuild.exe /p:DefineConstants=THING_TO_BE_DEFINED
Run Code Online (Sandbox Code Playgroud)

我已经尝试了我能提出的每一个变体:

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"
Run Code Online (Sandbox Code Playgroud)

......还有其他几十个人.我也以类似的方式调整了重写PreprocessorDefinitions.所有这些都触发​​了下面的#error:

#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;
}
Run Code Online (Sandbox Code Playgroud)

我一直在尝试使用上面的简单命令行应用程序,以及我在这里的一个巨大的游戏项目.我只能猜测Visual Studio(我在2005年和2008年看到这个)有一些默认设置深入阻止我的命令行参数被应用,但我没有找到证据来支持这个假设.

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

msbuild macros command-line c-preprocessor

20
推荐指数
3
解决办法
2万
查看次数