Domanda

Say for instance I have a Visual Studio project with a configuration called "MyConfig" and I have the compilation symbol MY_CONFIG_SYMBOL defined.

Is there a macro or command to see if MY_CONFIG_SYMBOL is defined in the pre/post build events? Something like #if MY_CONFIG_SYMBOL, but for the build event?

È stato utile?

Soluzione

I finally found an answer. The following works perfectly:

if "$(DefineConstants.Contains('DEBUG'))" == "True" <command>

This works for any constants defined in the build, but note that the constant is case-sensitive ('DEBUG' != 'Debug').

Altri suggerimenti

If you mean conditional builds based on the build types (Debug or Release) then yes. Check out these threads:

Conditional Post-build event in Visual Studio 2008

How to run Visual Studio post-build events for debug build only

Well, this is not a solution, just trying to advance state by sharing some experiments. (I've yet to find a way to test conditional compilation symbols.)

This as a way to consolidate switching debug on and off:

<#@ include file="debug.incl" #>`

some text1
<# if ( xdebug ) { #>
    foo = bas;
<# } #>
more text

Where debug.incl contains:

<# 
bool xdebug = true;
#>

The conditional (if) in the first file is able to see the value of xdebug, so output is altered based on the setting of xdebug in debug.incl.

Sadly, however, the output files are not rebuilt on changes to debug.incl, despite the obvious include of it. And even a clean & rebuild doesn't seem to trigger generation, so some separate build construct is need for that...

(I did try debug.tt instead of debug.incl to no avail, switch to .incl so that debug.cs wasn't created by debug.tt.)


This didn't work very well as it doesn't see conditional compilation symbols, though does actually switch on the template debug attribute!

<#
#if DEBUG 
bool xdebug = true;
#else
bool xdebug = false;
#endif
#>

some text1
<# if ( xdebug ) { #>
    foo = bas;
<# } #>
more text

with <#@ template debug="true" #> vs. <# template debug=false #> you get the conditional output or not, respectively.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top