Azure Pipeline无法构建Azure Function App

标签 azure azure-devops azure-functions azure-pipelines

我在 Visual Studio 2019 中创建了 Azure Function,并使用 Azure Pipelines 构建持续集成。

项目设置:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.2" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.8" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

enter image description here

Visual Studio 2019 中的 Azure DevOps 管道:

enter image description here

Azure DevOps 站点上的 Azure DevOps Pipeline:

enter image description here

该项目未构建并出现以下错误:

The nuget command failed with exit code(1) and error(C:\Program Files\dotnet\sdk\2.1.515\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.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\a\1\s\MyProject\MyProject.csproj])

enter image description here

我应该怎样解决这个问题?

最佳答案

构建代理正在尝试使用较旧的 SDK(可能是 .net core 3.0 或 2.x)运行构建。

如果安装了多个SDK,通常会选择最新的,但您可以通过输入global.json来强制使用某个SDK版本。在源代码旁边。

{
  "sdk": {
    "version": "3.1.101",
    "rollForward": "latestFeature"
  }
}

这可以与使用 .NET Core 任务结合使用,以确保安装所需版本的 SDK。通过指定所需的版本,也可以在没有全局 JSON 的情况下使用该任务。

use .NET Core task

如果您托管自己的代理,也可以选择简单地登录服务器并手动安装 SDK。

最后,有时使用 dotnet core 任务比使用 Visual Studio Build 更容易。尽管我认为两者都应该有效。

dotnet core task

关于Azure Pipeline无法构建Azure Function App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62725402/

相关文章:

c - Azure Functions - 应用程序服务计划(间歇性缓慢调用)

azure-devops - 如何将构建管道作为发布管道中的任务进行排队?

Windows Server 2019 上的 Azure 管道 powershell 和 git 在输出中出现错误

azure-functions - (Azure 函数)如何更改内存大小

每个函数或全局的 Azure Functions host.json 设置?

azure - 此虚拟机规模集已被池使用

azure - 多次读取 BrokeredMessage 正文

c# - 以编程方式获取 Azure 应用服务本地磁盘使用情况

bash - 使用 Bash/Curl 从 Azure Blob 存储下载文件

AzureML 模型注册