Skip to content
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

Microsoft.Extensions.PlatformAbstractions has been removed #237

Open
analogrelay opened this issue Apr 27, 2017 · 1 comment
Open

Microsoft.Extensions.PlatformAbstractions has been removed #237

analogrelay opened this issue Apr 27, 2017 · 1 comment

Comments

@analogrelay
Copy link

In ASP.NET Core 2.0 we are removing the Microsoft.Extensions.PlatformAbstractions package as it is no longer necessary to maintain this abstraction. Consumers of this package will need to replace their use of these APIs with the standard .NET APIs as follows:

Microsoft.Extensions.PlatformAbstractions Equivalent .NET API
ApplicationEnvironment.ApplicationBasePath System.AppContext.BaseDirectory or System.AppDomain.CurrentDomain.BaseDirectory
ApplicationEnvironment.ApplicationName System.Reflection.Assembly.GetEntryAssembly().GetName().Name or System.AppDomain.CurrentDomain.SetupInformation.ApplicationName
ApplicationEnvironment.ApplicationVersion System.Reflection.Assembly.GetEntryAssembly().GetName().Version
ApplicationEnvironment.RuntimeFramework System.Reflection.Assembly.GetEntryAssembly().GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName or System.AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName

See aspnet/PlatformAbstractions#50 for more detail or to discuss this change.

@aspnet aspnet locked and limited conversation to collaborators Apr 27, 2017
@natemcmaster natemcmaster added this to the 2.0.0-preview1 milestone Apr 27, 2017
@danroth27 danroth27 added 2.0.0 and removed 2.0.0 labels Aug 3, 2017
@analogrelay
Copy link
Author

analogrelay commented Aug 21, 2017

Note: As part of this change, you could encounter the following error if you build your WebHost by injecting IStartup directly into the DI container, rather than calling .UseStartup or .Configure:

Unhandled Exception: System.ArgumentException: A valid non-empty application name must be provided.
Parameter name: applicationName
   at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize(IHostingEnvironment hostingEnvironment, String applicationName, String contentRootPath, WebHostOptions options)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at ConsoleApp11.Program.Main(String[] args) in C:\Users\dfowler\documents\visual studio 2017\Projects\ConsoleApp11\ConsoleApp11\Program.cs:line 11

This occurs because we need to get the name of the application. Previously, we used some heuristics to detect it, but we removed some of them in 2.0. In the scenario above, where IStartup is manually injected into the container, add the following call to your WebHostBuilder set-up sequence:

WebHost.CreateDefaultBuilder(args)
    // ... other Web Host configuration calls
    .UseSetting(WebHostDefaults.ApplicationKey, "[Application Name]")

NOTE: This is only required in 2.0 and only when you do NOT call .UseStartup or .Configure

See aspnet/Hosting#1137 for further info.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants