且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何设置在Visual Studio 2010环境变量?

更新时间:2021-08-16 01:52:00

您在VS2008比较一个C ++项目在VS2010 C#项目。这两个项目都使用不同的编译引擎。 VS2008 C ++项目使用化妆基础的建立和使用大量的环境变量。 VS2010(和VS2008为此事)C#项目中使用的MSBuild,很少(1)依赖于环境变量。

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.

除非您修改过的.csproj文件或有一个自定义生成工具,改变环境变量的不应该做任何你想做的事情是这样的。如果你描述你的目标,我们将能够更好地帮助你的意见如何实现它。

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.

更新:MSBuild的可以使用环境vairables。但是,VS不提供用户界面来设置这些标准C#项目(即使安装了早期版本)。最大的可能是你正在寻找在构建项目旨在通过命令行中使用 msbuild.exe 打造。

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.

您有两个选择:

  • 在记事本中打开的.csproj文件,并添加到<的PropertyGroup> 元素,你需要和你想要设置的值的特定变量。 (为的MSBuild般的环境变量做出的工作设置属性)
  • 如果环境变量只用于在pre-构建和生成后事件,您可以编辑那些在项目属性,在Build事件选项卡。
  • 如果您使用msbuild.exe命令行构建,你可以在命令行上这些属性,就像这样:的MSBuild /属性:其中;名称> =<价值> ...
  • 您可以创建一个.settings文件,它包含了所有的属性,然后将其包含在所有需要共享同一个值的.csproj文件。
  • 您可以打开一个新的命令提示符下,设置它的环境变量,然后从里面推出VS。 VS将拿起环境,从命令提示符。
  • 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)我很想说从来没有,但我有几个我想要构建依赖于环境变量的项目,主要是为了启用自动构建的机器上没有安装.NET。

(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.