最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

visual studio - Type or namespace Azure does not exist in the namespace 'Microsoft' - Stack Overflow

programmeradmin6浏览0评论

I am new to C# development. I tried to create a new Azure function app by following online tutorial.

As soon as I created I am getting attached error. I tried the same in Visual Studio Code and Visual Studio as well.

Have I missed any reference or Nuget package?

Here is my csproj file

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <RootNamespace>Approve_PowerApp</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <!-- Application Insights isn't enabled by default. See . -->
    <!-- <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> -->
    <!-- <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" /> -->
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/>
  </ItemGroup>
</Project>

This is how my Nuget package manager looks like.

After dotnet restore command. The packages are showing error in csproj file.

I am new to C# development. I tried to create a new Azure function app by following online tutorial.

As soon as I created I am getting attached error. I tried the same in Visual Studio Code and Visual Studio as well.

Have I missed any reference or Nuget package?

Here is my csproj file

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <RootNamespace>Approve_PowerApp</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <!-- Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4. -->
    <!-- <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" /> -->
    <!-- <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" /> -->
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/>
  </ItemGroup>
</Project>

This is how my Nuget package manager looks like.

After dotnet restore command. The packages are showing error in csproj file.

Share Improve this question edited Mar 26 at 10:54 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Mar 20 at 10:45 VetrivelmuruganVetrivelmurugan 552 silver badges8 bronze badges 3
  • You have to install Microsoft.Azure.Functions.Worker Nuget package. If the package is already installed, wait for some time to load the libraries. – Pravallika KV Commented Mar 20 at 10:47
  • Look for the library in VS Solution Explorer : References. Right click the library and under properties you will find the property Identity. The identity could be wrong or the reference is not found on the machine and you would need to install the missing library. – jdweng Commented Mar 20 at 11:38
  • @AndreaT: thanks for wanting to improve posts here. Bear in mind that bolding is nearly never required; text is harder to read when it is different weights. Spoken emphasis can be achieved using italics, but it should be used sparingly. The names of software, languages etc are not themselves code and show not be rendered as code; they are proper nouns, so observing the rules on case is sufficient. – halfer Commented Mar 26 at 10:53
Add a comment  | 

2 Answers 2

Reset to default 2

Normally speaking, the error indicates that we don't have Microsoft.Azure.Functions.Worker reference but this package exists in csproj indeed with a correct version. So that the issue is the package isn’t properly referenced or resolved.

Firstly, we'd better to check weather our project has this reference or not like what jdweng said in the comment.

If it existed, try dotnet restore command or right click on the project and select to clean and rebuild the application, then see whether this issue still exists or not. We can also go to the project directory and delete .vs folder then try clean and rebuild.

To resolve this issue, you have to install Microsoft.Azure.Functions.Worker NuGet package.

Navigate to Tools=>NuGet Package Manager=>Manage NuGet Packages for solution, install the Microsoft.Azure.Functions.Worker package:

Check the installed packages in .csproj file, you can open it by clicking on the Project name.

.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/>
  </ItemGroup>
</Project>

After creating the project, wait for some time to load the libraries.

发布评论

评论列表(0)

  1. 暂无评论