我在 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>
Visual Studio 2019 中的 Azure DevOps 管道:
Azure DevOps 站点上的 Azure DevOps Pipeline:
该项目未构建并出现以下错误:
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])
我应该怎样解决这个问题?
最佳答案
构建代理正在尝试使用较旧的 SDK(可能是 .net core 3.0 或 2.x)运行构建。
如果安装了多个SDK,通常会选择最新的,但您可以通过输入global.json
来强制使用某个SDK版本。在源代码旁边。
{
"sdk": {
"version": "3.1.101",
"rollForward": "latestFeature"
}
}
这可以与使用 .NET Core
任务结合使用,以确保安装所需版本的 SDK。通过指定所需的版本,也可以在没有全局 JSON 的情况下使用该任务。
如果您托管自己的代理,也可以选择简单地登录服务器并手动安装 SDK。
最后,有时使用 dotnet core 任务比使用 Visual Studio Build 更容易。尽管我认为两者都应该有效。
关于Azure Pipeline无法构建Azure Function App,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62725402/