Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sdk.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@
<Project Path="src/BuiltInTools/DotNetWatchTasks/DotNetWatchTasks.csproj" />
<Project Path="src/BuiltInTools/HotReloadAgent.Data/Microsoft.DotNet.HotReload.Agent.Data.Package.csproj" />
<Project Path="src/BuiltInTools/HotReloadAgent.Data/Microsoft.DotNet.HotReload.Agent.Data.shproj" />
<Project Path="src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.Package.csproj" />
<Project Path="src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.shproj" />
<Project Path="src/BuiltInTools/HotReloadAgent.PipeRpc/Microsoft.DotNet.HotReload.Agent.PipeRpc.Package.csproj" />
<Project Path="src/BuiltInTools/HotReloadAgent.PipeRpc/Microsoft.DotNet.HotReload.Agent.PipeRpc.shproj" />
<Project Path="src/BuiltInTools/HotReloadAgent.WebAssembly.Browser/Microsoft.DotNet.HotReload.WebAssembly.Browser.csproj" />
<Project Path="src/BuiltInTools/HotReloadAgent/Microsoft.DotNet.HotReload.Agent.Package.csproj" />
<Project Path="src/BuiltInTools/HotReloadAgent/Microsoft.DotNet.HotReload.Agent.shproj" />
<Project Path="src/BuiltInTools/HotReloadClient/Microsoft.DotNet.HotReload.Client.Package.csproj" />
<Project Path="src/BuiltInTools/HotReloadClient/Microsoft.DotNet.HotReload.Client.shproj" Id="a78ff92a-d715-4249-9e3d-40d9997a098f" />
<Project Path="src/BuiltInTools/HotReloadClient/Microsoft.DotNet.HotReload.Client.shproj" />
<Project Path="src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.Package.csproj" />
<Project Path="src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.shproj" />
</Folder>
<Folder Name="/src/Cli/">
<Project Path="src/Cli/dotnet/dotnet.csproj" />
Expand Down
2 changes: 0 additions & 2 deletions src/BuiltInTools/BrowserRefresh/.editorconfig

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,13 @@
When updating the TFM also update minimal supported version in dotnet-watch.csproj and WebApplicationAppModel.cs.
-->
<TargetFramework>net6.0</TargetFramework>
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>

<!-- NuGet -->
<IsPackable>true</IsPackable>
<IsShipping>true</IsShipping>
<IsShippingPackage>true</IsShippingPackage>
<PackageId>Microsoft.DotNet.HotReload.Web.Middleware</PackageId>
<PackageDescription>Package containing Hot Reload middleware.</PackageDescription>
<DisableTransitiveFrameworkReferenceDownloads Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</DisableTransitiveFrameworkReferenceDownloads>

<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<EmbeddedResource Include="WebSocketScriptInjection.js" />

<!-- Back compat only -->
<EmbeddedResource Include="BlazorHotReload.js" />
</ItemGroup>

<ItemGroup Condition="'$(DotNetBuildSourceOnly)' == 'true'">
Expand All @@ -34,4 +24,5 @@
<InternalsVisibleTo Include="Microsoft.AspNetCore.Watch.BrowserRefresh.Tests" />
</ItemGroup>

<Import Project="..\Web.Middleware\Microsoft.DotNet.HotReload.Web.Middleware.projitems" Label="Shared" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\HotReloadAgent\Microsoft.DotNet.HotReload.Agent.projitems" Label="Shared" />
<Import Project="..\HotReloadAgent.Data\Microsoft.DotNet.HotReload.Agent.Data.projitems" Label="Shared" />
<Import Project="..\HotReloadAgent.PipeRpc\Microsoft.DotNet.HotReload.Agent.PipeRpc.projitems" Label="Shared" />

<PropertyGroup>
<!--
dotnet-watch may inject this assembly to .NET 6.0+ app.
Expand All @@ -13,26 +8,19 @@
-->
<TargetFrameworks>net6.0;net10.0</TargetFrameworks>
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>

<!-- NuGet -->
<IsPackable>true</IsPackable>
<IsShipping>true</IsShipping>
<IsShippingPackage>true</IsShippingPackage>
<PackageId>Microsoft.DotNet.HotReload.Agent.Host</PackageId>
<PackageDescription>Package containing Hot Reload agent host.</PackageDescription>
<DisableTransitiveFrameworkReferenceDownloads Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</DisableTransitiveFrameworkReferenceDownloads>
</PropertyGroup>

<!-- Reference 6.0.0 targeting packs in Source Build -->
<ItemGroup Condition="'$(DotNetBuildSourceOnly)' == 'true' and '$(TargetFramework)' == 'net6.0'">
<FrameworkReference Update="Microsoft.NETCore.App" TargetingPackVersion="6.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\dotnet-watch\Utilities\ProcessUtilities.cs" Link="ProcessUtilities.cs" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Microsoft.Extensions.DotNetDeltaApplier.Tests" />
</ItemGroup>

<Import Project="..\HotReloadAgent\Microsoft.DotNet.HotReload.Agent.projitems" Label="Shared" />
<Import Project="..\HotReloadAgent.Data\Microsoft.DotNet.HotReload.Agent.Data.projitems" Label="Shared" />
<Import Project="..\HotReloadAgent.Host\Microsoft.DotNet.HotReload.Agent.Host.projitems" Label="Shared" />
<Import Project="..\HotReloadAgent.PipeRpc\Microsoft.DotNet.HotReload.Agent.PipeRpc.projitems" Label="Shared" />
</Project>
6 changes: 6 additions & 0 deletions src/BuiltInTools/HotReloadAgent.Host/.editorconfig
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!--
This code may be injected into a .NET 6.0+ app.

When updating these also update ProjectReferences in dotnet-watch.csproj
and HotReloadAppModel.TryGetStartupHookPath.
-->
<TargetFrameworks>net6.0;net10.0</TargetFrameworks>
<DisableTransitiveFrameworkReferenceDownloads Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</DisableTransitiveFrameworkReferenceDownloads>

<GenerateDocumentationFile>false</GenerateDocumentationFile>
<DebugType>none</DebugType>
<GenerateDependencyFile>false</GenerateDependencyFile>
<LangVersion>preview</LangVersion>

<!-- NuGet -->
<IsPackable>true</IsPackable>
<IsShipping>true</IsShipping>
<IsSourcePackage>true</IsSourcePackage>
<PackageId>Microsoft.DotNet.HotReload.Agent.Host</PackageId>
<IncludeBuildOutput>false</IncludeBuildOutput>
<PackageDescription>Package containing Hot Reload agent host.</PackageDescription>
<!-- Remove once https://github.com/NuGet/Home/issues/8583 is fixed -->
<NoWarn>$(NoWarn);NU5128</NoWarn>
</PropertyGroup>

<!-- Reference 6.0.0 targeting packs in Source Build -->
<ItemGroup Condition="'$(DotNetBuildSourceOnly)' == 'true' and '$(TargetFramework)' == 'net6.0'">
<FrameworkReference Update="Microsoft.NETCore.App" TargetingPackVersion="6.0.0" />
</ItemGroup>

<Import Project="..\HotReloadAgent\Microsoft.DotNet.HotReload.Agent.projitems" Label="Shared" />
<Import Project="..\HotReloadAgent.Data\Microsoft.DotNet.HotReload.Agent.Data.projitems" Label="Shared" />
<Import Project="..\HotReloadAgent.PipeRpc\Microsoft.DotNet.HotReload.Agent.PipeRpc.projitems" Label="Shared" />

<!-- Make sure the shared source files do not require any global usings -->
<ItemGroup>
<Using Remove="@(Using)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>15C936B2-901D-4A27-AFA6-89CF56F5EB20</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Microsoft.DotNet.HotReload</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)**\*.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>15C936B2-901D-4A27-AFA6-89CF56F5EB20</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Microsoft.DotNet.HotReload.Agent.Host.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// The runtime startup hook looks for top-level type named "StartupHook".
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️‍🔥 I had no idea that a P/Invoke could be a local function.

}
else
{
Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/BuiltInTools/Web.Middleware/.editorconfig
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!--
This source code may be loaded by a .NET 6.0+ web server.
When updating the TFM also update minimal supported version in dotnet-watch.csproj and WebApplicationAppModel.cs.
-->
<TargetFrameworks>net6.0</TargetFrameworks>
<DisableTransitiveFrameworkReferenceDownloads Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</DisableTransitiveFrameworkReferenceDownloads>

<GenerateDocumentationFile>false</GenerateDocumentationFile>
<DebugType>none</DebugType>
<GenerateDependencyFile>false</GenerateDependencyFile>
<LangVersion>preview</LangVersion>

<!-- NuGet -->
<IsPackable>true</IsPackable>
<IsShipping>true</IsShipping>
<IsSourcePackage>true</IsSourcePackage>
<PackageId>Microsoft.DotNet.HotReload.Web.Middleware</PackageId>
<IncludeBuildOutput>false</IncludeBuildOutput>
<PackageDescription>Package containing web server middleware to support Hot Reload.</PackageDescription>
<!-- Remove once https://github.com/NuGet/Home/issues/8583 is fixed -->
<NoWarn>$(NoWarn);NU5128</NoWarn>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup Condition="'$(DotNetBuildSourceOnly)' == 'true'">
<!-- Reference 6.0 targeting packs in Source Build -->
<FrameworkReference Update="Microsoft.AspNetCore.App" TargetingPackVersion="6.0.2" />
<FrameworkReference Update="Microsoft.NETCore.App" TargetingPackVersion="6.0.0" />
</ItemGroup>

<!-- Make sure the shared source files do not require any global usings -->
<ItemGroup>
<Using Remove="@(Using)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>9F3A6169-66C9-4244-8FC6-222E4D6F8D29</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Microsoft.DotNet.HotReload</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)**\*.cs" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)**\*.js" />
</ItemGroup>
</Project>
Loading