【问题标题】:DevOps Pipeline - can't find packages during build stepDevOps Pipeline - 在构建步骤中找不到包
【发布时间】:2020-02-24 14:56:21
【问题描述】:

我正在尝试将现有的 ASP.NET MVC Web 应用程序从 TeamCity 转移到 Azure DevOps,但是我似乎无法让我的管道找到它从 NuGet 包还原任务恢复的包。

该解决方案有多个项目,它们使用大量 NuGet 包。我创建了一个多步骤管道,目前有一个 NuGet 还原任务和一个 VS 构建任务。

解决方案结构是这样的:

\source
..\SolutionFolder
...Solution.sln
..\..\Project1
....Project1.csproj
..\..\Project2
....Project2.csproj
..\..\Packages
azure-pipelines.yaml
NuGet.config

管道 YAML 如下所示:

trigger:
- PipelineBranch

pool:
  vmImage: 'windows-latest'

stages:

## NuGet Restore ##
- stage: nuget_restore
  displayName: 'Restore nuget packages'
  jobs:
  - job: nuget_package_restore
    steps:
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        command: 'restore'
        restoreSolution: 'source/SolutionFolder/Solution.sln'
        feedsToUse: 'config'
        nugetConfigPath: 'NuGet.Config'
        restoreDirectory: '$(Build.SourcesDirectory)\source\SolutionFolder\packages'

## Build ##
- stage: build_for_int
  displayName: 'Build to int)'
  jobs:
  - job: run_build
    pool:
      vmImage: 'windows-latest'
    steps:
      - task: VSBuild@1
        displayName: 'Build Solution.sln (int)'
        inputs:
          solution: 'source/SolutionFolder/Solution.sln'
          msbuildArgs: '
          /p:DeployOnBuild=true 
          /p:WebPublishMethod=Package 
          /p:PackageAsSingleFile=true 
          /p:SkipInvalidConfigurations=true 
          /p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
          platform: '$(BuildPlatform)'
          configuration: '$(BuildConfiguration)'

当管道运行时,恢复任务成功,输出如下:

<example package>

Added package 'postal.1.2.2' to folder 'd:\a\1\s\source\SolutionFolder\packages'

<loads more packages>

Installed:
    190 package(s) to packages.config projects

当构建任务在解决方案上运行时,它在遇到的第一个项目上失败并出现以下错误:

[warning]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): 
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "postal, Version=1.2.14706.0, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
...
Considered "d:\a\1\s\source\SolutionFolder\packages\postal.1.2.2\lib\postal.dll", but it didn't exist.

每个包依赖项都会发生相同的错误。看起来包恢复任务将包恢复到这里:

d:\a\1\s\source\SolutionFolder\packages\

根据构建日志,它正在分层包文件夹结构中寻找它们,例如:

d:\a\1\s\source\SolutionFolder\packages\<package>\<lib>\<dll>

我已经尝试了很多方法,包括从还原任务中删除 restoreDirectory 参数、在本地运行 MSBuild 命令(它有效)和删除一些包,但是我仍然看到相同的构建错误。

一些项目文件还包含提示路径;例如格式:

  <ItemGroup>
    <Reference Include="<some package>">
      <HintPath>..\packages\<package>\lib\<dll></HintPath>
    </Reference>

有人有什么见解吗?谢谢。

【问题讨论】:

    标签: azure-devops azure-pipelines nuget-package-restore msbuild-task multistage-pipeline


    【解决方案1】:

    您应该将任务 VSBuild@1NuGetCommand@2 包含在同一个 job 下。

    我在本地托管代理上进行了测试,发现运行 vsbuild 任务的第二个作业将清除工作文件夹并重新获取源代码,这会删除第一个作业任务创建的 packages 文件夹nuget 命令。这可能是导致错误的原因。

    所以管道 yaml 应该是这样的

        trigger:
        - PipelineBranch
        pool:
          vmImage: 'windows-latest'
        stages:
        ## NuGet Restore ##
        - stage: nuget_restore
          displayName: 'Restore nuget packages'
          jobs:
          - job: nuget_package_restore
            steps:
            - task: NuGetCommand@2
              displayName: 'NuGet restore'
              inputs:
                command: 'restore'
                restoreSolution: 'source/SolutionFolder/Solution.sln'
                feedsToUse: 'config'
                nugetConfigPath: 'NuGet.Config'
                restoreDirectory: '$(Build.SourcesDirectory)\source\SolutionFolder\packages'
    
            - task: VSBuild@1
              displayName: 'Build Solution.sln (int)'
              inputs:
                solution: 'source/SolutionFolder/Solution.sln'
                msbuildArgs: '
                /p:DeployOnBuild=true 
                /p:WebPublishMethod=Package 
                /p:PackageAsSingleFile=true 
                /p:SkipInvalidConfigurations=true 
                /p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
                platform: '$(BuildPlatform)'
                configuration: '$(BuildConfiguration)'
    

    【讨论】:

      猜你喜欢
      • 2021-07-24
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-14
      • 2020-04-06
      • 1970-01-01
      相关资源
      最近更新 更多