Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using compiler constants in build events

Is there anyway to use compiler constants in Build Events in Visual Studio - VB.NET? (especially in Post-Build events)

Scenario

If TEST_EDITION=TRUE is defined I want to run an executable during the Post-Build event so if it's FALSE then I'll run something else.

This can be used for creating different installers for different editions.

P.S. Before someone suggests: No I don't want to use nant, msbuild or something like that

like image 833
dr. evil Avatar asked Feb 27 '10 12:02

dr. evil


1 Answers

Yes, the $(DefineConstants) macro is available and can be tested in a build event. For example, Project + Compile, Advanced Compile Options, Custom constants = Test can be tested like this:

if /i "$(DefineConstants)" NEQ "TEST" goto skiptest
echo Setting up for test environment
:skiptest

More complicated custom constants like Test=TRUE or compound constants need to be parsed differently. Admittedly I quickly gave up trying to figure out how to use the horrid FOR command.

like image 54
Hans Passant Avatar answered Nov 15 '22 07:11

Hans Passant