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

Using Azure Predefined Variable in a .pubxml file in Azure YAML Pipeline

我有一个 YAML 管道来构建和发布一个 cs 项目。我试图在发布配置文件中放置一个预定义变量,但它抛出错误。我希望将已发布的文件放入 $(Build.ArtifactStagingDirectory) 位置,以便我可以使用 Publish Build Artifact 任务。

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

错误:

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

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>

您可以覆盖构建参数中的 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)'