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.
I do not think this can be done at project level: the vc project file is not parsed for logical statements as far as I know (apart from the build events in which you can use batch file syntax but that's because they are ran as a batch file).
The only thing you can do is create a global environment variable that has the default variable. It will be overriden if the environment in which devenv is called also specifies it.
environment:
MYVSOUTDIR="c:/temp"
vcproj/vsprops:
OutputDirectory="$(MYVSOUTDIR)\_$(ConfigurationName)_$(PlatformName)"
override this in a batch file:
set MYVSOUTDIR="d:/mytemp"
devenv
hmm, apparently I do not know how to fromat XML here
<PropertyGroup Condition=" '$(your_var)' == '' ">
<your_var>default</your_var>
</PropertyGroup>
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.
来源:https://stackoverflow.com/questions/2002420/optional-environment-variables-with-vcproj-vsprops