Optional environment variables with vcproj/vsprops

℡╲_俬逩灬. 提交于 2019-12-07 07:33:56

问题


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.


回答1:


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



回答2:


hmm, apparently I do not know how to fromat XML here

 <PropertyGroup Condition=" '$(your_var)' == '' ">
  <your_var>default</your_var>
 </PropertyGroup>



回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!