diff --git a/sdk.slnx b/sdk.slnx index dc0633c42d02..3db98db05673 100644 --- a/sdk.slnx +++ b/sdk.slnx @@ -49,13 +49,17 @@ + + - + + + diff --git a/src/BuiltInTools/BrowserRefresh/.editorconfig b/src/BuiltInTools/BrowserRefresh/.editorconfig deleted file mode 100644 index 4ae90dd7a7a0..000000000000 --- a/src/BuiltInTools/BrowserRefresh/.editorconfig +++ /dev/null @@ -1,2 +0,0 @@ -[*.js] -indent_size = 2 diff --git a/src/BuiltInTools/BrowserRefresh/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj b/src/BuiltInTools/BrowserRefresh/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj index 84852c4df9a9..cb7cec42e392 100644 --- a/src/BuiltInTools/BrowserRefresh/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj +++ b/src/BuiltInTools/BrowserRefresh/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj @@ -5,23 +5,13 @@ When updating the TFM also update minimal supported version in dotnet-watch.csproj and WebApplicationAppModel.cs. --> net6.0 - MicrosoftAspNetCore - - - true - true - true - Microsoft.DotNet.HotReload.Web.Middleware - Package containing Hot Reload middleware. true + + MicrosoftAspNetCore - - - - @@ -34,4 +24,5 @@ + diff --git a/src/BuiltInTools/DotNetDeltaApplier/Microsoft.Extensions.DotNetDeltaApplier.csproj b/src/BuiltInTools/DotNetDeltaApplier/Microsoft.Extensions.DotNetDeltaApplier.csproj index 5172480c5f98..87a397c3dd15 100644 --- a/src/BuiltInTools/DotNetDeltaApplier/Microsoft.Extensions.DotNetDeltaApplier.csproj +++ b/src/BuiltInTools/DotNetDeltaApplier/Microsoft.Extensions.DotNetDeltaApplier.csproj @@ -1,9 +1,4 @@  - - - - - net6.0;net10.0 MicrosoftAspNetCore - - - true - true - true - Microsoft.DotNet.HotReload.Agent.Host - Package containing Hot Reload agent host. - true - - - + + + + diff --git a/src/BuiltInTools/HotReloadAgent.Host/.editorconfig b/src/BuiltInTools/HotReloadAgent.Host/.editorconfig new file mode 100644 index 000000000000..4694508c4da5 --- /dev/null +++ b/src/BuiltInTools/HotReloadAgent.Host/.editorconfig @@ -0,0 +1,6 @@ +[*.cs] + +# IDE0240: Remove redundant nullable directive +# The directive needs to be included since all sources in a source package are considered generated code +# when referenced from a project via package reference. +dotnet_diagnostic.IDE0240.severity = none \ No newline at end of file diff --git a/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.Package.csproj b/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.Package.csproj new file mode 100644 index 000000000000..b5630dcc8e6e --- /dev/null +++ b/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.Package.csproj @@ -0,0 +1,42 @@ + + + + + net6.0;net10.0 + true + + false + none + false + preview + + + true + true + true + Microsoft.DotNet.HotReload.Agent.Host + false + Package containing Hot Reload agent host. + + $(NoWarn);NU5128 + + + + + + + + + + + + + + + + diff --git a/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.projitems b/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.projitems new file mode 100644 index 000000000000..c4cd6379e476 --- /dev/null +++ b/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.projitems @@ -0,0 +1,14 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 15C936B2-901D-4A27-AFA6-89CF56F5EB20 + + + Microsoft.DotNet.HotReload + + + + + \ No newline at end of file diff --git a/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.shproj b/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.shproj new file mode 100644 index 000000000000..771b511f6b46 --- /dev/null +++ b/src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.shproj @@ -0,0 +1,13 @@ + + + + 15C936B2-901D-4A27-AFA6-89CF56F5EB20 + 14.0 + + + + + + + + \ No newline at end of file diff --git a/src/BuiltInTools/DotNetDeltaApplier/PipeListener.cs b/src/BuiltInTools/HotReloadAgent.Host/PipeListener.cs similarity index 98% rename from src/BuiltInTools/DotNetDeltaApplier/PipeListener.cs rename to src/BuiltInTools/HotReloadAgent.Host/PipeListener.cs index 6110f0fa631c..dfa108189dff 100644 --- a/src/BuiltInTools/DotNetDeltaApplier/PipeListener.cs +++ b/src/BuiltInTools/HotReloadAgent.Host/PipeListener.cs @@ -1,10 +1,15 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System; using System.Diagnostics; using System.IO.Pipes; using System.Reflection; using System.Runtime.Loader; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.DotNet.HotReload; diff --git a/src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs b/src/BuiltInTools/HotReloadAgent.Host/StartupHook.cs similarity index 76% rename from src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs rename to src/BuiltInTools/HotReloadAgent.Host/StartupHook.cs index 03c7b04a4fea..8c55314f2d0f 100644 --- a/src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs +++ b/src/BuiltInTools/HotReloadAgent.Host/StartupHook.cs @@ -1,12 +1,19 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System; using System.Diagnostics; +using System.IO; using System.IO.Pipes; +using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Runtime.Loader; +using System.Threading; +using System.Threading.Tasks; using Microsoft.DotNet.HotReload; -using Microsoft.DotNet.Watch; /// /// The runtime startup hook looks for top-level type named "StartupHook". @@ -92,7 +99,27 @@ private static void RegisterSignalHandlers() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - ProcessUtilities.EnableWindowsCtrlCHandling(Log); + // Enables handling of Ctrl+C in a process where it was disabled. + // + // If a process is launched with CREATE_NEW_PROCESS_GROUP flag + // it allows the parent process to send Ctrl+C event to the child process, + // but also disables Ctrl+C handlers. + // + // "If the HandlerRoutine parameter is NULL, a TRUE value causes the calling process to ignore CTRL+C input, + // and a FALSE value restores normal processing of CTRL+C input. + // This attribute of ignoring or processing CTRL+C is inherited by child processes." + + if (SetConsoleCtrlHandler(null, false)) + { + Log("Windows Ctrl+C handling enabled."); + } + else + { + Log($"Failed to enable Ctrl+C handling: {GetLastPInvokeErrorMessage()}"); + } + + [DllImport("kernel32.dll", SetLastError = true)] + static extern bool SetConsoleCtrlHandler(Delegate? handler, bool add); } else { @@ -118,6 +145,16 @@ private static void RegisterSignalHandlers() } } + private static string GetLastPInvokeErrorMessage() + { + var error = Marshal.GetLastPInvokeError(); +#if NET10_0_OR_GREATER + return $"{Marshal.GetPInvokeErrorMessage(error)} (code {error})"; +#else + return $"error code {error}"; +#endif + } + private static void Log(string message) { var prefix = s_standardOutputLogPrefix; diff --git a/src/BuiltInTools/Web.Middleware/.editorconfig b/src/BuiltInTools/Web.Middleware/.editorconfig new file mode 100644 index 000000000000..fb89bbbf5f84 --- /dev/null +++ b/src/BuiltInTools/Web.Middleware/.editorconfig @@ -0,0 +1,9 @@ +[*.cs] + +# IDE0240: Remove redundant nullable directive +# The directive needs to be included since all sources in a source package are considered generated code +# when referenced from a project via package reference. +dotnet_diagnostic.IDE0240.severity = none + +[*.js] +indent_size = 2 \ No newline at end of file diff --git a/src/BuiltInTools/BrowserRefresh/ApplicationPaths.cs b/src/BuiltInTools/Web.Middleware/ApplicationPaths.cs similarity index 99% rename from src/BuiltInTools/BrowserRefresh/ApplicationPaths.cs rename to src/BuiltInTools/Web.Middleware/ApplicationPaths.cs index 1d8ea6069bb5..6d784e60e117 100644 --- a/src/BuiltInTools/BrowserRefresh/ApplicationPaths.cs +++ b/src/BuiltInTools/Web.Middleware/ApplicationPaths.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + using Microsoft.AspNetCore.Http; namespace Microsoft.AspNetCore.Watch.BrowserRefresh diff --git a/src/BuiltInTools/BrowserRefresh/BlazorHotReload.js b/src/BuiltInTools/Web.Middleware/BlazorHotReload.js similarity index 100% rename from src/BuiltInTools/BrowserRefresh/BlazorHotReload.js rename to src/BuiltInTools/Web.Middleware/BlazorHotReload.js diff --git a/src/BuiltInTools/BrowserRefresh/BlazorWasmHotReloadMiddleware.cs b/src/BuiltInTools/Web.Middleware/BlazorWasmHotReloadMiddleware.cs similarity index 97% rename from src/BuiltInTools/BrowserRefresh/BlazorWasmHotReloadMiddleware.cs rename to src/BuiltInTools/Web.Middleware/BlazorWasmHotReloadMiddleware.cs index 6ccdd09f6bc3..036ae918f03a 100644 --- a/src/BuiltInTools/BrowserRefresh/BlazorWasmHotReloadMiddleware.cs +++ b/src/BuiltInTools/Web.Middleware/BlazorWasmHotReloadMiddleware.cs @@ -1,7 +1,11 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System.Collections.Generic; using System.Text.Json; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; diff --git a/src/BuiltInTools/BrowserRefresh/BrowserRefreshMiddleware.cs b/src/BuiltInTools/Web.Middleware/BrowserRefreshMiddleware.cs similarity index 99% rename from src/BuiltInTools/BrowserRefresh/BrowserRefreshMiddleware.cs rename to src/BuiltInTools/Web.Middleware/BrowserRefreshMiddleware.cs index 13fac3ceae8e..fd215c4c9dc1 100644 --- a/src/BuiltInTools/BrowserRefresh/BrowserRefreshMiddleware.cs +++ b/src/BuiltInTools/Web.Middleware/BrowserRefreshMiddleware.cs @@ -1,6 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; diff --git a/src/BuiltInTools/BrowserRefresh/BrowserScriptMiddleware.cs b/src/BuiltInTools/Web.Middleware/BrowserScriptMiddleware.cs similarity index 96% rename from src/BuiltInTools/BrowserRefresh/BrowserScriptMiddleware.cs rename to src/BuiltInTools/Web.Middleware/BrowserScriptMiddleware.cs index a9bffacdf930..fcc10510e5eb 100644 --- a/src/BuiltInTools/BrowserRefresh/BrowserScriptMiddleware.cs +++ b/src/BuiltInTools/Web.Middleware/BrowserScriptMiddleware.cs @@ -1,7 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System; using System.Globalization; +using System.IO; +using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; diff --git a/src/BuiltInTools/BrowserRefresh/HostingStartup.cs b/src/BuiltInTools/Web.Middleware/HostingStartup.cs similarity index 97% rename from src/BuiltInTools/BrowserRefresh/HostingStartup.cs rename to src/BuiltInTools/Web.Middleware/HostingStartup.cs index 369133ccbec3..d9354ebdac34 100644 --- a/src/BuiltInTools/BrowserRefresh/HostingStartup.cs +++ b/src/BuiltInTools/Web.Middleware/HostingStartup.cs @@ -1,6 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; diff --git a/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.Package.csproj b/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.Package.csproj new file mode 100644 index 000000000000..f89cbbb34070 --- /dev/null +++ b/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.Package.csproj @@ -0,0 +1,41 @@ + + + + + net6.0 + true + + false + none + false + preview + + + true + true + true + Microsoft.DotNet.HotReload.Web.Middleware + false + Package containing web server middleware to support Hot Reload. + + $(NoWarn);NU5128 + + + + + + + + + + + + + + + + + diff --git a/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.projitems b/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.projitems new file mode 100644 index 000000000000..acee58a75952 --- /dev/null +++ b/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.projitems @@ -0,0 +1,15 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 9F3A6169-66C9-4244-8FC6-222E4D6F8D29 + + + Microsoft.DotNet.HotReload + + + + + + \ No newline at end of file diff --git a/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.shproj b/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.shproj new file mode 100644 index 000000000000..6d8a9e4077cb --- /dev/null +++ b/src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.shproj @@ -0,0 +1,13 @@ + + + + 9F3A6169-66C9-4244-8FC6-222E4D6F8D29 + 14.0 + + + + + + + + \ No newline at end of file diff --git a/src/BuiltInTools/BrowserRefresh/ResponseStreamWrapper.cs b/src/BuiltInTools/Web.Middleware/ResponseStreamWrapper.cs similarity index 98% rename from src/BuiltInTools/BrowserRefresh/ResponseStreamWrapper.cs rename to src/BuiltInTools/Web.Middleware/ResponseStreamWrapper.cs index 16b2256e3f8d..9d2d7f93ad37 100644 --- a/src/BuiltInTools/BrowserRefresh/ResponseStreamWrapper.cs +++ b/src/BuiltInTools/Web.Middleware/ResponseStreamWrapper.cs @@ -1,9 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System; using System.Diagnostics; +using System.IO; using System.IO.Compression; using System.IO.Pipelines; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/BuiltInTools/BrowserRefresh/ScriptInjectingStream.cs b/src/BuiltInTools/Web.Middleware/ScriptInjectingStream.cs similarity index 99% rename from src/BuiltInTools/BrowserRefresh/ScriptInjectingStream.cs rename to src/BuiltInTools/Web.Middleware/ScriptInjectingStream.cs index 7ba91142531f..477979e40de1 100644 --- a/src/BuiltInTools/BrowserRefresh/ScriptInjectingStream.cs +++ b/src/BuiltInTools/Web.Middleware/ScriptInjectingStream.cs @@ -1,8 +1,15 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System; using System.Diagnostics; +using System.IO; using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.AspNetCore.Watch.BrowserRefresh; diff --git a/src/BuiltInTools/BrowserRefresh/StartupHook.cs b/src/BuiltInTools/Web.Middleware/StartupHook.cs similarity index 93% rename from src/BuiltInTools/BrowserRefresh/StartupHook.cs rename to src/BuiltInTools/Web.Middleware/StartupHook.cs index 93be4f31fafa..01ae4ee90a00 100644 --- a/src/BuiltInTools/BrowserRefresh/StartupHook.cs +++ b/src/BuiltInTools/Web.Middleware/StartupHook.cs @@ -1,6 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#nullable enable + +using System; + internal class StartupHook { public static void Initialize() diff --git a/src/BuiltInTools/BrowserRefresh/WebSocketScriptInjection.js b/src/BuiltInTools/Web.Middleware/WebSocketScriptInjection.js similarity index 100% rename from src/BuiltInTools/BrowserRefresh/WebSocketScriptInjection.js rename to src/BuiltInTools/Web.Middleware/WebSocketScriptInjection.js diff --git a/src/BuiltInTools/dotnet-watch.slnf b/src/BuiltInTools/dotnet-watch.slnf index b7454eb8869a..a3cc85fc0d92 100644 --- a/src/BuiltInTools/dotnet-watch.slnf +++ b/src/BuiltInTools/dotnet-watch.slnf @@ -9,6 +9,8 @@ "src\\BuiltInTools\\DotNetWatchTasks\\DotNetWatchTasks.csproj", "src\\BuiltInTools\\HotReloadAgent.Data\\Microsoft.DotNet.HotReload.Agent.Data.Package.csproj", "src\\BuiltInTools\\HotReloadAgent.Data\\Microsoft.DotNet.HotReload.Agent.Data.shproj", + "src\\BuiltInTools\\HotReloadAgent.Host\\Microsoft.DotNet.HotReload.Agent.Host.Package.csproj", + "src\\BuiltInTools\\HotReloadAgent.Host\\Microsoft.DotNet.HotReload.Agent.Host.shproj", "src\\BuiltInTools\\HotReloadAgent.PipeRpc\\Microsoft.DotNet.HotReload.Agent.PipeRpc.Package.csproj", "src\\BuiltInTools\\HotReloadAgent.PipeRpc\\Microsoft.DotNet.HotReload.Agent.PipeRpc.shproj", "src\\BuiltInTools\\HotReloadAgent.WebAssembly.Browser\\Microsoft.DotNet.HotReload.WebAssembly.Browser.csproj", @@ -16,6 +18,8 @@ "src\\BuiltInTools\\HotReloadAgent\\Microsoft.DotNet.HotReload.Agent.shproj", "src\\BuiltInTools\\HotReloadClient\\Microsoft.DotNet.HotReload.Client.Package.csproj", "src\\BuiltInTools\\HotReloadClient\\Microsoft.DotNet.HotReload.Client.shproj", + "src\\BuiltInTools\\Web.Middleware\\Microsoft.DotNet.HotReload.Web.Middleware.Package.csproj", + "src\\BuiltInTools\\Web.Middleware\\Microsoft.DotNet.HotReload.Web.Middleware.shproj", "src\\BuiltInTools\\dotnet-watch\\dotnet-watch.csproj", "test\\Microsoft.AspNetCore.Watch.BrowserRefresh.Tests\\Microsoft.AspNetCore.Watch.BrowserRefresh.Tests.csproj", "test\\Microsoft.DotNet.HotReload.Client.Tests\\Microsoft.DotNet.HotReload.Client.Tests.csproj", diff --git a/src/BuiltInTools/dotnet-watch/Utilities/ProcessUtilities.cs b/src/BuiltInTools/dotnet-watch/Utilities/ProcessUtilities.cs index bcc5ea0374f9..4040e186f0c7 100644 --- a/src/BuiltInTools/dotnet-watch/Utilities/ProcessUtilities.cs +++ b/src/BuiltInTools/dotnet-watch/Utilities/ProcessUtilities.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Runtime.InteropServices; using System.Diagnostics; namespace Microsoft.DotNet.Watch; @@ -9,34 +11,6 @@ internal static class ProcessUtilities { public const int SIGKILL = 9; public const int SIGTERM = 15; - - /// - /// Enables handling of Ctrl+C in a process where it was disabled. - /// - /// If a process is launched with CREATE_NEW_PROCESS_GROUP flag - /// it allows the parent process to send Ctrl+C event to the child process, - /// but also disables Ctrl+C handlers. - /// - public static void EnableWindowsCtrlCHandling(Action log) - { - Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); - - // "If the HandlerRoutine parameter is NULL, a TRUE value causes the calling process to ignore CTRL+C input, - // and a FALSE value restores normal processing of CTRL+C input. - // This attribute of ignoring or processing CTRL+C is inherited by child processes." - - if (SetConsoleCtrlHandler(null, false)) - { - log("Windows Ctrl+C handling enabled."); - } - else - { - log($"Failed to enable Ctrl+C handling: {GetLastPInvokeErrorMessage()}"); - } - - [DllImport("kernel32.dll", SetLastError = true)] - static extern bool SetConsoleCtrlHandler(Delegate? handler, bool add); - } public static string? SendWindowsCtrlCEvent(int processId) {