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

时间:2021-01-15 22:44:34

How do I set Environment Variables in Visual Studio 2010?

如何在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:

但是当我选择“配置属性”时,没有“环境”选项:

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

This is an example in VS 2008:

这是VS 2008中的一个例子:

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

But how is it done in VS 2010?

但是如何在VS 2010中完成?

2 个解决方案

#1


14  

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.

您正在将VS2008中的C ++项目与VS2010中的C#项目进行比较。这两个项目使用不同类型的构建引擎。 VS2008 C ++项目使用基于make的构建并使用大量环境变量。 VS2010(和VS2008)C#项目使用MSBuild,很少(1)依赖于环境变量。

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.

除非您修改了.csproj文件或拥有自定义构建工具,否则更改环境变量不应该是您想要的任何方式。如果您描述目标,我们将能够更好地帮助您获得如何实现目标的建议。

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.

更新:MSBuild可以使用环境可变量。但是,VS不提供用于为标准C#项目设置的UI(即使您安装了早期版本)。很可能你正在查看的构建项目是使用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)
  • 在记事本中打开.csproj文件,并使用您要设置的值将所需的特定变量添加到 元素。 (在MSBuild的工作中设置的属性,如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> ...
  • 如果使用msbuild.exe从命令行构建,则可以在命令行中指定这些属性,如下所示:msbuild / property: = ...

  • 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.
  • 您可以创建一个.settings文件,其中包含带有所有属性的文件,然后将其包含在需要共享相同值的所有.csproj文件中。

  • 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.
  • 您可以打开一个新的命令提示符,在其中设置环境变量,然后从其中启动VS. VS将从该命令提示符中获取环境。

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

(1)我很想说“从不”,但我确实有几个项目,我希望构建依赖于环境变量,主要是为了在没有安装.Net的机器上实现自动构建。

#2


-1  

Simply add an eviroment variable in system. In command line SET VAR=VALUE Then pick it up with $(VAR)

只需在系统中添加一个eviroment变量。在命令行SET VAR = VALUE然后用$(VAR)拿起它

#1


14  

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.

您正在将VS2008中的C ++项目与VS2010中的C#项目进行比较。这两个项目使用不同类型的构建引擎。 VS2008 C ++项目使用基于make的构建并使用大量环境变量。 VS2010(和VS2008)C#项目使用MSBuild,很少(1)依赖于环境变量。

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.

除非您修改了.csproj文件或拥有自定义构建工具,否则更改环境变量不应该是您想要的任何方式。如果您描述目标,我们将能够更好地帮助您获得如何实现目标的建议。

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.

更新:MSBuild可以使用环境可变量。但是,VS不提供用于为标准C#项目设置的UI(即使您安装了早期版本)。很可能你正在查看的构建项目是使用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)
  • 在记事本中打开.csproj文件,并使用您要设置的值将所需的特定变量添加到 元素。 (在MSBuild的工作中设置的属性,如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> ...
  • 如果使用msbuild.exe从命令行构建,则可以在命令行中指定这些属性,如下所示:msbuild / property: = ...

  • 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.
  • 您可以创建一个.settings文件,其中包含带有所有属性的文件,然后将其包含在需要共享相同值的所有.csproj文件中。

  • 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.
  • 您可以打开一个新的命令提示符,在其中设置环境变量,然后从其中启动VS. VS将从该命令提示符中获取环境。

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

(1)我很想说“从不”,但我确实有几个项目,我希望构建依赖于环境变量,主要是为了在没有安装.Net的机器上实现自动构建。

#2


-1  

Simply add an eviroment variable in system. In command line SET VAR=VALUE Then pick it up with $(VAR)

只需在系统中添加一个eviroment变量。在命令行SET VAR = VALUE然后用$(VAR)拿起它