通过Azure Pipelines还原本地NuGet软件包的问题

问题描述

我在Azure Pipelines中遇到了一个问题,我的回购中有一个本地NuGet软件包,我希望将其与所有其他NuGet软件包(通常都是从nuget.org拾取)一起包含在管道构建中。我的项目基于ASP.NET Core,更具体地说,它是Blazor服务器端Web应用程序。

本地NuGet软件包“ Breeze.Sharp.0.9.6.nupkg”存储在我的存储库中,位于: MySolution / packages

正在发生的事情是nuget.org软件包在管道中恢复正常,但是在尝试找到我的本地NuGet软件包位置并抛出以下错误时失败了:

     1>/usr/share/dotnet/sdk/3.1.402/NuGet.targets(128,5): error : The local source '/home/vsts/work/1/Nuget/MySolution/packages' doesn't exist. [/home/vsts/work/1/s/MySolution/MySolution.sln]
         NuGet.Protocol.Core.Types.FatalProtocolException: The local source '/home/vsts/work/1/Nuget/MySolution/packages' doesn't exist.
            at NuGet.Protocol.LocalV3FindPackageByIdResource.GetVersionscore(String id,ILogger logger)
            at NuGet.Protocol.LocalV3FindPackageByIdResource.<>c__displayClass22_0.<GetVersions>b__0(String keyId)
            at System.Collections.Concurrent.ConcurrentDictionary`2.GetorAdd(TKey key,Func`2 valueFactory)
            at NuGet.Protocol.LocalV3FindPackageByIdResource.GetVersions(String id,SourceCacheContext cacheContext,ILogger logger)
            at NuGet.Protocol.LocalV3FindPackageByIdResource.GetAllVersionsAsync(String id,ILogger logger,CancellationToken cancellationToken)
            at NuGet.Commands.sourceRepositoryDependencyProvider.GetAllVersionsAsync(String id,CancellationToken cancellationToken)
            at NuGet.Commands.sourceRepositoryDependencyProvider.FindLibraryCoreAsync(LibraryRange libraryRange,CancellationToken cancellationToken)
            at NuGet.Commands.sourceRepositoryDependencyProvider.<>c__displayClass19_0.<<FindLibraryAsync>b__0>d.MoveNext()
         --- End of stack trace from prevIoUs location where exception was thrown ---
            at NuGet.Commands.sourceRepositoryDependencyProvider.FindLibraryAsync(LibraryRange libraryRange,NuGetFramework targetFramework,CancellationToken cancellationToken)
            at NuGet.DependencyResolver.ResolverUtility.<>c__displayClass9_1.<<FindLibraryFromSourcesAsync>b__0>d.MoveNext()
         --- End of stack trace from prevIoUs location where exception was thrown ---
            at NuGet.DependencyResolver.ResolverUtility.FindLibraryFromSourcesAsync(LibraryRange libraryRange,IEnumerable`1 providers,Func`2 action)
            at NuGet.DependencyResolver.ResolverUtility.FindLibraryByVersionAsync(LibraryRange libraryRange,NuGetFramework framework,CancellationToken token)
            at NuGet.DependencyResolver.ResolverUtility.FindPackageLibraryMatchAsync(LibraryRange libraryRange,IEnumerable`1 remoteProviders,IEnumerable`1 localProviders,CancellationToken cancellationToken)
            at NuGet.DependencyResolver.ResolverUtility.FindLibraryMatchAsync(LibraryRange libraryRange,String runtimeIdentifier,IEnumerable`1 projectProviders,IDictionary`2 lockFileLibraries,CancellationToken cancellationToken)
            at NuGet.DependencyResolver.ResolverUtility.FindLibraryEntryAsync(LibraryRange libraryRange,RemoteWalkContext context,CancellationToken cancellationToken)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange,String runtimeName,RuntimeGraph runtimeGraph,Func`2 predicate,GraphEdge`1 outerEdge,Transitivecentralpackageversions transitivecentralpackageversions)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange,Transitivecentralpackageversions transitivecentralpackageversions)
            at NuGet.DependencyResolver.RemoteDependencyWalker.WalkAsync(LibraryRange library,Boolean recursive)
            at NuGet.Commands.ProjectRestoreCommand.WalkDependenciesAsync(LibraryRange projectRange,RemoteDependencyWalker walker,CancellationToken token)
            at NuGet.Commands.ProjectRestoreCommand.TryRestoreAsync(LibraryRange projectRange,IEnumerable`1 frameworkRuntimePairs,NuGetv3LocalRepository userPackageFolder,IReadOnlyList`1 fallbackPackageFolders,RemoteDependencyWalker remoteWalker,Boolean forceRuntimeGraphCreation,CancellationToken token,TelemetryActivity telemetryActivity)
            at NuGet.Commands.RestoreCommand.ExecuteRestoreAsync(NuGetv3LocalRepository userPackageFolder,TelemetryActivity telemetryActivity)
            at NuGet.Commands.RestoreCommand.ExecuteAsync(CancellationToken token)
            at NuGet.Commands.RestoreRunner.ExecuteAsync(RestoreSummaryRequest summaryRequest,CancellationToken token)
            at NuGet.Commands.RestoreRunner.ExecuteAndCommitAsync(RestoreSummaryRequest summaryRequest,CancellationToken token)
            at NuGet.Commands.RestoreRunner.CompleteTaskAsync(List`1 restoreTasks)
            at NuGet.Commands.RestoreRunner.RunAsync(IEnumerable`1 restoreRequests,RestoreArgs restoreContext,CancellationToken token)
            at NuGet.Commands.RestoreRunner.RunAsync(RestoreArgs restoreContext,CancellationToken token)
            at NuGet.Build.Tasks.BuildTasksUtility.RestoreAsync(DependencyGraphSpec dependencyGraphSpec,Boolean interactive,Boolean recursive,Boolean noCache,Boolean ignoreFailedSources,Boolean disableParallel,Boolean force,Boolean forceEvaluate,Boolean hideWarningsAndErrors,Boolean restorePC,Boolean cleanupAssetsForUnsupportedProjects,ILogger log,CancellationToken cancellationToken)
            at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)
       Done executing task "RestoreTask" -- Failed.
     1>Done building target "Restore" in project "MySolution.sln" -- Failed.
     1>Done Building Project "/home/vsts/work/1/s/MySolution/MySolution.sln" (Restore target(s)) -- Failed.

Build Failed.

       "/home/vsts/work/1/s/MySolution/MySolution.sln" (Restore target) (1) ->
       (Restore target) -> 


我的最初想法与其他人相同... AH 路径一定不正确!但是...在尝试各种不同的路径以进入packages文件夹以提取我的本地NuGet软件包之后,我似乎无法使其正常工作。

为帮助您,我的配置文件在下面。

azure-pipelines.yml:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:   
- task: NuGetToolInstaller@1
  displayName: 'Use NuGet 4.9.1'
  inputs:
    versionSpec: 4.9.1

- task: DotNetCoreCLI@2
  displayName: 'Restore NuGet Packages'
  inputs:
    command: 'restore'
    projects: '**/*.sln'
    FeedsToUse: 'config'
    nugetConfigPath: 'MySolution/NuGet.Config'

- task: DotNetCoreCLI@2
  displayName: 'Build web project'
  inputs:
    command: 'build'
    projects: $(SolutionPath)
    

NuGet.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
        <add key="LocalPackages" value="MySolution/packages" />
    </packageSources>
</configuration>

我一直在讨论的问题是“ LocalPackages”元素,我认为这可能是问题所在,因此一直在尝试各种路径组合以缩小范围-但没有运气-这让我觉得这 可能 是个红鲱鱼,但是你永远不知道我会做些愚蠢的事!

我知道这里可以遵循一些最佳实践,例如创建我自己的NuGet软件包的Artifacts提要以实现可维护性,但这对我来说将是一个精炼阶段,此刻我的重点只是简单地处于构建状态的管道准备就绪,可以进行部署和测试。

对此有任何帮助或指导或我可以尝试解决的问题,将不胜感激!

让我知道是否需要更多具体信息,我可以提供!

谢谢。

解决方法

是导致问题的本地软件包路径。您应该将值设置为<add key="LocalPackages" value="../s/MySolution/packages" />

如果检查dotnet还原任务日志,则会发现已创建一个临时配置,并且还原任务正在使用此临时配置文件。见下文。

enter image description here

因此,您在nuget.config文件中指定的LocalPackages路径相对于临时配置文件夹/home/vsts/work/1/Nuget

由于您的项目已克隆到文件夹/home/vsts/work/1/s(即$(system.defaultworkingdirectory))中。您应该指定LocalPackages路径,如下所示:

<add key="LocalPackages" value="../s/MySolution/packages" />

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...