Azure Functions v3 and VS2019 - Build fails with Error NETSDK1045.

KANF 6 Reputation points
2020-12-10T11:49:38.267+00:00

A teammate encountered a problem with VS2019 Professional and development of Azure Functions v3. He's been developing Azure Functions v2 on VS2017 Professional for a time without any major issues, but moving on to VS2019 Professional and Azure Functions v3, he encountered a bug he couldnt get around. If he created a new Azure Functions project and selected v3, everything seemed fine. But when he tried to build, it failed with the error «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. Front C:\Program Files\dotnet\sdk\2.1.513\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets».

He checked that correct versions of SDK and .NET was installed, but the error message persisted. Then he noticed when looking at project-dependencies in VS-gui the whole Framework was missing from dependencies. Opening the .csproj file in a text editor ensured that a framework was referenced, but it didnt show in the VS2019 gui. If we opened the same solution on a different computer with VS2019, the framework showed up and the project compiled just fine.

The next thing we noticed, was that none of the NuGet packages referenced was showing anything in the property «path», meaning VS2019 didnt know where to find them. When he opened NuGet Package Manager he could install succesfully any NuGet package (the output log said installed succesfully), and the dll was downloaded correct to the global NuGet package folder. But, if he switched the view in the VS-gui to Installed packages, no packages were visible there. It seemed the NuGet Package Manager downloaded NuGet packages correct, but Visual Studio failed to recognize them or VS didnt look in the correct location. He checked all Git for Windows config files, and VS settings to see if he could find the error but without any luck.

Next step which he tried was to uninstall VS2017 and VS2019 together with Visual Studio Installer. After reinstalling VS2019 the problem was still there. Reinstalling the entire computer though, with fresh Windows solved the problem. VS2019 works fine for him now, with NuGet packages and Azure Functions v3.

This would have been the end of the story, if not only a second teammate had encountered the exact same problem today. Is this a known problem, and is there a way to fix this without having to wipe the computer and reinstalling everything?

Any help would be deeply appreciated.

Sincerely,
Kjell

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
{count} votes

1 answer

Sort by: Most helpful
  1. KANF 6 Reputation points
    2020-12-11T08:13:24.82+00:00

    Hi, thanks for your reply @JayaC-MSFT

    As mentioned in the original post, a complete reinstall of VS2019 did not solve the issue. We are using VS2019 Professional version 16.8.3.
    Result from dotnet --list-sdks:

    dotnet --list-sdks  
    2.1.509 [C:\Program Files\dotnet\sdk]  
    2.1.511 [C:\Program Files\dotnet\sdk]  
    2.1.512 [C:\Program Files\dotnet\sdk]  
    2.1.513 [C:\Program Files\dotnet\sdk]  
    2.1.514 [C:\Program Files\dotnet\sdk]  
    2.1.515 [C:\Program Files\dotnet\sdk]  
    2.1.516 [C:\Program Files\dotnet\sdk]  
    2.1.517 [C:\Program Files\dotnet\sdk]  
    2.1.519 [C:\Program Files\dotnet\sdk]  
    5.0.101 [C:\Program Files\dotnet\sdk]  
    

    Version 5.0.101 corresponds to .NET Core 3.1 which is referenced in the project file.
    The projectfile for the Azure Function looks like this:

    <Project Sdk="Microsoft.NET.Sdk">  
      <PropertyGroup>  
        <TargetFramework>netcoreapp3.1</TargetFramework>  
        <AzureFunctionsVersion>v3</AzureFunctionsVersion>  
      </PropertyGroup>  
      <ItemGroup>  
        <PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="3.0.0" />  
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.0" />  
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />  
        <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />  
      </ItemGroup>  
      <ItemGroup>  
        <None Update="host.json">  
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>  
        </None>  
        <None Update="local.settings.json">  
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>  
          <CopyToPublishDirectory>Never</CopyToPublishDirectory>  
        </None>  
      </ItemGroup>  
    </Project>  
    

    PS! One of the computers in the team, which is working fine with Functions v3, has the following list of SDK's:

    2.1.202 [C:\Program Files\dotnet\sdk]  
    2.1.403 [C:\Program Files\dotnet\sdk]  
    2.1.519 [C:\Program Files\dotnet\sdk]  
    5.0.101 [C:\Program Files\dotnet\sdk]  
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.