我有一个 YAML 管道来构建和发布一个 cs 项目。我试图在发布配置文件中放置一个预定义的变量,但它抛出了一个错误。我希望将已发布的文件放入$(Build.ArtifactStagingDirectory)
位置,以便可以使用"发布生成项目"任务。
我不确定为什么在代理目录中运行时,发布配置文件中的变量无法按预期工作。
错误:
错误 MSB4184:表达式 ""。无法评估项目暂存目录"。找不到方法"System.String.ArtifactStagingDirectory">
亚姆:
- 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 }}PropertiesPublishProfilesSTARS.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 }}PropertiesPublishProfilesSTARS.Website.Publish.Profile.pubxml /p:publishUrl=$(Build.ArtifactStagingDirectory)'