【问题标题】:Retrieving the MSBuild content into an artifact? Directory 'D:\a\1\a' is empty. Nothing will be added to build artifact 'drop'将 MSBuild 内容检索到工件中?目录 'D:\a\1\a' 为空。不会添加任何内容来构建工件“drop”
【发布时间】:2021-12-30 07:55:45
【问题描述】:

我尝试了解此 MSBuild 命令如何与 Yaml 中的 Azure DevOps Pipeline 一起使用。我收到此错误:

这是我在 Azure Pipeline 项目中的 MSBuild 说明:

- task: MSBuild@1
  inputs:
    solution: '**/Beper-EDI.sln'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    msbuildArguments: # Optional
    clean: true
    #maximumCpuCount: false # Optional
    #restoreNugetPackages: false # Optional
    #logProjectEvents: false # Optional
    #createLogFile: false # Optional
    #logFileVerbosity: 'normal' # Optional. Options: quiet, minimal, normal, detailed, 

构建是正确的。我可以建立我的项目。然后我尝试使用以下方法发布我的工件:

- task: PublishBuildArtifacts@1
  inputs:
    ArtifactName: 'drop'
    pathToPublish: '$(Build.ArtifactStagingDirectory)'

我可以处理管道,但最后我的工件是空的。

在我的构建过程中,我可以看到创建了 bin/Release 文件夹和 obj/Release 文件夹并编译了代码。:

Starting: MSBuild
==============================================================================
Task         : MSBuild
Description  : Build with MSBuild
Version      : 1.192.2
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/msbuild
==============================================================================
"D:\a\_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.192.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [17.0,18.0) -latest -format json
"D:\a\_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.192.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [17.0,18.0) -products Microsoft.VisualStudio.Product.BuildTools -latest -format json
"D:\a\_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.192.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -latest -format json
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" "D:\a\1\s\Beper-EDI.sln" /nologo /nr:false /dl:CentralLogger,"D:\a\_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.192.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=|SolutionDir=D:\a\1\s"*ForwardingLogger,"D:\a\_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.192.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"  /p:platform="Any CPU" /p:configuration="Release" /p:_MSDeployUserAgent="VSTS_10aa52a5-54c3-4730-90df-e99d0388b1f5_build_50_0"
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 12/30/2021 8:07:45 AM.
Project "D:\a\1\s\Beper-EDI.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Release|Any CPU".
Project "D:\a\1\s\Beper-EDI.sln" (1) is building "D:\a\1\s\Nppg.Core.BusinessServices\Nppg.Core.BusinessServices.csproj" (2) on node 1 (default targets).
PrepareForBuild:
  Creating directory "bin\Release\".
  Creating directory "obj\Release\".
Project "D:\a\1\s\Nppg.Core.BusinessServices\Nppg.Core.BusinessServices.csproj" (2) is building "D:\a\1\s\Nppg.Core.Reports\Nppg.Core.Reports.csproj" (3:2) on node 1 (default targets).
PrepareForBuild:
  Creating directory "bin\Release\".
  Creating directory "obj\Release\".
Project "D:\a\1\s\Nppg.Core.Reports\Nppg.Core.Reports.csproj" (3:2) is building "D:\a\1\s\Submodules\nppg-core\Nppg.Core\Nppg.Core.csproj" (5:3) on node 1 (default targets).
PrepareForBuild:
  Creating directory "bin\Release\".
  Creating directory "obj\Release\".

如何确保系统允许我访问我的 /Release 文件夹?

【问题讨论】:

    标签: azure-devops msbuild continuous-integration


    【解决方案1】:

    将 MSBuild 内容检索到工件中?目录 'D:\a\1\a' 为空。不会添加任何内容来构建工件“drop”

    那是因为任务PublishBuildArtifacts的来源是$(Build.ArtifactStagingDirectory)

    但是MSBuild任务没有在$(Build.ArtifactStagingDirectory)文件夹中生成文件,所以我们需要在MSBuild任务之后通过复制任务将文件从MSBuild任务的输出文件夹复制到文件夹$(Build.ArtifactStagingDirectory)

    - task: CopyFiles@2
      displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
      inputs:
        SourceFolder: '$(Build.SourcesDirectory)'
        Contents: '**\bin\release\**'
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
    

    【讨论】:

    • 为什么在 Azure DevOps 库中从未提及此步骤并且不是模板的一部分?
    • 我仍然不明白,因为现在我在 CI 过程之后有 2 个已发布的工件。一个是 build.SourceLabel,另一个是我的放置文件夹
    • 因为构建顺序不固定,所以没有刻意要求一定要完成哪个任务,一切根据实际需要选择。您可以使用 .NET 桌面模板。
    • @BastienVandamme,更新你的 YAML 文件和构建结果,我会跟进。
    • 它正在工作。感谢您的帮助。我检查了您的个人资料,并希望与您保持联系或能够关注您,因为我对 MSBuild 和 DevOps 有很多问题。
    猜你喜欢
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多