在Azure YAML管道的.pubxml文件中使用Azure预定义变量

时间:2020-01-29 13:11:04

标签: azure-devops yaml azure-pipelines csproj pubxml

我有一个用于构建和发布CS项目的YAML管道。我试图在发布配置文件中放入预定义变量,但是它引发了错误。我希望将已发布的文件放在$(Build.ArtifactStagingDirectory)位置,以便可以使用“发布构建工件”任务。

我不确定为什么在代理目录中运行它时,发布配置文件中的变量不能按预期工作。

错误:

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

YAML:

  - task: MSBuild@1
    displayName: '${{ parameters.Site }} - Publish'
    inputs:
      solution: '*${{ parameters.Location }}/${{ parameters.Site }}.csproj'
      msbuildVersion: '15.0'
      msbuildArchitecture: 'x64'
      platform: 'anycpu'
      configuration: '${{ parameters.Configuration }}'
      msbuildArguments: '/p:PublishProfile=$(Build.SourcesDirectory)\${{ parameters.Location }}\Properties\PublishProfiles\STARS.Website.Publish.Profile.pubxml'


  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifacts'
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
      artifactName: '${{ parameters.Site }}'

pubxml:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <PublishProvider>FileSystem</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>True</ExcludeApp_Data>
    <publishUrl>$(Build.ArtifactStagingDirectory)</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

1 个答案:

答案 0 :(得分:1)

您可以在构建参数中覆盖publishUrl

/p:publishUrl=$(Build.ArtifactStagingDirectory)

因此在您的pubxml中放置一个占位符:

<publishUrl>Placeholder-You-Want</publishUrl>

在您的YAML中:

msbuildArguments: '/p:PublishProfile=$(Build.SourcesDirectory)\${{ parameters.Location }}\Properties\PublishProfiles\STARS.Website.Publish.Profile.pubxml /p:publishUrl=$(Build.ArtifactStagingDirectory)'