Search code examples
visual-studioenvironment-variablesvspropsvcbuild

Optional environment variables with vcproj/vsprops


Is there any way to make an environment variable substituion in a project file (with or without vsprops) that, if the variable is not found, is substituted instead with a default value? I haven't found any way to do this, because everything seems to override environment variables.

EDIT: I need this to work for a property, not for an environment variable. Specifically, devenv may be invoked from another source with an environment variable specifying the target build directory. If that variable doesn't exist (perhaps because devenv is just being used as the IDE) then it should use a default.

I already have this working for MSBuild; I now need it working for VCBuild.


Solution

  • I know it's technically outside the purview of my original question, but I've gone about solving this by writing an add-in that will detect if the environment variable is set and, if not, construct the variable's default value and store it. It's not the most elegant solution, but it works.