1

I need to use an environment variable.

The CMD Prompt shows the following content

VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\

Now I try to use this

  <Merge Id='VC_CRT_x86' 
     Language='0' 
     SourceFile='$(env.VCINSTALLDIR)\Redist\MSVC\14.16.27012\MergeModules\Microsoft_VC141_CRT_x86.msm'  
     DiskId='1' 
  />

But I get the message

error CNDL0150: Undefined preprocessor variable '$(env.VCINSTALLDIR)'.

Using the full path works.

I compile from within the VS-2019 environment.

EDIT: When I use a simple CMD window and I use Candle.exe from there. Everything works. It seams that the environment variables are not passed within VS-2019.

EDIT2: Using devenv.exe /build release mywxsproject.sln works too!

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • 1
    Heads-up on this issue: [WiX 3.14](https://stackoverflow.com/questions/57589954/wix-vs-schema-and-visual-studio-2019/57593964#57593964) - [WixVSExtension](https://wixtoolset.org/documentation/manual/v3/customactions/wixvsextension.html). Not the same, but since you use VS2019. – Stein Åsmul Sep 16 '19 at 14:05

1 Answers1

1

UPDATE: First a couple of links on the issue of environment variables and running processes:


cmd.exe: You are probably doing "set" from a Visual Studio Developer Command Prompt as opposed to doing "set" from a regular cmd.exe => this yields a false list of what are actual environment variables.

Visual Studio Developer Command Prompt: The Visual Studio Developer Command Prompt is essentially a batch file which launches cmd.exe with a number of developer tweaks. How this all works I have no idea, but that's the essence. We may need to summon Mr. Heath Stewart to get to the bottom of this?

WiX Variables: I did a smoke test and the $(env.MY_VALUE_HERE) construct should resolve if the environment variable is set from the environment variable applet:

rundll32.exe sysdm.cpl,EditEnvironmentVariables

Press Windows Key, tap R, paste the above and press Enter.

Solutions: In the realm of fixes I am not sure what to suggest since I don't know what the purpose is in detail. I am suspecing you want everything to "run out of the box", but I would simply copy all the merge modules you need to the release area where you assemble your setup:

Something like this:

  • $(env.VCINSTALLDIR)\Redist\MSVC\14.16.27012\MergeModules\Microsoft_VC141_CRT_x86.msm

  • \\Releases\Common\MergeModules\Microsoft_VC141_CRT_x86.msm

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • I have to disagree. If I start a batch file from within the build process in VS-2019, the required variables are there. I have a post and pre build processthat uses them successfully. Also using it pure from the command line works, but only the build process inside VS-2019 fails.See new note: – xMRi Sep 17 '19 at 05:53
  • Did you try WiX 3.14? – Stein Åsmul Sep 17 '19 at 08:03
  • No. Currently I have no time to switch. – xMRi Sep 18 '19 at 10:46
  • I suppose you could try to add it as a "real" environment variable? Not that clean (sort of an override - visual studio might even complain?), but I guess it could work for now? I really would propose to put all merge modules on a shared UNC path though - since they can be included in any package that way and it gives you a "preserved library" of merge modules? – Stein Åsmul Sep 18 '19 at 10:54