Skip to content

Commit 05c1dad

Browse files
authored
Convert Middleware and Agent.Host packages to source packages (#51335)
1 parent 43f8f05 commit 05c1dad

26 files changed

+255
-61
lines changed

sdk.slnx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@
4949
<Project Path="src/BuiltInTools/DotNetWatchTasks/DotNetWatchTasks.csproj" />
5050
<Project Path="src/BuiltInTools/HotReloadAgent.Data/Microsoft.DotNet.HotReload.Agent.Data.Package.csproj" />
5151
<Project Path="src/BuiltInTools/HotReloadAgent.Data/Microsoft.DotNet.HotReload.Agent.Data.shproj" />
52+
<Project Path="src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.Package.csproj" />
53+
<Project Path="src/BuiltInTools/HotReloadAgent.Host/Microsoft.DotNet.HotReload.Agent.Host.shproj" />
5254
<Project Path="src/BuiltInTools/HotReloadAgent.PipeRpc/Microsoft.DotNet.HotReload.Agent.PipeRpc.Package.csproj" />
5355
<Project Path="src/BuiltInTools/HotReloadAgent.PipeRpc/Microsoft.DotNet.HotReload.Agent.PipeRpc.shproj" />
5456
<Project Path="src/BuiltInTools/HotReloadAgent.WebAssembly.Browser/Microsoft.DotNet.HotReload.WebAssembly.Browser.csproj" />
5557
<Project Path="src/BuiltInTools/HotReloadAgent/Microsoft.DotNet.HotReload.Agent.Package.csproj" />
5658
<Project Path="src/BuiltInTools/HotReloadAgent/Microsoft.DotNet.HotReload.Agent.shproj" />
5759
<Project Path="src/BuiltInTools/HotReloadClient/Microsoft.DotNet.HotReload.Client.Package.csproj" />
58-
<Project Path="src/BuiltInTools/HotReloadClient/Microsoft.DotNet.HotReload.Client.shproj" Id="a78ff92a-d715-4249-9e3d-40d9997a098f" />
60+
<Project Path="src/BuiltInTools/HotReloadClient/Microsoft.DotNet.HotReload.Client.shproj" />
61+
<Project Path="src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.Package.csproj" />
62+
<Project Path="src/BuiltInTools/Web.Middleware/Microsoft.DotNet.HotReload.Web.Middleware.shproj" />
5963
</Folder>
6064
<Folder Name="/src/Cli/">
6165
<Project Path="src/Cli/dotnet/dotnet.csproj" />

src/BuiltInTools/BrowserRefresh/.editorconfig

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/BuiltInTools/BrowserRefresh/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,13 @@
55
When updating the TFM also update minimal supported version in dotnet-watch.csproj and WebApplicationAppModel.cs.
66
-->
77
<TargetFramework>net6.0</TargetFramework>
8-
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
9-
10-
<!-- NuGet -->
11-
<IsPackable>true</IsPackable>
12-
<IsShipping>true</IsShipping>
13-
<IsShippingPackage>true</IsShippingPackage>
14-
<PackageId>Microsoft.DotNet.HotReload.Web.Middleware</PackageId>
15-
<PackageDescription>Package containing Hot Reload middleware.</PackageDescription>
168
<DisableTransitiveFrameworkReferenceDownloads Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</DisableTransitiveFrameworkReferenceDownloads>
9+
10+
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
1711
</PropertyGroup>
1812

1913
<ItemGroup>
2014
<FrameworkReference Include="Microsoft.AspNetCore.App" />
21-
<EmbeddedResource Include="WebSocketScriptInjection.js" />
22-
23-
<!-- Back compat only -->
24-
<EmbeddedResource Include="BlazorHotReload.js" />
2515
</ItemGroup>
2616

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

27+
<Import Project="..\Web.Middleware\Microsoft.DotNet.HotReload.Web.Middleware.projitems" Label="Shared" />
3728
</Project>
Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<Import Project="..\HotReloadAgent\Microsoft.DotNet.HotReload.Agent.projitems" Label="Shared" />
4-
<Import Project="..\HotReloadAgent.Data\Microsoft.DotNet.HotReload.Agent.Data.projitems" Label="Shared" />
5-
<Import Project="..\HotReloadAgent.PipeRpc\Microsoft.DotNet.HotReload.Agent.PipeRpc.projitems" Label="Shared" />
6-
72
<PropertyGroup>
83
<!--
94
dotnet-watch may inject this assembly to .NET 6.0+ app.
@@ -13,26 +8,19 @@
138
-->
149
<TargetFrameworks>net6.0;net10.0</TargetFrameworks>
1510
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
16-
17-
<!-- NuGet -->
18-
<IsPackable>true</IsPackable>
19-
<IsShipping>true</IsShipping>
20-
<IsShippingPackage>true</IsShippingPackage>
21-
<PackageId>Microsoft.DotNet.HotReload.Agent.Host</PackageId>
22-
<PackageDescription>Package containing Hot Reload agent host.</PackageDescription>
23-
<DisableTransitiveFrameworkReferenceDownloads Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</DisableTransitiveFrameworkReferenceDownloads>
2411
</PropertyGroup>
2512

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

3418
<ItemGroup>
3519
<InternalsVisibleTo Include="Microsoft.Extensions.DotNetDeltaApplier.Tests" />
3620
</ItemGroup>
3721

22+
<Import Project="..\HotReloadAgent\Microsoft.DotNet.HotReload.Agent.projitems" Label="Shared" />
23+
<Import Project="..\HotReloadAgent.Data\Microsoft.DotNet.HotReload.Agent.Data.projitems" Label="Shared" />
24+
<Import Project="..\HotReloadAgent.Host\Microsoft.DotNet.HotReload.Agent.Host.projitems" Label="Shared" />
25+
<Import Project="..\HotReloadAgent.PipeRpc\Microsoft.DotNet.HotReload.Agent.PipeRpc.projitems" Label="Shared" />
3826
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[*.cs]
2+
3+
# IDE0240: Remove redundant nullable directive
4+
# The directive needs to be included since all sources in a source package are considered generated code
5+
# when referenced from a project via package reference.
6+
dotnet_diagnostic.IDE0240.severity = none
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<!--
5+
This code may be injected into a .NET 6.0+ app.
6+
7+
When updating these also update ProjectReferences in dotnet-watch.csproj
8+
and HotReloadAppModel.TryGetStartupHookPath.
9+
-->
10+
<TargetFrameworks>net6.0;net10.0</TargetFrameworks>
11+
<DisableTransitiveFrameworkReferenceDownloads Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</DisableTransitiveFrameworkReferenceDownloads>
12+
13+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
14+
<DebugType>none</DebugType>
15+
<GenerateDependencyFile>false</GenerateDependencyFile>
16+
<LangVersion>preview</LangVersion>
17+
18+
<!-- NuGet -->
19+
<IsPackable>true</IsPackable>
20+
<IsShipping>true</IsShipping>
21+
<IsSourcePackage>true</IsSourcePackage>
22+
<PackageId>Microsoft.DotNet.HotReload.Agent.Host</PackageId>
23+
<IncludeBuildOutput>false</IncludeBuildOutput>
24+
<PackageDescription>Package containing Hot Reload agent host.</PackageDescription>
25+
<!-- Remove once https://github.com/NuGet/Home/issues/8583 is fixed -->
26+
<NoWarn>$(NoWarn);NU5128</NoWarn>
27+
</PropertyGroup>
28+
29+
<!-- Reference 6.0.0 targeting packs in Source Build -->
30+
<ItemGroup Condition="'$(DotNetBuildSourceOnly)' == 'true' and '$(TargetFramework)' == 'net6.0'">
31+
<FrameworkReference Update="Microsoft.NETCore.App" TargetingPackVersion="6.0.0" />
32+
</ItemGroup>
33+
34+
<Import Project="..\HotReloadAgent\Microsoft.DotNet.HotReload.Agent.projitems" Label="Shared" />
35+
<Import Project="..\HotReloadAgent.Data\Microsoft.DotNet.HotReload.Agent.Data.projitems" Label="Shared" />
36+
<Import Project="..\HotReloadAgent.PipeRpc\Microsoft.DotNet.HotReload.Agent.PipeRpc.projitems" Label="Shared" />
37+
38+
<!-- Make sure the shared source files do not require any global usings -->
39+
<ItemGroup>
40+
<Using Remove="@(Using)" />
41+
</ItemGroup>
42+
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
<HasSharedItems>true</HasSharedItems>
6+
<SharedGUID>15C936B2-901D-4A27-AFA6-89CF56F5EB20</SharedGUID>
7+
</PropertyGroup>
8+
<PropertyGroup Label="Configuration">
9+
<Import_RootNamespace>Microsoft.DotNet.HotReload</Import_RootNamespace>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<Compile Include="$(MSBuildThisFileDirectory)**\*.cs" />
13+
</ItemGroup>
14+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Label="Globals">
4+
<ProjectGuid>15C936B2-901D-4A27-AFA6-89CF56F5EB20</ProjectGuid>
5+
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
6+
</PropertyGroup>
7+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
8+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
9+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
10+
<PropertyGroup />
11+
<Import Project="Microsoft.DotNet.HotReload.Agent.Host.projitems" Label="Shared" />
12+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
13+
</Project>

src/BuiltInTools/DotNetDeltaApplier/PipeListener.cs renamed to src/BuiltInTools/HotReloadAgent.Host/PipeListener.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#nullable enable
5+
6+
using System;
47
using System.Diagnostics;
58
using System.IO.Pipes;
69
using System.Reflection;
710
using System.Runtime.Loader;
11+
using System.Threading;
12+
using System.Threading.Tasks;
813

914
namespace Microsoft.DotNet.HotReload;
1015

src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs renamed to src/BuiltInTools/HotReloadAgent.Host/StartupHook.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
#nullable enable
5+
6+
using System;
47
using System.Diagnostics;
8+
using System.IO;
59
using System.IO.Pipes;
10+
using System.Linq;
611
using System.Reflection;
12+
using System.Runtime.InteropServices;
713
using System.Runtime.Loader;
14+
using System.Threading;
15+
using System.Threading.Tasks;
816
using Microsoft.DotNet.HotReload;
9-
using Microsoft.DotNet.Watch;
1017

1118
/// <summary>
1219
/// The runtime startup hook looks for top-level type named "StartupHook".
@@ -92,7 +99,27 @@ private static void RegisterSignalHandlers()
9299
{
93100
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
94101
{
95-
ProcessUtilities.EnableWindowsCtrlCHandling(Log);
102+
// Enables handling of Ctrl+C in a process where it was disabled.
103+
//
104+
// If a process is launched with CREATE_NEW_PROCESS_GROUP flag
105+
// it allows the parent process to send Ctrl+C event to the child process,
106+
// but also disables Ctrl+C handlers.
107+
//
108+
// "If the HandlerRoutine parameter is NULL, a TRUE value causes the calling process to ignore CTRL+C input,
109+
// and a FALSE value restores normal processing of CTRL+C input.
110+
// This attribute of ignoring or processing CTRL+C is inherited by child processes."
111+
112+
if (SetConsoleCtrlHandler(null, false))
113+
{
114+
Log("Windows Ctrl+C handling enabled.");
115+
}
116+
else
117+
{
118+
Log($"Failed to enable Ctrl+C handling: {GetLastPInvokeErrorMessage()}");
119+
}
120+
121+
[DllImport("kernel32.dll", SetLastError = true)]
122+
static extern bool SetConsoleCtrlHandler(Delegate? handler, bool add);
96123
}
97124
else
98125
{
@@ -118,6 +145,16 @@ private static void RegisterSignalHandlers()
118145
}
119146
}
120147

148+
private static string GetLastPInvokeErrorMessage()
149+
{
150+
var error = Marshal.GetLastPInvokeError();
151+
#if NET10_0_OR_GREATER
152+
return $"{Marshal.GetPInvokeErrorMessage(error)} (code {error})";
153+
#else
154+
return $"error code {error}";
155+
#endif
156+
}
157+
121158
private static void Log(string message)
122159
{
123160
var prefix = s_standardOutputLogPrefix;

0 commit comments

Comments
 (0)