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)
S开发者_开发技巧cenario
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
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.
Have you tried the MsBuild PostEvents? this is an extract of a .csproj... but the same applies to vbproj files
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="$(BinariesFolder)" ContinueOnError="true" />
</Target>
You can use it with the TaskExec Target, which allows you to run a batch file or an executable.
<Target Name="DoSomething">
<Exec Command="D:\DoSomething.exe"/>
</Target>
Not sure about Visual Basic's syntax, but the following trick can be used by C++: the file global_inc.bat reads as:
SET PARAMETER=TRUE
This could be input by a batch script which was called in post-build event. The C++ code used the file as follows:
#define PARAMETER const int parameter
#define SET /**/
#include "global_inc.bat"
;
#undef PARAMETER
The postbuild step looked like this:
call global_inc.bat
if "%PARAMETER%" == "TRUE" echo True
Another possibility would be for the prebuild step to generate a .vb
file, as well as a configuration file used in postbuild step.
精彩评论