无法访问MSBuild中的ArtifactStagingDirectory变量 [英] Can't access ArtifactStagingDirectory variable in MSBuild

查看:104
本文介绍了无法访问MSBuild中的ArtifactStagingDirectory变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建过程中,我试图将文件夹复制到工件文件夹(\myserver\d $ \TFBuild-Agent01\66\a)。

During my build process I'm trying to copy a folder to the artifacts folder (\myserver\d$\TFBuild-Agent01\66\a).

所以我将其放在.csproj文件中:

So I put this in the .csproj file:

<Target Name="BeforeBuild">
  <Exec 
    Command="xcopy.exe  Databases &quot;$(Build.ArtifactStagingDirectory)\Databases&quot; /i /e /y /d" />
</Target>

这让我


错误MSB4184:无法评估表达式 .ArtifactStagingDirectory。方法'System.String.ArtifactStagingDirectory'找不到*

Error MSB4184: The expression """.ArtifactStagingDirectory" cannot be evaluated. Method 'System.String.ArtifactStagingDirectory' not found*

我在网上可以找到的所有内容都表明$(Build.ArtifactStagingDirectory)是这种方式去做吧。

Everything I can find online says that $(Build.ArtifactStagingDirectory) is the way to do it. But it doesn't work.

在TFS 2015上使用Visual Studio 2015构建

Building with Visual Studio 2015 on TFS 2015

这不起作用要么:

<Exec 
Command="xcopy.exe  Databases &quot;$($Env:BUILD_ARTIFACTSTAGINGDIRECTORY)\Databases&quot; /i /e /y /d" />




表达式 $ Env:BUILD_ARTIFACTSTAGINGDIRECTORY无法计算。*

The expression "$Env:BUILD_ARTIFACTSTAGINGDIRECTORY" cannot be evaluated.*

这不会出错,但看起来%BUILD_ARTIFACTSTAGINGDIRECTORY%被替换为空字符串:

This doesn't error, but it looks like %BUILD_ARTIFACTSTAGINGDIRECTORY% gets replaced as an empty string:

 <Exec Command="xcopy.exe  Databases &quot;%BUILD_ARTIFACTSTAGINGDIRECTORY%\Databases&quot; /i /e /y /d" /> 


推荐答案

您一直在混合访问构建变量的方法代理允许您。使用 $(some.variable)的语法由代理本身解释。 MSBuild具有类似的外观语法- $(PropertyName)-做了一些不同的事情-它提供对msbuild属性的访问,并且不允许点(),因为您可以使用点来调用值上的函数(例如 $(OutputPath.Substring(3)))。

You have been mixing ways to access the build variables that the agent allows you. The syntax using $(some.variable) is interpreted by the agent itself. MSBuild has a similar looking syntax - $(PropertyName) - which does something different - it gives access to msbuild properties and does not allow for dots (.) in it's name, since you can use the dot to call functions on the value (e.g. $(OutputPath.Substring(3))).

要从MSBuild引用构建变量时,需要引用代理设置的环境变量。这是可能的,因为MSBuild使用其属性语法使所有环境变量都可以作为全局属性进行访问。 Build.ArtifactStagingDirectory 的环境变量为 BUILD_ARTIFACTSTAGINGDIRECTORY ,因此您可以使用 $在MSBuild中使用它。 (BUILD_ARTIFACTSTAGINGDIRECTORY)

When you want to reference build variables from MSBuild, you need to reference the environment variable that the agent sets. This is possible because MSBuild makes all environment variables accessible as global properties using its property syntax. The environment variable for Build.ArtifactStagingDirectory is BUILD_ARTIFACTSTAGINGDIRECTORY so you can use it in MSBuild using $(BUILD_ARTIFACTSTAGINGDIRECTORY).

我已经在此脚本在作为TFS / VSTS构建的一部分运行时默认为属性( PublishBaseDir 是稍后使用的自定义属性):

I have been using it successfully in this script to default a property when run as part of a TFS/VSTS build (PublishBaseDir is a custom property used later):

<PropertyGroup>
  <!-- Default artifact staging directory when built via VSTS / TFS agent -->
  <PublishBaseDir Condition="'$(PublishBaseDir)' == '' and '$(BUILD_ARTIFACTSTAGINGDIRECTORY)' != '' ">$(BUILD_ARTIFACTSTAGINGDIRECTORY)</PublishBaseDir>

  <!-- If not built on a known agent, use a "publish" subdir next to this file -->
  <PublishBaseDir Condition="'$(PublishBaseDir)' == ''">$(MSBuildThisFileDirectory)publish\</PublishBaseDir>

  <!-- Normalize directory if set manually or through ENV var -->
  <PublishBaseDir Condition="!HasTrailingSlash('$(PublishBaseDir)')">$(PublishBaseDir)\</PublishBaseDir>
</PropertyGroup>

这篇关于无法访问MSBuild中的ArtifactStagingDirectory变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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