Reputation: 67
I am very new - trying to build hello world azure function in vs code ide. When I am trying to test it localy I am getting these errors:
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : You must install or update .NET to run this application. [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : App: /Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/tools/netcoreapp3.1/Microsoft.NET.Sdk.Functions.Generator.dll [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Architecture: arm64 [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Framework: 'Microsoft.NETCore.App', version '3.1.0' (arm64) [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : .NET location: /usr/local/share/dotnet/ [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : The following frameworks were found: [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : 6.0.12 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Learn about framework resolution: [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : https://aka.ms/dotnet/app-launch-failed [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : To install missing framework, download: [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.1.0&arch=arm64&rid=osx.13-arm64 [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
/Users/<username>/.nuget/packages/microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Metadata generation failed. [/Users/<username>/Library/CloudStorage/OneDrive-<companyName>/ConsentizerSandbox/sand-generateUserGuid/sand-generateUserGuid.csproj]
I tried:
and probably other things laying on the internet. without any luck. Build is ok, after build Azure extensions take over and return these errors.
the script is easy:
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace Consentizer.guid
{
public static class helloWorlFc
{
[FunctionName("helloWorld")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"Hello, {name}. This HTTP triggered function executed successfully.";
return new OkObjectResult(responseMessage);
}
}
}
Can you please give the kick in the right direction please? How to solve it in order to be able to locally tested and deployed to azure through vs code azure extension?
Upvotes: 1
Views: 1323
Reputation: 1063
You must install or update .NET to run this application.
Microsoft.net.sdk.functions/3.0.10/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error
Looks like you’re using older version of .net SDK for functions> that is Microsoft.net.sdk.functions/3.0.10 > And this SDK is only supported for .net 3 framework, You might be running this SDK in the .net6 or .net 7 framework which might be causing this issue.
Also, The Error code states that the .net 3.1 which is only supported for Microsoft.net.sdk.functions 3.0.10 is not installed in your local machine.
The new functions SDK 4.1 is supported across .net 6.0 and .net 7.0 as well.
Refer the supported versions here :- https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library?tabs=v2%2Ccmd#supported-versions
Make sure you have .net 6.0 installed in your Local machine or this Project, You can make use of command prompt to installed the packages required for Azure Functions to run on VS code.
If you try to create the function app directly via VS code, you need to install .net latest version and the above SDK in the VS code terminal or your local command prompt in the same function app folder.
Install .net 6.0 SDK from this link- Download .NET (Linux, macOS, and Windows) (microsoft.com)
After >Net 6.0 is downloaded, Install it in your local machine
Install Functions nuget package - dotnet add package Microsoft.NET.Sdk.Functions
After I installed both these dependencies, I was able to Create Function app in VS code successfully
After function app was created added these additional packages with :
dotnet add package command - AspNetCore.Mvc
dotnet add package Azure.WebJobs
dotnet add package Azure.WebJobs.Extensions.Http
dotnet add package AspNetCore.Http
dotnet add package Extensions.Logging
dotnet add package Newtonsoft.Json
Now, Restore all these dependencies in your Function app.
I tried deploying Azure functions in VS code with .net 6.0 version and after creating a http trigger in Vs code it worked.
Upvotes: 2