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
202 views
in Technique[技术] by (71.8m points)

c# - How do I set Environment Variables in Visual Studio 2010?

How do I set Environment Variables in Visual Studio 2010?

I found this web page.

Which says:

From the Project menu, choose Properties.

In the left pane, select Configuration Properties, and then select Environment.

But when I select "Configuration Properties", there is no "Enviroment" option:

enter image description here

This is an example in VS 2008:

enter image description here

But how is it done in VS 2010?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You are comparing a C++ project in VS2008 to a C# project in VS2010. These two projects use different kind of build engine. VS2008 C++ project use a make-based build and use heavily environment variables. VS2010 (and VS2008 for that matter) C# projects use MSBuild and rarely (1) depend on environment variables.

Unless you have modified your .csproj file or have a custom build tool, changing environment variables should not be the way to do whatever you want to it is. If you describe your goal, we'll be able to better help you with advice how to achieve it.

Update: MSBuild can use environment vairables. However, VS does not provide an UI to set those for standard C# projects (even if you install earlier version). Most probably the build project you are looking at is intended to be build from the command line using msbuild.exe.

You have couple of options:

  • Open the .csproj file in Notepad and add to the <PropertyGroup> element the particular variable you need with the value you want to set. (properties set in a work for MSBuild like environment variables for Make)
  • If the environment variables are used only in the pre-build and post-build events, you can edit those in the Project properties, in the Build Events tab.
  • If you build from the command line using msbuild.exe, you can specify those properties on the command line, like this: msbuild /property:<name>=<value> ...
  • You can create a .settings file, which contains a with all the properties and then include it in all the .csproj files that need to share same values.
  • You can open a new command-prompt, set the environment variables in it and then launch VS from inside it. VS will pick up the environment from that command prompt.

(1) I was tempted to say "never", but I do have couple of projects where I want the build to depend on environment variables, mostly to enable automated builds on machines without .Net installed.


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

...