Reputation: 62886
I am using instructions from https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code to try and build my first Azure Functions project in .Net Core
My problem is I cannot build it:
PS C:\work\proj> dotnet build .\proj.csproj
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
c:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. [C:\work\proj\proj.csproj]
Build FAILED.
c:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. [C:\work\proj\proj.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.56
PS C:\work\proj>
Here is the project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
I have installed the latest .Net Core SDK from https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-2.1.700-windows-x64-installer, so:
PS C:\> dir 'C:\Program Files\dotnet\sdk\'
Directory: C:\Program Files\dotnet\sdk
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 6/7/2018 6:35 PM 1.0.0-preview2-003131
da---- 2/21/2018 7:57 PM 2.1.4
d----- 10/2/2018 9:04 PM 2.1.403
d----- 12/3/2018 9:46 AM 2.1.500
d----- 1/3/2019 9:06 PM 2.1.502
d----- 5/23/2019 8:18 PM 2.1.507
d----- 6/30/2019 11:27 PM 2.1.700
d----- 6/30/2019 11:27 PM NuGetFallbackFolder
PS C:\>
I do not understand why the build selects version 2.1.4. What am I doing wrong?
EDIT 1
I am pretty sure it is related. For some reason I have environment variable
MSBuildSdksPath
:
PS C:\> $env:MSBuildSdksPath
c:\Program Files\dotnet\sdk\2.1.4\Sdks
PS C:\>
Installing the latest SDK did not update it. Why?
Build succeeds when I remove it in the local console. Is it safe to remove it from the environment variables at all?
EDIT 2
PS C:\> dotnet --list-sdks
1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk]
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.507 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
PS C:\>
Upvotes: 1
Views: 2839
Reputation: 2286
I had this problem after cleaning up previous sdks before 3.0.0. I had installed an x86 version before. I didn't want to installed both X86 and X64 versions again. I looked at my envirnment variables and and saw an entry in the PATH pointing to the dotnet folder. I changed it to be C:\Program Files\dotnet\ and now I'm okay.
Upvotes: 0
Reputation: 11
Try to install x32 and x64. First I had installed only x64 and this was the wrong one... was my mistake but maybe you did the same :)
Upvotes: 1
Reputation: 62886
I just deleted the environment variable MSBuildSdksPath
.
Still do not know what added it, why and whether I am out of the woods by just removing it. Will gladly accept a more information answer.
Upvotes: 1
Reputation: 537
Which version of Visual Studio are you using?
I had this problem too, If you are using visual studio 2017 then this version of the .Net Core SDK will not work, you will need to use this one
https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-2.1.507-windows-x64-installer
Upvotes: 0