Skip to content

Commit ca8b8f1

Browse files
committed
Include AddExplicitInterfaceImplementation capability
1 parent ce90906 commit ca8b8f1

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

src/BuiltInTools/HotReloadClient/DefaultHotReloadClient.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,15 @@ async Task<ImmutableArray<string>> ConnectAsync()
7777
// When the client connects, the first payload it sends is the initialization payload which includes the apply capabilities.
7878

7979
var capabilities = (await ClientInitializationResponse.ReadAsync(_pipe, cancellationToken)).Capabilities;
80-
Logger.Log(LogEvents.Capabilities, capabilities);
80+
81+
var result = AddImplicitCapabilities(capabilities.Split(' '));
82+
83+
Logger.Log(LogEvents.Capabilities, string.Join(" ", result));
8184

8285
// fire and forget:
8386
_ = ListenForResponsesAsync(cancellationToken);
8487

85-
return [.. capabilities.Split(' ')];
88+
return result;
8689
}
8790
catch (Exception e) when (e is not OperationCanceledException)
8891
{

src/BuiltInTools/HotReloadClient/HotReloadClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ internal abstract class HotReloadClient(ILogger logger, ILogger agentLogger) : I
4141
internal Task PendingUpdates
4242
=> _pendingUpdates;
4343

44+
/// <summary>
45+
/// .NET Framework runtime does not support adding MethodImpl entries, therefore the capability is not in the baseline capability set.
46+
/// All other runtimes (.NET and Mono) support it and rather than servicing all of them we include the capability here.
47+
/// </summary>
48+
protected static ImmutableArray<string> AddImplicitCapabilities(IEnumerable<string> capabilities)
49+
=> [.. capabilities, "AddExplicitInterfaceImplementation"];
50+
4451
public abstract void ConfigureLaunchEnvironment(IDictionary<string, string> environmentBuilder);
4552

4653
/// <summary>

src/BuiltInTools/HotReloadClient/Web/WebAssemblyHotReloadClient.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,30 @@ internal sealed class WebAssemblyHotReloadClient(
4141

4242
private static ImmutableArray<string> GetUpdateCapabilities(ILogger logger, ImmutableArray<string> projectHotReloadCapabilities, Version projectTargetFrameworkVersion)
4343
{
44-
var capabilities = projectHotReloadCapabilities;
45-
46-
if (capabilities.IsEmpty)
47-
{
48-
logger.LogDebug("Using capabilities based on project target framework version: '{Version}'.", projectTargetFrameworkVersion);
49-
50-
capabilities = projectTargetFrameworkVersion.Major switch
44+
var capabilities = projectHotReloadCapabilities.IsEmpty
45+
? projectTargetFrameworkVersion.Major switch
5146
{
5247
9 => s_defaultCapabilities90,
5348
8 => s_defaultCapabilities80,
5449
7 => s_defaultCapabilities70,
5550
6 => s_defaultCapabilities60,
5651
_ => [],
57-
};
52+
}
53+
: projectHotReloadCapabilities;
54+
55+
if (capabilities is not [])
56+
{
57+
capabilities = AddImplicitCapabilities(capabilities);
58+
}
59+
60+
var capabilitiesStr = string.Join(", ", capabilities);
61+
if (projectHotReloadCapabilities.IsEmpty)
62+
{
63+
logger.LogDebug("Project specifies capabilities: {Capabilities}.", capabilitiesStr);
5864
}
5965
else
6066
{
61-
logger.LogDebug("Project specifies capabilities: '{Capabilities}'", string.Join(" ", capabilities));
67+
logger.LogDebug("Using capabilities based on project target framework version: '{Version}': {Capabilities}.", projectTargetFrameworkVersion, capabilitiesStr);
6268
}
6369

6470
return capabilities;

test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public static void Print()
6969
UpdateSourceFile(Path.Combine(dependencyDir, "Foo.cs"), newSrc);
7070

7171
await App.AssertOutputLineStartsWith("Changed!");
72+
73+
App.AssertOutputContains("dotnet watch 🔥 Hot reload capabilities: AddExplicitInterfaceImplementation AddFieldRva AddInstanceFieldToExistingType AddMethodToExistingType AddStaticFieldToExistingType Baseline ChangeCustomAttributes GenericAddFieldToExistingType GenericAddMethodToExistingType GenericUpdateMethod NewTypeDefinition UpdateParameters.");
7274
}
7375

7476
[Fact]
@@ -892,11 +894,11 @@ public async Task BlazorWasm(bool projectSpecifiesCapabilities)
892894
// check project specified capapabilities:
893895
if (projectSpecifiesCapabilities)
894896
{
895-
App.AssertOutputContains("dotnet watch 🔥 Hot reload capabilities: Baseline AddMethodToExistingType.");
897+
App.AssertOutputContains("dotnet watch 🔥 Hot reload capabilities: AddExplicitInterfaceImplementation AddMethodToExistingType Baseline.");
896898
}
897899
else
898900
{
899-
App.AssertOutputContains("dotnet watch 🔥 Hot reload capabilities: Baseline AddMethodToExistingType AddStaticFieldToExistingType NewTypeDefinition ChangeCustomAttributes AddInstanceFieldToExistingType GenericAddMethodToExistingType GenericUpdateMethod UpdateParameters GenericAddFieldToExistingType.");
901+
App.AssertOutputContains("dotnet watch 🔥 Hot reload capabilities: AddExplicitInterfaceImplementation AddFieldRva AddInstanceFieldToExistingType AddMethodToExistingType AddStaticFieldToExistingType Baseline ChangeCustomAttributes GenericAddFieldToExistingType GenericAddMethodToExistingType GenericUpdateMethod NewTypeDefinition UpdateParameters.");
900902
}
901903
}
902904

@@ -963,10 +965,10 @@ public async Task BlazorWasmHosted()
963965
App.AssertOutputContains(MessageDescriptor.ApplicationKind_BlazorHosted);
964966

965967
// client capabilities:
966-
App.AssertOutputContains($"dotnet watch ⌚ [blazorhosted ({tfm})] Project 'blazorwasm ({tfm})' specifies capabilities: 'Baseline AddMethodToExistingType AddStaticFieldToExistingType NewTypeDefinition ChangeCustomAttributes AddInstanceFieldToExistingType GenericAddMethodToExistingType GenericUpdateMethod UpdateParameters GenericAddFieldToExistingType'");
968+
App.AssertOutputContains($"dotnet watch ⌚ [blazorhosted ({tfm})] Project specifies capabilities: Baseline AddMethodToExistingType AddStaticFieldToExistingType NewTypeDefinition ChangeCustomAttributes AddInstanceFieldToExistingType GenericAddMethodToExistingType GenericUpdateMethod UpdateParameters GenericAddFieldToExistingType AddExplicitInterfaceImplementation.");
967969

968970
// server capabilities:
969-
App.AssertOutputContains($"dotnet watch ⌚ [blazorhosted ({tfm})] Capabilities: 'Baseline AddMethodToExistingType AddStaticFieldToExistingType AddInstanceFieldToExistingType NewTypeDefinition ChangeCustomAttributes UpdateParameters GenericUpdateMethod GenericAddMethodToExistingType GenericAddFieldToExistingType AddFieldRva'");
971+
App.AssertOutputContains($"dotnet watch ⌚ [blazorhosted ({tfm})] Capabilities: Baseline AddMethodToExistingType AddStaticFieldToExistingType AddInstanceFieldToExistingType NewTypeDefinition ChangeCustomAttributes UpdateParameters GenericUpdateMethod GenericAddMethodToExistingType GenericAddFieldToExistingType AddFieldRva AddExplicitInterfaceImplementation.");
970972
}
971973

972974
[PlatformSpecificFact(TestPlatforms.Windows)] // https://github.com/dotnet/aspnetcore/issues/63759

0 commit comments

Comments
 (0)