The Microsoft.AspNetCore.Hosting.IWebHostEnvironment Bug journey #29691
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.
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.
The text was updated successfully, but these errors were encountered: