我们有一个Azure函数应用程序项目,它使用.NET8RC2 SDK在本地构建得很好.但是,当通过Azure管道构建时,它在还原NuGet包步骤期间失败,并引发以下错误:

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(D:\a\1\s\some.API.csproj : error : Could not resolve SDK "Microsoft.NET.Sdk". 
Exactly one of the probing messages below indicates why we could not resolve the SDK. Investigate and resolve that message to correctly specify the SDK.

D:\a\1\s\SOME.API.csproj : error :   Unable to locate the .NET SDK. Check that it is installed, your PATH is configured for the correct architecture, and that the version specified in global.json (if any) matches the installed version.

D:\a\1\s\SOME.API.csproj : error :   The NuGetSdkResolver did not resolve this SDK because there was no version specified in the project or global.json.

D:\a\1\s\SOME.API.csproj : error :   MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.Sdk" because directory "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\Sdk" did not exist.

D:\a\1\s\SOME.API.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found. No .NET SDKs were found.

在此之前的步骤中,成功下载了.NET 8.0.x SDK,并为"使用.NET核心"任务步骤启用了"包含预览版本".

你知道这个错误的原因是什么吗?

推荐答案

当我使用NuGet恢复任务构建.NET8项目时,我可以重现该问题.

- task: NuGetToolInstaller@1
 
- task: NuGetCommand@2
  inputs:
    restoreSolution: '**/*.sln'

然后我try 使用DotNet恢复任务,这次它起作用了.

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.sln'
    feedsToUse: 'select'

在查看了这两个任务的详细日志(log)后,我发现在NuGet恢复任务中,"msBuildVersion":"17.7.2.0".在DotNet还原任务中,MSBuild version="17.8.0+6cdef4241".

正如jessehouwing提到的,在这Announcing .NET 8 Release Candidate 2个人中,

.NET SDK 8.0.100-rc.2必须与Visual Studio 17.8预览版3一起使用

基于上述情况,这个问题确实与VS版本(MsBuildVersion)有关.DotNet恢复任务将在内部版本中使用最新的.NET 8.0.x SDK.因此,解决方法是使用DotNet还原任务而不是NuGet还原任务.

最新情况:

在DotNet构建中,DotNet恢复隐式运行(请参见Implicit restore).当还原步骤成功时,您可以在生成步骤中添加参数'--no-restore'以禁用还原.

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--no-restore'
  name:   build

.net相关问答推荐

安装特定主要版本的DotNet SDK最新版本

.NET发布的应用程序运行与开发不同的端口

从没有流的EventStore中读取流不存在异常

MSBuild:CopyToOutputDirectory不会将本机DLL复制到输出

从窗体中移除另一个控件中引用的控件时获取设计时通知

.NET MAUI ListView - ObservableCollection - 在异步方法期间不更新

使用 PowerShell 从文件夹中获取文件名的最快\最好的方法是什么?

"投掷;" 是什么意思?靠自己做什么?

是否有任何为 C# 编写的模糊搜索或字符串相似函数库?

比较 C# 中的双精度值

SqlDateTime.MinValue != DateTime.MinValue,为什么?

在 WPF 窗口中获取当前聚焦的元素/控件

添加新实体标量时实体框架 4 映射片段错误

.NET 世界是否有 Maven 替代方案或端口?

如何授予所有用户对我的应用程序创建的文件的完全权限?

清除 .NET 的 StringBuilder 内容的最佳方法

如何将 Excel 序列日期编号转换为 .NET DateTime?

可以从 C# 调用 C++ 代码吗?

当它被抛出和捕获时,不要在那个异常处停止调试器

没有科学记数法的双精度字符串转换