Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
New Project , Class Library (.NET Standard)
On project, properties, changed from 2.0 to 2.1
Modified Class1 :
public class Class1
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
This fixed (correctly?) the IApplicationBuilder red squiggly :
However the library project does not compile :
"Error CS0246 The type or namespace name 'IWebHostEnvironment' could not be found ..."
What references should be added for these two interfaces please ?
Or are you only supposed to only ever use these interfaces within the web site project ?
Also same result with a .NET Core 3.1 Class Library.
Visual Studio 16.4.4
Any help much appreciated.
You might want to follow this guide (for migrating 2.2 to 3.0)
https://learn.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio
This explains what happened
https://github.com/dotnet/AspNetCore/issues/7749
Update:
Net Standard
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- Should work with either if you have sdks installed and do restore -->
<!--<TargetFramework>netstandard2.1</TargetFramework>-->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.1" />
</ItemGroup>
</Project>
With class file
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
namespace ClassLibrary2
public class Class1
public void Configure(IApplicationBuilder app, IHostEnvironment env)
Net Core 3.1
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
With class file
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
namespace ClassLibrary3
public class Class1
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
–
–
This seems to work in a .NET Core 3.1 Class Library project file, but not a .NET Standard 2.1 one :
I added the following to the project file :
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
Now the build succeeds with :
public class Class1
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Is there a way for a .NET Standard 2.1 Class Library project to support the new IWebHostEnvironment ?
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.