Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing VS2010 environment variables for WIX

I need to build two branded versions of my WIX based installer. The only difference between the the versions is a single bitmap containing the company contact details. I'd like to keep a single WIX project so I have less projects to maintain. I'm using an environment variable to alter which bitmap is inserted into the installer

Source="$(env.CompanyName) contact.png"

This works fine, however I cannot change the environment variable from within VS2010. VS2010 is compiling the WIX installers using the environment variables that were set when VS2010 started. I have to restart VS2010 to get it to pick up the new environment variable value.

I have 36 nested projects so I don't want to have to set the build variables within each project - that's why I'm trying to use an environment variable.

Does anyone know how to change one of the environment variables used by the current VS2010 instance? Or perhaps there is a better way?

like image 354
Andrew Jones Avatar asked Nov 30 '11 00:11

Andrew Jones


People also ask

How do I set global environment variables?

Search and select System (Control Panel). Click on the Advanced system settings link and then click Environment Variables. Under the section System Variables, select the environment variable you want to edit, and click Edit. If the environment variable you want doesn't exist, click New.


1 Answers

I do this and significantly more customization in a single WiX project. I have a different project configuration for each variant. So rather than "Debug" and "Release", I have for example "Debug", "East" and "West". This only applies to the setup project. The code projects still use "Debug" and "Release". The WiX compiler can read the configuration value.

<?if   $(var.Configuration)="West"?>
  <?define CompanyName="West Coast Office"?>
<?elif $(var.Configuration)="East"?>
  <?define CompanyName="East Coast Office"?>
<?else?>
  <?define CompanyName="Debugging purposes"?>
<?endif?>

Source="$(var.CompanyName) contact.png"

Alternatively, you can add it to the setup project's preprocessor variables (Project Properties, Build, General), but again, you'll require multiple configurations:

CompanyName=West Coast Office

And in your Product.wxs:

Source="$(var.CompanyName) contact.png"

To add the configurations in Visual Studio:

  1. Open the menu Build, Configuration Manager...

    Create solution configurations

  2. Under Active solution configurations select <New...>
  3. Type the Name (eg. East), Copy settings from Release, and do not create new project configurations.
  4. Repeat steps 2 and 3 for the other office (eg. West).

    Create setup project configurations

  5. Next to the setup project, open the Configuration drop down and select <New...>
  6. Type the Name East, Copy settings from Release, and do not create new project configurations.
  7. Repeat steps 5 and 6 for West.

    Delete setup project's Release configuration

  8. Next to the setup project, open the Configuration drop down and select <Edit...>
  9. Select Release and press Remove, followed by Yes and Close.

    Delete solution's Release configuration

  10. Under Active solution configurations select <Edit...>
  11. Select Release and press Remove, followed by Yes and Close.

    Assign the project configurations to the solution configurations

  12. Under Active solution configurations select East.
  13. Set the setup project's Configuration to East and every other project's configuration to Release. Tick Build next to each project (assuming you need all of them.)
  14. Repeat steps 12 and 13 for West.

Now when you select each solution configuration, you should have the following settings:

Solution       Debug    East     West
------------------------------------------
Main Project   Debug    Release  Release
Setup Project  Debug    East     West

Finally, go into the setup project's properties and ensure everything is correct for the East and West configurations. Take note of the output folder. If that is still bin\Release, then the two configurations will overwrite eachother's output. Set it to bin\East and bin\West respectively.

like image 198
Hand-E-Food Avatar answered Oct 30 '22 22:10

Hand-E-Food