管道上的调用目标抛出异常

Exception has been thrown by the target of an invocation on a pipeline

我已经为 .NET Framework 项目创建了构建管道。当管道被拉取请求触发时,我在任务中遇到了这个错误:'NuGet restore'

  • ##[error]The nuget command failed with exit code(1) and error(Error parsing solution file at d:\a\s\***.sln: Exception has been thrown by the target of an invocation. The project file could not be loaded. Could not load file or assembly Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or one of its dependencies. The system cannot find the file specified. d:\a\s\***.sln)

  • ##[error]Packages failed to restore

当我尝试在与目标分支合并后在本地计算机上编译解决方案时,我没有遇到任何冲突或错误。

这是我的 YML 文件:

pool:
  name: Hosted Windows 2019 with VS2019
  demands:
  - msbuild
  - visualstudio
  - vstest

steps:
- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.4.1'
  inputs:
    versionSpec: 4.4.1

- task: NuGetCommand@2 # --> This task fails.
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '***.sln'

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '***.sln'
    platform: 'any cpu'
    configuration: 'release'

- task: PublishSymbols@2
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'
    PublishSymbols: false
  continueOnError: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact drop'
  inputs:
    PathtoPublish: ***
    ArtifactName: 'drop wa'

怎么了?

nuget 任务目前似乎有问题。您可能会尝试将版本更改为 5.4,因为这似乎可以解决某些人的问题,包括我。

请参阅下面的link: https://developercommunity.visualstudio.com/content/problem/978914/nuget-restore-on-hosted-agent-builds-cannot-find-s.html