通过msbuild设置vcbuild环境 [英] set vcbuild environment through msbuild

查看:179
本文介绍了通过msbuild设置vcbuild环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个msbuild项目文件,该文件用于构建多个C ++项目(* .vcproj).这是典型项目文件的一部分,其中构建的全局环境变量被覆盖为属性:

I have an msbuild project file that is used for building several C++ projects (*.vcproj). Here's a part of a typical project file, in which global environment variables for the build are overridden as properties:

<PropertyGroup>
  <MYBINDIR>d:\buildsysroot\bin</MYBINDIR>
  <MYLIBDIR>d:\buildsysroot\lib</MYLIBDIR>
  ...
</PrpertyGroup>

<ItemGroup>
  <MyItems Include="d:\buildsysroot\myproject\myproject.vcproj"/>
</ItemGroup>

<Target Name="Release_x64">
  <VCBuild Projects="@(MyItems)" Configuration="Release_dll|x64"/>
</Target>

这些vcproj文件通过属性表使用这些环境变量. 这是vcproj的摘录:

These environment variables are used by all vcproj files, through property sheets. Here's an excerpt of a vcproj:

<Configuration
  Name="Release_dll|x64"
  ConfigurationType="1"
  InheritedPropertySheets="$(BUILDPROPSDIR)\defaults.vsprops;$(BUILDPROPSDIR)\build_dll.vsprops"
>

这是属性表的外观:

<VisualStudioPropertySheet
  Name="defaults"
  OutputDirectory="$(MYBINDIR)\_$(ConfigurationName)_$(PlatformName)"
  IntermediateDirectory="$(MYBUILDDIR)_$(ProjectName)_$(ConfigurationName)_$(PlatformName)"
  >
  <Tool
    Name="VCLinkerTool"
    AdditionalLibraryDirectories="&quot;$(MYLIBDIR)&quot;"
  />
<VisualStudioPropertySheet/>

问题是:生成时,在msbuild文件中声明的环境变量(MYBINDIR,MYLIBDIR)的值不会进入属性表,而是仅在msbuild文件中本地:在msbuild项目中MYBINDIR扩展为"d:\ buildsysroot \ bin",但在vc项目中,MYBINDIR扩展为"d:\ projects \ bin",这是我全局设置的值(例如,通过MyComputer-> Advanced-> EnvironmentVariables)必须保留在那里,因为这是我主要的开发环境的设置方式.

The problem is: when building, the value for the environment variables declared in the msbuild file (MYBINDIR, MYLIBDIR) do not make it into the property sheets, but seem to be local to the msbuild file only: within the msbuild project MYBINDIR expands to "d:\buildsysroot\bin", but within the vc project MYBINDIR expands to "d:\projects\bin", which is the value that I set globally (eg via MyComputer->Advanced->EnvironmentVariables) and which must stay there because it's how my main development environment is set up.

如何将msbuild文件中设置的环境传递给VCBuild任务?

How do I pass the environment set in the msbuild file to the VCBuild task?

我知道可以通过使用批处理文件并使用'set'而不是msbuild文件在其中声明环境来解决此问题;这就是我过去的做法,但是我更喜欢上面的方法,因为它只是一个带有一个参数的msbuild调用而已.

I know that this problem could be solved by using a batch file and declaring the environment there using 'set', and not in the msbuild file; that's how I used to do it, but I prefer the method above as it's just one call to msbuild with one argument and that's it.

编辑

我需要一个快速解决方案,并提出了一个自定义任务,该任务以与批处理文件相同的方式设置环境,但是有在msbuild中执行该操作的好处.该任务的Execute()方法仅完成Environment. SetEnvironmentVariable(var,val). 这仍然需要设置过程的环境,我很高兴听到是否还有其他方法!

I needed a solution quickly and came up with a custom task that sets the environment in the same way a batch file would do, but with the bonus of doing it within msbuild.. The tasks's Execute() method simply does Environment.SetEnvironmentVariable( var, val ). This still requires setting the proces' environment, I'd be glad to hear if there is another way!

推荐答案

因为没有其他人回答/评论我要回答我自己的问题:一个使用Environment.SetEnvironmentVariable(var,val)设置进程环境的自定义任务

since nobody else answered/commented I'm going with my own answer: a custom task that sets the process' environment using Environment.SetEnvironmentVariable( var, val )

这篇关于通过msbuild设置vcbuild环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆