How do you pass conditional compilation symbols (DefineConstants) to msbuild

前端 未结 2 1708
独厮守ぢ
独厮守ぢ 2020-12-10 01:23

So, both this and this are pretty clear. Simply pass /p:DefineConstants=\"SYMBOL\"

It doesn\'t work at all for me, even in a test project. I\'m expectin

2条回答
  •  臣服心动
    2020-12-10 01:47

    Using DefineConstants definitely does work. Which means you are doing something wrong. My guess is you first built the project without defining anything, then built it again. MSBuild will then see the project was built already and won't build again, but just copy output files. You should post the output of msbuild so we can be sure, but for reference I compiled your project using the necessary switches only and here is the result (full msbuild output omitted):

    > msbuild ConsoleApplication1.sln /p:DefineConstants="DEV" /t:Rebuild
    ....
    Building solution configuration "Debug|x86".
    Project ... is building ConsoleApplication1.csproj" (Rebuild target(s)).
    ...
    > ConsoleApplication1\bin\Debug\DefineConstants.exe
    DEV
    > msbuild ConsoleApplication1.sln /p:DefineConstants="UAT" /t:Rebuild
    ...
    > ConsoleApplication1\bin\Debug\DefineConstants.exe
    UAT
    > msbuild ConsoleApplication1.sln /t:Rebuild
    ...
    > ConsoleApplication1\bin\Debug\DefineConstants.exe
    No environment provided 
    

提交回复
热议问题