diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs
index 1403858a40..3a6b4f7562 100644
--- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs
+++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs
@@ -176,7 +176,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
var model = new ErrorPageModel();
var runtimeType = Microsoft.Extensions.Internal.RuntimeEnvironment.RuntimeType;
model.RuntimeDisplayName = (runtimeType == "CoreCLR") ? ".NET Core" : runtimeType == "CLR" ? ".NET Framework" : "Mono";
-#if NETSTANDARD1_3
+#if NETSTANDARD1_3 || NETSTANDARD1_5
var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly;
var assemblyVersion = new AssemblyName(systemRuntimeAssembly.FullName).Version.ToString();
var clrVersion = assemblyVersion;
diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs b/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs
index 6504208c0b..ff2aa31a7d 100644
--- a/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs
+++ b/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs
@@ -2,6 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+#if NETSTANDARD1_5
+using System.Reflection;
+using System.Runtime.Loader;
+#endif
using System.Threading;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.DependencyInjection;
@@ -16,18 +20,33 @@ namespace Microsoft.AspNetCore.Hosting
/// The to run.
public static void Run(this IWebHost host)
{
+ var done = new ManualResetEventSlim(false);
using (var cts = new CancellationTokenSource())
{
+ Action shutdown = () =>
+ {
+ if (!cts.IsCancellationRequested)
+ {
+ Console.WriteLine("Application is shutting down...");
+ cts.Cancel();
+ }
+
+ done.Wait();
+ };
+
+#if NETSTANDARD1_5
+ var assemblyLoadContext = AssemblyLoadContext.GetLoadContext(typeof(WebHostExtensions).GetTypeInfo().Assembly);
+ assemblyLoadContext.Unloading += context => shutdown();
+#endif
Console.CancelKeyPress += (sender, eventArgs) =>
{
- Console.WriteLine("Application is shutting down...");
- cts.Cancel();
-
+ shutdown();
// Don't terminate the process immediately, wait for the Main thread to exit gracefully.
eventArgs.Cancel = true;
};
host.Run(cts.Token, "Application started. Press Ctrl+C to shut down.");
+ done.Set();
}
}
diff --git a/src/Microsoft.AspNetCore.Hosting/project.json b/src/Microsoft.AspNetCore.Hosting/project.json
index 639e321429..e63a105171 100644
--- a/src/Microsoft.AspNetCore.Hosting/project.json
+++ b/src/Microsoft.AspNetCore.Hosting/project.json
@@ -69,6 +69,12 @@
"dependencies": {
"System.Diagnostics.StackTrace": "4.3.0-*"
}
+ },
+ "netstandard1.5": {
+ "dependencies": {
+ "System.Diagnostics.StackTrace": "4.3.0-*",
+ "System.Runtime.Loader": "4.3.0-*"
+ }
}
},
"tools": {