Azure管道-使用.NET 8 RC 2 SDK构建C#项目失败

a11xaf1n  于 11个月前  发布在  .NET
关注(0)|答案(1)|浏览(112)

我们有一个Azure Function应用程序项目,该项目使用.NET 8 RC2 SDK在本地构建良好。但是,当通过Azure Pipeline构建时,它在恢复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 Core”任务步骤启用了“包含预览版本”。
你知道这个错误的原因是什么吗?

ymdaylpp

ymdaylpp1#

当我使用NuGet还原任务构建.NET 8项目时,我可以重现这个问题。

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

字符串
然后我尝试使用DotNet恢复任务,这一次它的作品.

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


在查看了这两个任务的详细日志后,我发现在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 Preview 3一起使用
基于以上情况,这个问题确实与VS版本(msBuildVersion)有关。DotNet恢复任务将使用构建中最新的.NET 8.0.x SDK。因此,解决方法是使用DotNet恢复任务而不是NuGet恢复任务。
更新:
在dotnet build中,DotNet restore隐式运行(请参阅隐式恢复)。当恢复步骤成功时,您可以添加参数'--no-restore'以在构建步骤中禁用恢复。

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

相关问题