Eric
Eric

Reputation: 167

Azure Functions - Microsoft.NET.Sdk.Functions U1100 Error

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

Answers (2)

Art Spasky
Art Spasky

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

anon
anon

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.

  1. Vs Code > Azure Function Extension > Created New Folder for workspace > Selected C# as language and .Net Core 6 as Runtime along with Azure Functions Core Tools Version 4.
  2. When I Run locally, I got the following output: enter image description here

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: enter image description here

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:

enter image description here

U1100: Unable to resolve 'Microsoft.NET.Sdk.Functions (>= 4.0.1)' for 'net6.0

Note:

  1. Make Sure you have installed both the dotnet 6.0 SDK and runtime packages. If anything is missed, download it from here.
  2. Even if you installed the azure functions core tools version 4, check-in the command prompt whether it is showing version 4 using this cmdlet func version or func --version.
  3. Press F1 or Fn + F1 in the VS Code editor and type Preferences: Open user settings, then search for Azure Functions: Project Runtime and change the default runtime version to ~4. enter image description here

Upvotes: 0

Related Questions