无法在Azure Pipelines中使用Paket还原NuGet软件包(工件提要)

时间:2020-04-14 09:04:28

标签: .net azure nuget azure-pipelines paket

我正在尝试定义为 .NET Core 解决方案构建的管道。依赖关系由 Paket 管理。从 Azure Artifacts 供稿中下载依赖项。

在第一阶段,我认为问题出在Paket上,我能够定义一个没有它的构建管道(使用私有包源,我们的私有供稿)。

一旦我解决了Paket问题,我就无法尝试使dotnet restore正常工作。

这是我实际的YML定义:

trigger:
- none

pool:
  vmImage: 'windows-latest'

steps:
  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '3.1.x'

  - powershell: |
      cd ..
      dotnet tool install -g paket

  - task: setCredentialManager@0

  - task: PaketRestore@0
    inputs:
      PaketPath: '.paket'

  - task: paketCredentialCleanup@0

  # I'm not sure the following task is necessary
  - task: PowerShell@2
    inputs:
      filePath: './installcredprovider.ps1'

  - task: NuGetCommand@2
    inputs:
      command: 'restore'
      restoreSolution: '**/*.sln'
      feedsToUse: 'config'
      nugetConfigPath: './NuGet.config'

  - task: CmdLine@2
    inputs:
      script: 'dotnet restore'

  - task: DotNetCoreCLI@2
    inputs:
      command: 'build'
      projects: '*.csproj'

NuGetCommand@2还原任务因以下日志而失败:

NuGet Version: 5.4.0.6315
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
MSBuild auto-detection: using msbuild version '16.5.0.12403' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
MSBuild P2P timeout [ms]: 120000
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe "C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\rjysskyy.m01.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\1cpdh2ma.wgd.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe" /p:RestoreSolutionDirectory="d:\a\1\s\\" /p:RestoreConfigFile="d:\a\1\s\NuGet.config" /p:SolutionDir="d:\a\1\s\\" /p:SolutionName="ArtifactsVs"
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
   at NuGet.CommandLine.MsBuildUtility.<GetProjectReferencesAsync>d__6.MoveNext()
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
--- End of stack trace from previous location where exception was thrown ---
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
d:\a\1\s\.paket\Paket.Restore.targets(219,5): error MSB3073: The command ""paket" restore --project "d:\a\1\s\ArtifactsVs.csproj" --output-path "obj" --target-framework "netcoreapp3.1"" exited with code 1. [d:\a\1\s\ArtifactsVs.csproj]
   at NuGet.CommandLine.RestoreCommand.<GetDependencyGraphSpecAsync>d__68.MoveNext()

--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.CommandLine.RestoreCommand.<DetermineInputsFromMSBuildAsync>d__63.MoveNext()
##[error]The nuget command failed with exit code(1) and error(EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
EXEC : Standard error : It was not possible to find any compatible framework version [d:\a\1\s\ArtifactsVs.csproj]
d:\a\1\s\.paket\Paket.Restore.targets(219,5): error MSB3073: The command ""paket" restore --project "d:\a\1\s\ArtifactsVs.csproj" --output-path "obj" --target-framework "netcoreapp3.1"" exited with code 1. [d:\a\1\s\ArtifactsVs.csproj])
##[error]Packages failed to restore
Finishing: NuGetCommand

无论如何,dotnet restore都会失败。

脚本installcredprovider.ps1的来源是here

可以从here下载存储库(部分混淆了供稿URL)。

在此先感谢任何想要帮助的人!

1 个答案:

答案 0 :(得分:1)

我创建了一个用于故障排除的测试项目。我发现.NET Core sdk 2.0.0对于Paket是必需的。

如果未安装dotnet core 2.0.0,则Nuget恢复任务将失败,并显示上述错误"It was not possible to find any compatible framework version"。而paket retore任务将失败,并显示错误The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.

使用 UseDotNet 任务安装.NET Core sdk 2.0.0之后。 Nuget restore和paket restore均成功运行。请检查以下yaml:

pool:
  vmImage: 'windows-latest'

steps:

  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '2.0.0'

  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '3.1.x'

  - powershell: |
      cd ..
      dotnet tool install -g paket

  - task: setCredentialManager@0

  - task: PaketRestore@0
    inputs:
      PaketPath: '.paket'

  - task: paketCredentialCleanup@0

  # - task: PowerShell@2
  #   inputs:
  #     filePath: './installcredprovider.ps1'

  # - task: NuGetToolInstaller@1
  #   inputs:
  #     versionSpec: 5.x

  - task: NuGetCommand@2
    inputs:
      command: 'restore'
      restoreSolution: '**/*.sln'
      feedsToUse: 'config'
      nugetConfigPath: './NuGet.config'

对于上述管道,还必须执行任务setCredentialManager@0,但是不需要运行./installcredprovider.ps1的powershell任务。

我还发现上述管道将无法在代理vs2017-win2016上运行,因为在执行nuget restore命令时会调用vs2017中的旧版本msbuild。

Paket还原,dotnet还原和nuget还原它们都做相同的事情(dotnet还原和nuget还原将称为paket还原)。您只能在管道中保留其中之一。我进行了测试,并且其中任何一个都成功构建了我的项目。

希望上面有帮助!