Skip to content

The Microsoft.AspNetCore.Hosting.IWebHostEnvironment Bug journey #29691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
codingyourlife opened this issue May 6, 2020 · 3 comments
Closed
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue.

Comments

@codingyourlife
Copy link

Hi. I'm after a little Bug journey...

The goal:
I just wanted to have a small class library project which uses IWebHostEnvironment and is referenced by my ASP.NET Core MVC web application.

Obstacle 1 - Where is IWebHostEnvironment:
So IWebHostEnvironment is housing in Microsoft.AspNetCore.Hosting namespace. There is a nuget package called Microsoft.AspNetCore.Hosting where you could suspect finding it. When installed it still cannot find this Interface.
I've found out that IWebHostEnvironment can be found in the nuget package Microsoft.AspNetCore.App.
My answer here on SO: https://stackoverflow.com/a/61156057/828184

-> still open SO question

Obstacle 2 - Not building on mac / Is it an app or a classlib now:
I guess after Obstacle 1 with now the Microsoft.AspNetCore.App nuget package it caused my classlibrary project to become an app. At least somehow an app because the csproj could still be a classlibrary. On Windows with Visual Studio 2019 it works without changing to and all is fine. But when I tried to build on Visual Studio for Mac I ran into really strange build errors. I remembered my SO answer and tried what someone commented in my answer and this did help me. But now it's an executable classlibrary.
So I've decided to just change my small classlibrary into a web project. This also implicates having a useless Main method where I just throw a NotImplementedException.
-> so not working on VS for mac or an unwanted executable

Obstacle 3 - Cannot publish self-contained worker project referencing another:
Everything seemed to work fine. Now I tried to publish. Publishing works when using the publish feature in VS on Windows but it does not when using the dotnet publish command using powershell. I use DotNetNuke also and there it just fails with exit code 1.
Well even if one could argue that you shouldn't reference another project which is also an executable kind I was forced to have it that way. Well and then there is this open Github issue about it or actually at least two it seems:
dotnet/sdk#10902
dotnet/sdk#10566
-> still open github issues and publishing only works with a workaround

The current status/workaround:
So all in all I just wanted to use IWebHostEnvironment in a .NET Core 3.1 classlibrary project being referenced by my MVC webapp and I ended up in open SO and Github issues. I've wasted a lot of time troubleshooting and now I have a workaround I am really not happy with. Concretely I have a classlibrary that has to be an executable and a RuntimeIdentifier in the *.csproj file where I do not want to have it and I guess will cause other issues.

In testing there is a saying that if you find a bug in one spot there is likely more around that area. I found this to be very true here so I thought I do this unusual summary issue with a simple use case behind it.

@a-patel
Copy link

a-patel commented Dec 7, 2020

any update on this, please?

@joeloff joeloff removed their assignment Jan 27, 2021
@joeloff joeloff transferred this issue from dotnet/sdk Jan 27, 2021
@Tratcher
Copy link
Member

See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-5.0&tabs=visual-studio

@Tratcher Tratcher added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Jan 29, 2021
@ghost
Copy link

ghost commented Feb 2, 2021

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Feb 5, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Mar 8, 2021
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue.
Projects
None yet
Development

No branches or pull requests

6 participants