简体   繁体   English

无法使用 Azure 管道中的 Paket 恢复 NuGet 包(工件馈送)

[英]Cannot restore NuGet packages using Paket in Azure Pipelines (Artifacts feed)

I'm trying to define a pipeline that builds for .NET Core solution.我正在尝试定义为.NET 核心解决方案构建的管道。 Dependencies are managed by Paket .依赖项由Paket管理。 A dependency is downloaded from Azure Artifacts feed.Azure 工件源下载依赖项。

In first stages I thought the problem was Paket and I was able to define a pipeline that builds without it (using a private packages source , our private feed).在第一阶段,我认为问题出在 Paket 上,我能够定义一个无需它即可构建的管道(使用私有包源,我们的私有提要)。

Once I fixed Paket issues I got problems trying to get dotnet restore working.一旦我修复了 Paket 问题,我在尝试让dotnet restore正常工作时遇到了问题。

This my actual YML definition:这是我实际的 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'

The NuGetCommand@2 restore task fails with this log: 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

Anyway omitting it, dotnet restore fails the same.无论如何省略它, dotnet restore都会失败。

Source of script installcredprovider.ps1 is here .脚本installcredprovider.ps1的来源在这里

Repository can be downloaded from here (feed URL is partly obfuscated).可以从这里下载存储库(Feed URL 被部分混淆)。

Thanks in advance to anyone who wants to help!提前感谢任何想提供帮助的人!

I created a test project for troubleshooting.我创建了一个用于故障排除的测试项目。 And i found .NET Core sdk 2.0.0 is needed for Paket.我发现Paket需要.NET Core sdk 2.0.0

If dotnet core 2.0.0 is not installed, Nuget restore task will fail with above error "It was not possible to find any compatible framework version" .如果未安装 dotnet core 2.0.0,Nuget 恢复任务将失败,并出现上述错误"It was not possible to find any compatible framework version" And paket retore task will fail with error The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.并且 paket retore 任务将失败并出现错误The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.

After i installed .NET Core sdk 2.0.0 with UseDotNet task.在我使用UseDotNet任务安装.NET Core sdk 2.0.0后。 Both Nuget restore and paket restore ran successfully. Nuget 恢复和 paket 恢复都成功运行。 Please check below yaml:请查看以下 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'

For above pipeline, Task setCredentialManager@0 is also must, but the powershell task to run ./installcredprovider.ps1 is not needed.对于上述管道,任务setCredentialManager@0也是必须的,但不需要运行./installcredprovider.ps1的 powershell 任务。

And i also found above pipeline will fail to run on agent vs2017-win2016, for an older version msbuild in vs2017 is invoked while executing nuget restore command.而且我还发现上面的管道将无法在代理 vs2017-win2016 上运行,因为在执行 nuget 恢复命令时调用 vs2017 中的旧版本 msbuild。

Paket restore, dotnet restore and nuget restore they all do the same thing(dotnet restore and nuget restore will call paket restore). Paket restore、dotnet restore 和 nuget restore 它们都做同样的事情(dotnet restore 和 nuget restore 将调用 paket restore)。 You can only keep one of them in your pipeline.您只能将其中一个保留在您的管道中。 I tested and my project was successfully built with either one of them.我进行了测试,我的项目使用其中任何一个都成功构建了。

Hope above helps!以上希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM