Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage Bundle's code using preprocessor variables?

Tags:

wix

votive

burn

I had created several configurations on my bundle-project in Visual Studio and I want to define which fragments of code must be included in each configuration. My aim is to get several bootstrappers: some of them will include prerequisites and some will not. I tried something like:

<PackageGroup
       Id="Prerequisites">
      <?if $(Configuration)='Release'?>
      <ExePackage
        Id="Netfx4Client"
        Cache="yes"
        Compressed="yes"
        PerMachine="yes"
        Permanent="yes"
        Vital="yes"
        SourceFile=".\SupportFiles\dotNetFx40_Client_x86_x64.exe"
        DetectCondition="NETFRAMEWORK40CLIENT OR (VersionNT64 AND NETFRAMEWORK40CLIENTX64)"
        InstallCondition="(v4.0.30319 > NETFRAMEWORK40CLIENT OR NOT NETFRAMEWORK40CLIENT)  OR (VersionNT64 AND v4.0.30319 > NETFRAMEWORK40CLIENTX64 OR NOT NETFRAMEWORK40CLIENTX64)"
        InstallCommand="/q /norestart  /log [TempFolder]\dotnetframework4.log"/>
<?endif?>

But of course it is not correct.. Is it possible to manage which fragments of code will be included into chain of packages of the Bundle depending on any variable? Thank you.

like image 535
Nerielle Avatar asked Oct 04 '22 16:10

Nerielle


1 Answers

Yes, you first need to pass the MSBuild property to the compiler's preprocessor. In your .wixproj use the DefineConstants property to tunnel the property through. The default .wixproj provided by Votive does this by default for Configuration but for other properties it'd look like this:

<PropertyGroup>
   <DefineConstants>$(DefineConstants);MyNewVariable=$(MSBuildPropertyName)</DefineConstants>
</PropertyGroup>

Now that the MSBuild Property is a preprocessor variable you can do the following:

<?if $(var.Configuration)="Release" ?>
    Stuff to conditionally compile out
<?endif?>

Basically, your example above is correct except you're missing the var. part of the preprocessor variable name. More details on the preprocessor syntax in the documentation.

like image 95
Rob Mensching Avatar answered Dec 04 '22 21:12

Rob Mensching