【问题标题】:How to detect debug/release in visual studio pre/post-build command line?如何在 Visual Studio 构建前/构建后命令行中检测调试/发布?
【发布时间】:2011-08-18 23:55:26
【问题描述】:
如何从命令行 pre-build 或 post-build 窗口检测 Debug 或 Release 模式?
我测试了下面的代码,它在代码文本窗口中工作。
它可以转换为命令行代码吗?
如果可以,怎么做,谢谢。
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);
【问题讨论】:
标签:
c#
visual-studio
c#-2.0
pre-build-event
post-build-event
【解决方案1】:
您可以检查$(ConfigurationName) 变量的值。
它与您在代码示例中使用的不同。 #if DEBUG 是一个条件编译指令,它取决于 DEBUG 是否已被定义为符号。 ConfigurationName 变量取决于您指定的构建配置(与条件编译符号无关)。
【解决方案2】:
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)