更新时间:2022-10-20 19:17:12
您正在将VS2008中的C ++项目与VS2010中的C#项目进行比较。这两个项目使用不同的构建引擎。 VS2008 C ++项目使用基于make的构建并大量使用环境变量。 VS2010(和VS2008)C#项目使用MSBuild,很少(1)依赖于环境变量。
除非您修改了.csproj文件或自定义构建工具,变化的环境变量不应该是你想做的任何事情。如果您描述您的目标,我们将能够更好地帮助您建议如何实现。
更新:MSBuild可以使用环境vairables。但是,VS不提供用于设置标准C#项目的UI(即使您安装较早版本)。很可能您正在查看的构建项目旨在使用 msbuild.exe
从命令行构建。
您有几个选项:
< PropertyGroup>
使用要设置的值元素所需的特定变量。 (在MSBuild的工作中设置的属性与Make的环境变量一样) msbuild / property:< name> =<值GT; ...
(1)我很想说从不,但我确实有几个项目,我希望构建依赖于环境变量,主要是在没有.Net安装的机器上启用自动构建。
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:
This is an example in VS 2008:
But how is it done in VS 2010?
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:
<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) msbuild /property:<name>=<value> ...
(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.