asp.net-core - 为什么我的 Azure Pipeline 作业失败并显示错误 NU1101?

标签 asp.net-core azure-devops continuous-integration azure-pipelines

我正在 Azure DevOps 中运行 CD/CI 管道,最近我的管道作业开始失败并出现以下错误:

##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
##[warning]Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.0 and 3.1) SDK/Runtime along with 2.1.
Unless you have locked down a SDK version for your project(s), 3.x SDK
might be picked up which might have breaking behavior as compared to
previous versions. 
Some commonly encountered changes are: 
If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root
directory rather than Project File's directory. To learn about more
such changes and troubleshoot, refer here:
https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\MyProject\MyProject.UI.csproj

除上述内容外,还有与资源位置有关的错误:
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : warning NU1603: System.Memory 4.5.1 depends on System.Buffers (>= 4.4.0) but System.Buffers 4.4.0 was not found. An approximate best match of System.Buffers 4.5.0 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : warning NU1603: System.Memory 4.5.1 depends on System.Buffers (>= 4.4.0) but System.Buffers 4.4.0 was not found. An approximate best match of System.Buffers 4.5.0 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : warning NU1603: System.Net.WebSockets.WebSocketProtocol 4.5.1 depends on System.Buffers (>= 4.4.0) but System.Buffers 4.4.0 was not found. An approximate best match of System.Buffers 4.5.0 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : warning NU1603: System.Net.WebSockets.WebSocketProtocol 4.5.1 depends on System.Buffers (>= 4.4.0) but System.Buffers 4.4.0 was not found. An approximate best match of System.Buffers 4.5.0 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : warning NU1603: System.Memory 4.5.1 depends on System.Numerics.Vectors (>= 4.4.0) but System.Numerics.Vectors 4.4.0 was not found. An approximate best match of System.Numerics.Vectors 4.5.0 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : warning NU1603: System.Net.WebSockets.WebSocketProtocol 4.5.1 depends on System.Numerics.Vectors (>= 4.4.0) but System.Numerics.Vectors 4.4.0 was not found. An approximate best match of System.Numerics.Vectors 4.5.0 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : warning NU1603: System.Memory 4.5.1 depends on System.Numerics.Vectors (>= 4.4.0) but System.Numerics.Vectors 4.4.0 was not found. An approximate best match of System.Numerics.Vectors 4.5.0 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : warning NU1603: System.Threading.Channels 4.5.0 depends on System.Threading.Tasks.Extensions (>= 4.5.0) but System.Threading.Tasks.Extensions 4.5.0 was not found. An approximate best match of System.Threading.Tasks.Extensions 4.5.1 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : warning NU1603: System.Net.WebSockets.WebSocketProtocol 4.5.1 depends on System.Numerics.Vectors (>= 4.4.0) but System.Numerics.Vectors 4.4.0 was not found. An approximate best match of System.Numerics.Vectors 4.5.0 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : warning NU1603: System.Threading.Channels 4.5.0 depends on System.Threading.Tasks.Extensions (>= 4.5.0) but System.Threading.Tasks.Extensions 4.5.0 was not found. An approximate best match of System.Threading.Tasks.Extensions 4.5.1 was resolved. [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : error NU1101: Unable to find package Azure.Storage.Blobs. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : error NU1101: Unable to find package Microsoft.Azure.KeyVault.Core. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : error NU1101: Unable to find package WindowsAzure.Storage. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.Hosting. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.Mvc.Core. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : error NU1101: Unable to find package Microsoft.EntityFrameworkCore.SqlServer. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.SignalR.Client. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Services\MyProject.Services.csproj : error NU1101: Unable to find package SixLabors.ImageSharp. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.SignalR.Client. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : error NU1101: Unable to find package Microsoft.EntityFrameworkCore.SqlServer. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : error NU1101: Unable to find package Microsoft.EntityFrameworkCore.Tools. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : error NU1101: Unable to find package SixLabors.ImageSharp. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.Hosting. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.Mvc.Core. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj : error NU1101: Unable to find package WindowsAzure.Storage. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\1\s\MyProject\MyProject.UI.csproj]
  Restore failed in 3.8 sec for D:\a\1\s\MyProject.Repo\MyProject.Repo.csproj.
  Restore failed in 3.8 sec for D:\a\1\s\MyProject.Services\MyProject.Services.csproj.
  Restore completed in 1.07 min for D:\a\1\s\MyProject.Data\MyProject.Data.csproj.
  Restore completed in 1.13 min for D:\a\1\s\MyProject\MyProject.UI.csproj.

我在这里注意到的是它正在查看 Microsoft Visual Studio Offline Packages对于这些包,我不确定为什么或者这是否可以接受。本地解决方案构建良好,只有在我们尝试在管道上构建时才会发生这些错误。研究错误带来了几个选项,但都没有奏效。
  • 我尝试的第一件事是清除我的包缓存并更新我的
    来源,这并没有改变任何东西。
  • 然后我更新了这些来源,但同样,这并没有改变任何东西。

  • 我的应用程序正在使用 .NET Core 3.1.101并且完全是最新的。我定义了三个包源,NuGet , Microsoft Visual Studio Offline , 和 Telerik .

    Package Sources

    这是我的 nuget.config文件:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageRestore>
        <add key="enabled" value="True" />
        <add key="automatic" value="True" />
      </packageRestore>
      <activePackageSource>
        <add key="All" value="(Aggregate source)" />
      </activePackageSource>
      <packageSources>
        <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
        <add key="Telerik" value="https://nuget.telerik.com/nuget" />
        <add key="MyGet" value="https://www.myget.org/F/sixlabors/api/v3/index.json" />
      </packageSources>
    <packageSourceCredentials>   
        <Telerik>
          <add key="Username" value="xxx" />
          <add key="ClearTextPassword" value="xxx" />
        </Telerik>
      </packageSourceCredentials>  
    </configuration>
    

    我不久前建立的管道和可能导致问题的一个区域看起来像这样,我很高兴收到有关此的反馈:
    # Add steps that publish symbols, save build artifacts, and more:
    # https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
    
    trigger:
    - master
    
    pool:
      vmImage: 'windows-latest'
    
    variables:
      solution: '**/*.sln'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'
      dotnetSdkVersion: '3.1.101'
    
    steps:
    - task: DotNetCoreCLI@2
      inputs:
        command: 'publish'
        publishWebProjects: true
        arguments: '--configuration $(buildConfiguration) --output $(Build.artifactStagingDirectory)'
        zipAfterPublish: true
    
    # Build and test ASP.NET Core projects targeting the full .NET Framework.
    - task: UseNode@1
    
    - task: PublishBuildArtifacts@1
      displayName: 'publish artifacts'
    - task: NuGetToolInstaller@1
    
    # Restore #
    - task: NuGetCommand@2
      inputs:
        command: 'restore'
        restoreSolution: '**/*.sln'
        feedsToUse: 'config'
        nugetConfigPath: 'MyProject/nuget.config'
        externalFeedCredentials: 'Telerik NuGet'
    
    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'
    
    - task: VSTest@2
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'
    

    所以,这是一个我无法确定的令人沮丧的问题,希望有人能帮助我深入了解它。

    更新

    只是为了给我的问题添加一些额外的上下文,我的解决方案分为 MyProject.Repo , MyProject.Services , MyProject.DataMyProject.UI .

    就这些目标框架而言,它们如下:
  • MyProject.Repo(类库)- .NET 标准 2.1
  • MyProject.Services(类库)- .NET Standard 2.1
  • MyProject.Data(类库)- .NET Standard 2.1
  • MyProject.UI - .NET Core 3.1

  • 构建在工作中失败 DotNetCoreCLI
    enter image description here

    最佳答案

    error NU1101: Unable to find package Microsoft.AspNetCore.Mvc.Core. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages.



    根据错误消息,在 Private Nuget 资源中找不到该包。这些包存在于 nuget.org .

    为此,您可以尝试添加“dotnet restore”任务 之前 “dotnet 发布”任务。然后你可以在任务中引用 nuget.config 文件。

    例如:
    - task: DotNetCoreCLI@2
      displayName: 'dotnet restore'
      inputs:
        command: restore
        projects: '**/*.csproj'
        feedsToUse: config
        nugetConfigPath: 'nuget.config'
    

    希望这可以帮助。

    关于asp.net-core - 为什么我的 Azure Pipeline 作业失败并显示错误 NU1101?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61866257/

    相关文章:

    android - 在ship.io中生成.jar文件和javadoc

    c# - 在 Xunit 测试中使用 Moq 库模拟 HttpClient GetAsync

    node.js - ASP.NET Core MVC 项目中的 node_modules 文件夹

    asp.net - 将 .Net Core 转换为 .Net Framework

    Android SDK 下载作为 Gradle 构建的一部分

    msbuild - 类型或命名空间名称 'WebApi' 在命名空间 'Microsoft.AspNet' 中不存在(是否缺少程序集引用?)

    c# - ASP.NET Core 应用程序生命周期

    entity-framework - 以前不兼容的 ef core 迁移,如何在 CI/CD 系统中正确绕过它们?

    azure-devops - 如何从 Azure DevOps CI 上的多个文件夹复制文件?

    azure - Azure DevOps 中构建管道失败时如何添加相关工作项?