4

如何从命令行预构建构建后窗口检测调试发布模式?

我测试了下面的代码,它在代码文本窗口中工作。它可以转换为命令行代码吗?如果可以,怎么做,谢谢。

bool debugging = false;
#if DEBUG
    debugging = true;
    // do something like to move ../debug/bin/ to somewhere.
#else
    debugging = false;
    // do something like to move ../debug/bin/ to somewhere.
#endif

Console.WriteLine(debugging);
4

2 回答 2

8

您可以检查$(ConfigurationName)变量的值。

它与您在代码示例中使用的不同。#if DEBUG是一个条件编译指令,取决于是否DEBUG被定义为符号。该ConfigurationName变量取决于您指定的构建配置(独立于条件编译符号)。

于 2011-05-05T01:20:24.167 回答
0
echo **** Visual Studio PREBUILD... **** 
echo **** Remember these are running from command line, aka BATCH commands 
echo **** watch out (include) single space after the conditional (and other ridiculous traps and pitfalls)
echo **** so I HIGHLY recommend getting out of BATCH and into Powershell as soon as possible.  Make prebuild a one-liner and then put additional code in your powershell... (you will thank me later)
echo **** Read more about why I'd rather claw my eyes out than program in BATCH here: https://www.tutorialspoint.com/batch_script/batch_script_if_else_statement.htm

if "Debug" == $(ConfigurationName) (
  echo OPTIONALLY just pass in the Configuration name and do all the logic and checking INSIDE the powershell.  Seriously, it is way better.
  powershell .\DevBox.Prebuild.ps1 -Config:$(ConfigurationName)
)

echo *** Much better to just check for Debug INSIDE the powershell
powershell .\DevBox.Prebuild.ps1 -Config:$(ConfigurationName)
于 2021-10-19T19:37:19.843 回答