dotnet / Scaffolding

Code generators to speed up development.
MIT License
639 stars 229 forks source link

IWebHostEnvironment could not be found #1186

Open kanisimoff opened 4 years ago

kanisimoff commented 4 years ago

I use Microsoft.Extensions.Hosting.Abstraction, but when compiling, I see an error:

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) LogicServices D:\GitHub\tyrchik\src\Tyrchik.Site\LogicLayer\LogicServices\UploadFileService.cs 15 Active

Actual behavior:

Additional information about the project:

Target framework(s):

.Net Core 3.1

Package version of Microsoft.AspNetCore.App or Microsoft.AspNetCore.All (if applicable):

Microsoft.Extensions.Hosting.Abstraction v3.1.0

deepchoudhery commented 4 years ago

Hi, Could you let me know what Microsoft.VisualStudio.Web.CodeGeneration.Design package version you are using from the csproj file.

Thanks.

kanisimoff commented 4 years ago

Hi, All links to all libraries from the project:

<ItemGroup>
    <PackageReference Include="Markdig" Version="0.18.0" />
    <PackageReference Include="Markdig.SyntaxHighlighting" Version="1.1.7" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
  </ItemGroup>

Thanks

deepchoudhery commented 4 years ago

Just to get some information, what was the last action you made that made this warning pop up? Updated the Code Gen package, adding the Abstraction package etc. What does the file contain pertaining the warning?

Thanks

kanisimoff commented 4 years ago

I have a basic site project and a project with a class library. I added assemblies to the class library as indicated in the previous post, but when compiling I get an error message: IWebHostEnvironment could not be found.

Thanks

deepchoudhery commented 4 years ago

Is the problem still persisting?

mgrdanc commented 4 years ago

I had a similar issue with a class library and the way I solved it was adding FrameworkReference Include="Microsoft.AspNetCore.App" to the references. Oddly enough it seemed like the project was stuck using an earlier version of .NetCore's framework. I know its not directly connected but it might help out someone else.

lionelquirynen commented 4 years ago

I received the same problem while trying to build a docker image : error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?). Target Framework : .net Core 3.0

lrsbrgrn commented 4 years ago

I received the same problem while trying to build a docker image : error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?). Target Framework : .net Core 3.0

Issue solved by adding in our csproj file (3.1 core app):

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

See: https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#framework-reference

deepchoudhery commented 4 years ago

@kanisimoff does the aformentioned info help?

ghost commented 4 years ago

yes, it helps

martijnvanschie commented 4 years ago

I received the same problem while trying to build a docker image : error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?). Target Framework : .net Core 3.0

Issue solved by adding in our csproj file (3.1 core app):

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

See: https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#framework-reference

I tried a tutorial on self-hosted SignalR server in a console application and your solution work great :).

See: SignalR background-service

But apparently there is another solution as the example i used actually uses another SDK in the project file.

<Project Sdk="Microsoft.NET.Sdk.Web">

I started a new console app and it gives me

<Project Sdk="Microsoft.NET.Sdk">

Both solution work. Thanx :)

danieltabarest commented 4 years ago
<FrameworkReference Include="Microsoft.AspNetCore.App" />

This worked for me thanks

dorkalord commented 4 years ago

I received the same problem while trying to build a docker image : error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?). Target Framework : .net Core 3.0

Issue solved by adding in our csproj file (3.1 core app):

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

See: https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#framework-reference

I tried a tutorial on self-hosted SignalR server in a console application and your solution work great :).

See: SignalR background-service

But apparently there is another solution as the example i used actually uses another SDK in the project file.

<Project Sdk="Microsoft.NET.Sdk.Web">

I started a new console app and it gives me

<Project Sdk="Microsoft.NET.Sdk">

Both solution work. Thanx :)

This works

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include=...
</ItemGroup>

And also changing <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="Microsoft.NET.Sdk.Web"> Worked for me

frankodoom commented 3 years ago

this also worked for me `

`

bdshanto commented 3 years ago

Package Microsoft.AspNetCore.App 2.2.0 is not compatible with netstandard2.1 (.NETStandard,Version=v2.1). Package Microsoft.AspNetCore.App 2.8.0 supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2) 😞

deepchoudhery commented 3 years ago

Scaffolding is not supported in netstandard. Only netcoreapp2.1+ and .NET 5.0+.

Thanks.

davidbuckleyni commented 3 years ago

I received the same problem while trying to build a docker image : error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?). Target Framework : .net Core 3.0

Issue solved by adding in our csproj file (3.1 core app):

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

See: https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#framework-reference

Cant beleive this fixed it in VS2022 same issue crazy but its a .net 6 project is it safe to do that,

Millymanz commented 2 years ago
<FrameworkReference Include="Microsoft.AspNetCore.App" />

This worked for me thanks

This worked for me also, this solves it