如何在Visual Studio的预/后构建命令行中检测调试/发布模式?

4

如何从命令行的预编译后编译窗口检测DebugRelease模式?

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

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);
2个回答

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

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)

编辑:

另外,还可以参考这个答案,包括 PowerShell 命名参数和解决在 (ProjectDir) 中的空格和转义问题。 如何在 VS 后期构建事件中运行 PS 脚本时转义参数中的空格


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接