Reputation: 167
I'm trying to setup Visual Studio Code so I can modify Azure Functions but seem to be hitting some issues. The guide that I'm using is the official MS documentation that is found here.
When I go to run the code for the first time, I get the following error:
U1100: Unable to resolve 'Microsoft.NET.Sdk.Functions (>= 4.0.1)' for 'net6.0
I've seen a few similar posts where users ran into this issue but it was on older versions and didn't find an obvious answer for my setup. This entire install if new so there shouldn't be any issues from that perspective.
Any help would be greatly appreciated.
Below is my csproj file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<RootNamespace>Azure_Functions</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Upvotes: 1
Views: 1507
Reputation: 1705
I had the same issue as you.
Try the following command from the terminal:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
It helped me.
Upvotes: 7
Reputation:
I tried to run the Azure Function - C# - Http Trigger in VS Code using the same documentation provided and run locally without any errors as you see the steps I followed.
Here is my .csproj code:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
local.settings.json and host.json code:
HttpExample.cs code:
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 My.Functions
{
public static class HttpExample
{
[FunctionName("HttpExample")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "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);
}
}
}
Modified the Function class (removed post request in the function class declaration) and executed again:
U1100: Unable to resolve 'Microsoft.NET.Sdk.Functions (>= 4.0.1)' for 'net6.0
Note:
func version
or func --version
.Preferences: Open user settings
, then search for Azure Functions: Project Runtime
and change the default runtime version to ~4
.
Upvotes: 0