diff --git a/Hosting.sln b/Hosting.sln
index cccee8976f..8aafc60dd3 100644
--- a/Hosting.sln
+++ b/Hosting.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.26228.9
+VisualStudioVersion = 15.0.26510.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0497F39-AFFB-4819-A116-E39E361915AB}"
EndProject
@@ -32,6 +32,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestStartupAssembly1", "tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Hosting.Abstractions", "src\Microsoft.Extensions.Hosting.Abstractions\Microsoft.Extensions.Hosting.Abstractions.csproj", "{96BC7EEA-64D9-4DA5-8E87-1C18CBFE7D12}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Hosting.WindowsServices", "src\Microsoft.AspNetCore.Hosting.WindowsServices\Microsoft.AspNetCore.Hosting.WindowsServices.csproj", "{9C93A93B-270A-4785-8F41-46C38DC33825}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -178,6 +180,18 @@ Global
{96BC7EEA-64D9-4DA5-8E87-1C18CBFE7D12}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{96BC7EEA-64D9-4DA5-8E87-1C18CBFE7D12}.Release|x86.ActiveCfg = Release|Any CPU
{96BC7EEA-64D9-4DA5-8E87-1C18CBFE7D12}.Release|x86.Build.0 = Release|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Debug|x86.Build.0 = Debug|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Release|x86.ActiveCfg = Release|Any CPU
+ {9C93A93B-270A-4785-8F41-46C38DC33825}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -195,5 +209,6 @@ Global
{542D4600-B232-4B17-A08C-E31EBFA0D74E} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0}
{39D3B138-37DB-4D03-A5A0-3F2B02EFC671} = {FEB39027-9158-4DE2-997F-7ADAEF8188D0}
{96BC7EEA-64D9-4DA5-8E87-1C18CBFE7D12} = {E0497F39-AFFB-4819-A116-E39E361915AB}
+ {9C93A93B-270A-4785-8F41-46C38DC33825} = {E0497F39-AFFB-4819-A116-E39E361915AB}
EndGlobalSection
EndGlobal
diff --git a/build/common.props b/build/common.props
index 6fe4c620dc..1241ae80fb 100644
--- a/build/common.props
+++ b/build/common.props
@@ -16,8 +16,8 @@
-
-
+
+
diff --git a/build/dependencies.props b/build/dependencies.props
index 98f4d1a3e7..419f253f2c 100644
--- a/build/dependencies.props
+++ b/build/dependencies.props
@@ -3,6 +3,8 @@
2.0.0-*
2.1.0-*
$(BundledNETStandardPackageVersion)
+ 2.0.0-*
+ 4.4.0-*
15.3.0-*
1.0.1
2.3.0-beta2-*
diff --git a/samples/SampleStartups/SampleStartups.csproj b/samples/SampleStartups/SampleStartups.csproj
index c090c5bdea..4b3cb32749 100644
--- a/samples/SampleStartups/SampleStartups.csproj
+++ b/samples/SampleStartups/SampleStartups.csproj
@@ -3,7 +3,7 @@
- netcoreapp2.0
+ netcoreapp2.0;net461
SampleStartups.StartupInjection
exe
@@ -18,4 +18,7 @@
+
+
+
diff --git a/src/Microsoft.AspNetCore.Hosting.Abstractions/Microsoft.AspNetCore.Hosting.Abstractions.csproj b/src/Microsoft.AspNetCore.Hosting.Abstractions/Microsoft.AspNetCore.Hosting.Abstractions.csproj
index 910262a023..6fee54c3bd 100644
--- a/src/Microsoft.AspNetCore.Hosting.Abstractions/Microsoft.AspNetCore.Hosting.Abstractions.csproj
+++ b/src/Microsoft.AspNetCore.Hosting.Abstractions/Microsoft.AspNetCore.Hosting.Abstractions.csproj
@@ -4,7 +4,7 @@
ASP.NET Core hosting and startup abstractions for web applications.
- netcoreapp2.0
+ netstandard2.0
$(NoWarn);CS1591
true
aspnetcore;hosting
diff --git a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj
index 8641009420..d2c9b9dab7 100644
--- a/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj
+++ b/src/Microsoft.AspNetCore.Hosting.Server.Abstractions/Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj
@@ -4,7 +4,7 @@
ASP.NET Core hosting server abstractions for web applications.
- netcoreapp2.0
+ netstandard2.0
$(NoWarn);CS1591
true
aspnetcore;hosting
diff --git a/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.csproj b/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.csproj
new file mode 100644
index 0000000000..f6535f0801
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/Microsoft.AspNetCore.Hosting.WindowsServices.csproj
@@ -0,0 +1,19 @@
+
+
+
+
+
+ ASP.NET Core hosting infrastructure and startup logic for web applications running within a Windows service.
+ net461
+ $(NoWarn);CS1591
+ true
+ aspnetcore;hosting
+
+
+
+
+
+
+
+
+
diff --git a/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs
new file mode 100644
index 0000000000..f8121e5dce
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostService.cs
@@ -0,0 +1,76 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.ServiceProcess;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Microsoft.AspNetCore.Hosting.WindowsServices
+{
+ ///
+ /// Provides an implementation of a Windows service that hosts ASP.NET Core.
+ ///
+ public class WebHostService : ServiceBase
+ {
+ private IWebHost _host;
+ private bool _stopRequestedByWindows;
+
+ ///
+ /// Creates an instance of WebHostService which hosts the specified web application.
+ ///
+ /// The configured web host containing the web application to host in the Windows service.
+ public WebHostService(IWebHost host)
+ {
+ _host = host;
+ }
+
+ protected sealed override void OnStart(string[] args)
+ {
+ OnStarting(args);
+
+ _host
+ .Services
+ .GetRequiredService()
+ .ApplicationStopped
+ .Register(() =>
+ {
+ if (!_stopRequestedByWindows)
+ {
+ Stop();
+ }
+ });
+
+ _host.Start();
+
+ OnStarted();
+ }
+
+ protected sealed override void OnStop()
+ {
+ _stopRequestedByWindows = true;
+ OnStopping();
+ _host?.Dispose();
+ OnStopped();
+ }
+
+ ///
+ /// Executes before ASP.NET Core starts.
+ ///
+ /// The command line arguments passed to the service.
+ protected virtual void OnStarting(string[] args) { }
+
+ ///
+ /// Executes after ASP.NET Core starts.
+ ///
+ protected virtual void OnStarted() { }
+
+ ///
+ /// Executes before ASP.NET Core shuts down.
+ ///
+ protected virtual void OnStopping() { }
+
+ ///
+ /// Executes after ASP.NET Core shuts down.
+ ///
+ protected virtual void OnStopped() { }
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs
new file mode 100644
index 0000000000..9e657fbe3e
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/WebHostWindowsServiceExtensions.cs
@@ -0,0 +1,42 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.ServiceProcess;
+
+namespace Microsoft.AspNetCore.Hosting.WindowsServices
+{
+ ///
+ /// Extensions to for hosting inside a Windows service.
+ ///
+ public static class WebHostWindowsServiceExtensions
+ {
+ ///
+ /// Runs the specified web application inside a Windows service and blocks until the service is stopped.
+ ///
+ /// An instance of the to host in the Windows service.
+ ///
+ /// This example shows how to use .
+ ///
+ /// public class Program
+ /// {
+ /// public static void Main(string[] args)
+ /// {
+ /// var config = WebHostConfiguration.GetDefault(args);
+ ///
+ /// var host = new WebHostBuilder()
+ /// .UseConfiguration(config)
+ /// .Build();
+ ///
+ /// // This call will block until the service is stopped.
+ /// host.RunAsService();
+ /// }
+ /// }
+ ///
+ ///
+ public static void RunAsService(this IWebHost host)
+ {
+ var webHostService = new WebHostService(host);
+ ServiceBase.Run(webHostService);
+ }
+ }
+}
diff --git a/src/Microsoft.AspNetCore.Hosting.WindowsServices/baseline.netframework.json b/src/Microsoft.AspNetCore.Hosting.WindowsServices/baseline.netframework.json
new file mode 100644
index 0000000000..ec158c87ac
--- /dev/null
+++ b/src/Microsoft.AspNetCore.Hosting.WindowsServices/baseline.netframework.json
@@ -0,0 +1,122 @@
+{
+ "AssemblyIdentity": "Microsoft.AspNetCore.Hosting.WindowsServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60",
+ "Types": [
+ {
+ "Name": "Microsoft.AspNetCore.Hosting.WindowsServices.WebHostService",
+ "Visibility": "Public",
+ "Kind": "Class",
+ "BaseType": "System.ServiceProcess.ServiceBase",
+ "ImplementedInterfaces": [],
+ "Members": [
+ {
+ "Kind": "Method",
+ "Name": "OnStart",
+ "Parameters": [
+ {
+ "Name": "args",
+ "Type": "System.String[]"
+ }
+ ],
+ "ReturnType": "System.Void",
+ "Sealed": true,
+ "Virtual": true,
+ "Override": true,
+ "Visibility": "Protected",
+ "GenericParameter": []
+ },
+ {
+ "Kind": "Method",
+ "Name": "OnStop",
+ "Parameters": [],
+ "ReturnType": "System.Void",
+ "Sealed": true,
+ "Virtual": true,
+ "Override": true,
+ "Visibility": "Protected",
+ "GenericParameter": []
+ },
+ {
+ "Kind": "Method",
+ "Name": "OnStarting",
+ "Parameters": [
+ {
+ "Name": "args",
+ "Type": "System.String[]"
+ }
+ ],
+ "ReturnType": "System.Void",
+ "Virtual": true,
+ "Visibility": "Protected",
+ "GenericParameter": []
+ },
+ {
+ "Kind": "Method",
+ "Name": "OnStarted",
+ "Parameters": [],
+ "ReturnType": "System.Void",
+ "Virtual": true,
+ "Visibility": "Protected",
+ "GenericParameter": []
+ },
+ {
+ "Kind": "Method",
+ "Name": "OnStopping",
+ "Parameters": [],
+ "ReturnType": "System.Void",
+ "Virtual": true,
+ "Visibility": "Protected",
+ "GenericParameter": []
+ },
+ {
+ "Kind": "Method",
+ "Name": "OnStopped",
+ "Parameters": [],
+ "ReturnType": "System.Void",
+ "Virtual": true,
+ "Visibility": "Protected",
+ "GenericParameter": []
+ },
+ {
+ "Kind": "Constructor",
+ "Name": ".ctor",
+ "Parameters": [
+ {
+ "Name": "host",
+ "Type": "Microsoft.AspNetCore.Hosting.IWebHost"
+ }
+ ],
+ "Visibility": "Public",
+ "GenericParameter": []
+ }
+ ],
+ "GenericParameters": []
+ },
+ {
+ "Name": "Microsoft.AspNetCore.Hosting.WindowsServices.WebHostWindowsServiceExtensions",
+ "Visibility": "Public",
+ "Kind": "Class",
+ "Abstract": true,
+ "Static": true,
+ "Sealed": true,
+ "ImplementedInterfaces": [],
+ "Members": [
+ {
+ "Kind": "Method",
+ "Name": "RunAsService",
+ "Parameters": [
+ {
+ "Name": "host",
+ "Type": "Microsoft.AspNetCore.Hosting.IWebHost"
+ }
+ ],
+ "ReturnType": "System.Void",
+ "Static": true,
+ "Extension": true,
+ "Visibility": "Public",
+ "GenericParameter": []
+ }
+ ],
+ "GenericParameters": []
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNetCore.Hosting/Microsoft.AspNetCore.Hosting.csproj b/src/Microsoft.AspNetCore.Hosting/Microsoft.AspNetCore.Hosting.csproj
index f9677775a3..9913716f60 100644
--- a/src/Microsoft.AspNetCore.Hosting/Microsoft.AspNetCore.Hosting.csproj
+++ b/src/Microsoft.AspNetCore.Hosting/Microsoft.AspNetCore.Hosting.csproj
@@ -4,7 +4,7 @@
ASP.NET Core hosting infrastructure and startup logic for web applications.
- netcoreapp2.0
+ netstandard2.0
$(NoWarn);CS1591
true
aspnetcore;hosting
@@ -29,6 +29,7 @@
+
diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs b/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs
index 167668dcd2..0689b9f252 100644
--- a/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs
+++ b/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs
@@ -3,7 +3,6 @@
using System;
using System.Reflection;
-using System.Runtime.Loader;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting.Server.Features;
@@ -90,8 +89,7 @@ namespace Microsoft.AspNetCore.Hosting
done.Wait();
};
- var assemblyLoadContext = AssemblyLoadContext.GetLoadContext(typeof(WebHostExtensions).GetTypeInfo().Assembly);
- assemblyLoadContext.Unloading += context => shutdown();
+ AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => shutdown();
Console.CancelKeyPress += (sender, eventArgs) =>
{
shutdown();
diff --git a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Microsoft.AspNetCore.Server.IntegrationTesting.csproj b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Microsoft.AspNetCore.Server.IntegrationTesting.csproj
index 3a81b2f913..d3a7fb1491 100644
--- a/src/Microsoft.AspNetCore.Server.IntegrationTesting/Microsoft.AspNetCore.Server.IntegrationTesting.csproj
+++ b/src/Microsoft.AspNetCore.Server.IntegrationTesting/Microsoft.AspNetCore.Server.IntegrationTesting.csproj
@@ -5,7 +5,7 @@
ASP.NET Core helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.
0.4.0
- netcoreapp2.0
+ netstandard2.0
$(NoWarn);CS1591
true
aspnetcore;testing
diff --git a/src/Microsoft.AspNetCore.TestHost/Microsoft.AspNetCore.TestHost.csproj b/src/Microsoft.AspNetCore.TestHost/Microsoft.AspNetCore.TestHost.csproj
index 81cee25977..63e5fbd1d4 100644
--- a/src/Microsoft.AspNetCore.TestHost/Microsoft.AspNetCore.TestHost.csproj
+++ b/src/Microsoft.AspNetCore.TestHost/Microsoft.AspNetCore.TestHost.csproj
@@ -4,7 +4,7 @@
ASP.NET Core web server for writing and running tests.
- netcoreapp2.0
+ netstandard2.0
$(NoWarn);CS1591
true
aspnetcore;hosting;testing
diff --git a/src/Microsoft.Extensions.Hosting.Abstractions/Microsoft.Extensions.Hosting.Abstractions.csproj b/src/Microsoft.Extensions.Hosting.Abstractions/Microsoft.Extensions.Hosting.Abstractions.csproj
index f68cec68fb..678a046bb3 100644
--- a/src/Microsoft.Extensions.Hosting.Abstractions/Microsoft.Extensions.Hosting.Abstractions.csproj
+++ b/src/Microsoft.Extensions.Hosting.Abstractions/Microsoft.Extensions.Hosting.Abstractions.csproj
@@ -4,7 +4,7 @@
.NET Core hosting and startup abstractions for applications.
- netcoreapp2.0
+ netstandard2.0
$(NoWarn);CS1591
true
hosting
diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.csproj
index ee55cd9f6e..20bb60d399 100644
--- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.csproj
+++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.csproj
@@ -3,7 +3,8 @@
- netcoreapp2.0
+ netcoreapp2.0;net461
+ netcoreapp2.0
diff --git a/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.csproj b/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.csproj
index cb05129b5e..69b8d0068c 100644
--- a/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.csproj
+++ b/test/Microsoft.AspNetCore.Hosting.TestSites/Microsoft.AspNetCore.Hosting.TestSites.csproj
@@ -3,7 +3,8 @@
- netcoreapp2.0
+ netcoreapp2.0;net461
+ netcoreapp2.0
Exe
diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.csproj b/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.csproj
index 8b3a08da12..8916957acd 100644
--- a/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.csproj
+++ b/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.csproj
@@ -3,7 +3,8 @@
- netcoreapp2.0
+ netcoreapp2.0;net461
+ netcoreapp2.0
diff --git a/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.csproj b/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.csproj
index 792dbe7aec..ccd8da73eb 100644
--- a/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.csproj
+++ b/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.csproj
@@ -3,7 +3,8 @@
- netcoreapp2.0
+ netcoreapp2.0;net461
+ netcoreapp2.0
diff --git a/test/TestStartupAssembly1/TestStartupAssembly1.csproj b/test/TestStartupAssembly1/TestStartupAssembly1.csproj
index 02ed725637..a1bd289c68 100644
--- a/test/TestStartupAssembly1/TestStartupAssembly1.csproj
+++ b/test/TestStartupAssembly1/TestStartupAssembly1.csproj
@@ -3,7 +3,7 @@
- netcoreapp2.0
+ netcoreapp2.0;net461