正在构建.NET 5.0项目Azure DevOps管道

3duebb1j  于 2022-11-19  发布在  .NET
关注(0)|答案(4)|浏览(247)

我正在尝试使用Azure DevOps pipeline Build在.NET 5.0中生成项目,但收到此错误

2020-11-14T01:59:45.8238544Z [command]"C:\Program Files\dotnet\dotnet.exe" build D:\a\1\s\XXX.csproj "-dl:CentralLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.178.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.178.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\""
2020-11-14T01:59:46.1472016Z Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
2020-11-14T01:59:46.1473316Z Copyright (C) Microsoft Corporation. All rights reserved.
2020-11-14T01:59:46.1473902Z 
2020-11-14T01:59:46.6006398Z   Determining projects to restore...
2020-11-14T01:59:47.2059773Z   Restored D:\a\1\s\XXX.csproj (in 234 ms).
2020-11-14T01:59:47.2119638Z   1 of 2 projects are up-to-date for restore.

    2020-11-14T01:59:47.3209350Z ##[error]C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(1177,5): Error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

2020-11-14T01:59:47.3261839Z C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [D:\a\1\s\XXX.csproj]
2020-11-14T01:59:47.3270768Z 
2020-11-14T01:59:47.3274231Z Build FAILED.
2020-11-14T01:59:47.3275925Z 
2020-11-14T01:59:47.3277393Z C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [D:\a\1\s\XXX.csproj]
2020-11-14T01:59:47.3279484Z     0 Warning(s)
2020-11-14T01:59:47.3279860Z     1 Error(s)
2020-11-14T01:59:47.3280170Z 
2020-11-14T01:59:47.3280537Z Time Elapsed 00:00:01.09
2020-11-14T01:59:47.3624731Z ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1

有人知道Azure DevOps管道是否支持构建.NET 5.0代码吗?

z9zf31ra

z9zf31ra1#

是的,Azure DevOps管道可以构建net5.0应用。
如果您正在使用“.Net Core”(yaml中为DotNetCoreCLI)任务进行构建-请在其前面添加“Use .NET Core”(yaml中为UseDotNet)任务,并使用正确的版本:

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '5.0.x'

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: 'build'
sqxo8psd

sqxo8psd2#

支持此功能。

由于您使用的是.Net 5,请尝试使用带有restore命令的Use .net core taskDotnet core task,而不要使用Nuget restore。

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.0.100'
  inputs:
    packageType: 'sdk'
    version: '5.0.100'
    includePreviewVersions: true

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'

强烈建议针对以.net core为目的的项目使用dotnet restoredotnet build责任。请参阅this statement from Nuget task
再看一下这个类似的问题:Azure CI pipeline for Blazor .NET 5 doesn't work

dfddblmv

dfddblmv3#

希望这个答案能帮助那些仍然在Azure DevOps中使用“经典管道”(而不是yaml)的人。
有完全相同的任务模板来设置.net core sdk的特定版本,可以通过搜索对话框添加:

将其包含在您的管道中并通过UI设置正确的版本。还要确保它在实际的构建/发布步骤之前运行。

cbjzeqam

cbjzeqam4#

我需要使用两个framework版本来构建我在. net5中的函数。
步骤:

- task: UseDotNet@2
  inputs:
    version: '5.0.x'
    packageType: sdk
    includePreviewVersions: false

- task: UseDotNet@2
  inputs:
    version: '3.1.x'
    packageType: sdk
    includePreviewVersions: false

相关问题