简体   繁体   English

Azure 构建管道 NuGet 还原错误 NETSDK1045

[英]Azure build pipeline NuGet Restore error NETSDK1045

I created an Azure CI pipeline through Visual Studio 2019. The project target framework is .net core 3.1.我通过 Visual Studio 2019 创建了一个 Azure CI 管道。项目目标框架是 .net core 3.1。 However, during the NuGet Restore it fails.但是,在 NuGet 还原期间它会失败。 I have .Net Core 2.2.2017 and 3.1.101 installed on my computer and my Visual Studio 2019 community version is 16.4.我的计算机上安装了 .Net Core 2.2.2017 和 3.1.101,我的 Visual Studio 2019 社区版本是 16.4。 My environment variables paths are in place.我的环境变量路径已经到位。

I also tried creating an app service manually that uses .net core 3.1 LTS stack but I still get the same error.我还尝试手动创建一个使用 .net core 3.1 LTS 堆栈的应用服务,但我仍然遇到相同的错误。

    ##[error]The nuget command failed with exit code(1) and error(C:\Program Files\dotnet\sdk\2.2.110\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5):

    error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. 

This is the YAML file generated by Visual Studio这是 Visual Studio 生成的 YAML 文件

pool:
  name: Hosted VS2017
  demands:
  - msbuild
  - visualstudio
  - vstest

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

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(Parameters.solution)'

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*test*.dll
     !**\obj\**
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

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

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
    ArtifactName: '$(Parameters.ArtifactName)'


I believe, you do not need to install NuGetToolInstaller and vsbuild, you should firstly install DotNetCoreCLI after that you can use it .我相信,你不需要安装 NuGetToolInstaller 和 vsbuild,你应该先安装 DotNetCoreCLI 之后你就可以使用它了 Here is manual how your yaml file should looks like. 这是您的 yaml 文件应该是什么样子的手册

Publishing by the IDE has no pain because it use the tools you have installed on your machine, in the pipeline you need to specify the toolin you gonna use and that is the pain. IDE 发布没有痛苦,因为它使用您安装在机器上的工具,在管道中您需要指定要使用的工具,这就是痛苦。

For those who are not using the new YAML based pipeline but instead use classic editor on devops you might need to add dot net core add task and change from nuget restore to dotnet restore task对于那些不使用新的基于 YAML 的管道而是在 devops 上使用经典编辑器的人,您可能需要添加 dot net core add 任务并从 nuget restore 更改为 dotnet restore task

在此处输入图片说明

When I create a pipeline from the Azure Devops UI, my YAML looks like the below.当我从 Azure Devops UI 创建管道时,我的 YAML 如下所示。 It uses DotNetCoreCLI instead of VSBuild .它使用DotNetCoreCLI而不是VSBuild Notice that it uses the Restore command instead of anything having to do with Nuget.请注意,它使用Restore命令而不是任何与 Nuget 相关的内容。

pool:
  name: Azure Pipelines
#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

steps:
- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore
    projects: '$(Parameters.RestoreBuildProjects)'

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '$(Parameters.RestoreBuildProjects)'
    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
    zipAfterPublish: True

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()

暂无
暂无

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

相关问题 gitlab CI 中的 ASP.NET 核心项目构建错误:错误 NETSDK1045:当前 .NET SDK 不支持面向 .NET Core 5.0 - ASP.NET core project build error in gitlab CI : error NETSDK1045: The current .NET SDK does not support targeting .NET Core 5.0 无效 - 错误 NETSDK1045:当前 .NET SDK 不支持定位 .NET 6.0 - None worked - Error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0 构建 azure Pipeline 中一些库的“nuget restore”问题 - Problem with "nuget restore" with some lib's in build azure Pipeline NETSDK1045 当前的 .NET SDK 不支持面向 .NET Core 3.1 - 由缓存引起? - NETSDK1045 The current .NET SDK does not support targeting .NET Core 3.1 - Caused by Cache? 如何修复 Azure 管道错误.NETSDK1152? - How do I fix Azure pipeline error NETSDK1152? Azure DevOps Pipeline 在 NuGet 恢复任务中失败 - Azure DevOps Pipeline failing at NuGet restore task 如何修复错误 NETSDK1 project.assets.json 文件未找到。 运行 NuGet 包还原以生成此文件 - How to fix error NETSDK1 project.assets.json file not found. Run a NuGet package restore to generate this file .net 核心 3.1 Azure devops 管道在 nuget 恢复时失败 - .net core 3.1 Azure devops Pipeline failed on nuget restore 使用 Blazor Asp.NetCore 托管模板时获取“NETSDK1045 当前 .NET SDK 不支持 .NET Core 3.0 作为目标” - Getting “NETSDK1045 The current .NET SDK does not support .NET Core 3.0 as a target” when using Blazor Asp.NetCore hosted template AzureDevOps Build 中 NuGet 包的恢复错误 - Restore Error of NuGet Packages in AzureDevOps Build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM