Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

visual studio 2010 - VS2010: How to use Environment Variables in Post-Build

On my PC I have created a system environment variable called 3DSMaxInstallDirectory

At the command line, if I give

echo %3DSMaxInstallDirectory%Plugins

I get

D:Program FilesAutodesk3ds Max 2011Plugins

In Visual Studio I enter into the Post-Build section

copy "$(TargetDir)$(TargetName).*" "$(3DSMaxInstallDirectory)Plugins"

However on build I get

Error   4   The command "copy "C:UsersSebastianDocumentsVisual Studio 2010ProjectsMaxBridgeMaxBridgeImporterPlugininDebugMaxBridgePlugin.*" "Plugins"
" exited with code 1.   MaxBridgeImporterPlugin

The results on Google are a confusing mix of suggestions that Visual Studio doesn't support EVs, Visual Studio does support EVs, Visual Studio needs %..% and Visual Studio needs $(..) - and none of which seem to work on my computer.

What is the correct way to use my environment variable in Visual Studio?

(Yes, the directory exists, and the reason I don't want to set the path explicitly is I am preparing to share this project, and every step someone else has to take after downloading and before building is another barrier.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This works for me in the Post-Build setting of the 'Build Events' of the project.

echo %CodeContractsInstallDir%
echo %DXSDK_DIR%
echo "%ONLYME%"

ONLYME is a environment var in the User variables of my profile.

The others are System wide vars.

ONLYME stays empty if I start VS2010 as administrator, the systemvars still have values as expected.

I'm on V2010 SP1


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...