Skip to content

Commit 80f889a

Browse files
tmatdrewnoakes
andauthored
Move HotReload types to Microsoft.VisualStudio.ProjectSystem.Managed (#9680)
* Move HotReload types to Microsoft.VisualStudio.ProjectSystem.Managed * Tests * Fix * Remove workaround * Update tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Mocks/IProjectHotReloadBuildManagerFactory.cs Co-authored-by: Drew Noakes <[email protected]> * Update tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Mocks/IProjectHotReloadLaunchProvider.cs Co-authored-by: Drew Noakes <[email protected]> * Fix --------- Co-authored-by: Drew Noakes <[email protected]>
1 parent 0a0e2ce commit 80f889a

File tree

71 files changed

+1570
-1449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1570
-1449
lines changed

Directory.Packages.props

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
<PropertyGroup>
77
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
8-
<VSDebuggerVersion>17.13.0-beta.25272.1</VSDebuggerVersion>
98
</PropertyGroup>
109

1110
<!--
@@ -45,8 +44,6 @@
4544
<PackageVersion Include="Microsoft.ServiceHub.Framework" Version="4.8.55" />
4645
<PackageVersion Include="Microsoft.VisualStudio.ComponentModelHost" Version="17.13.13-preview" />
4746
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.13.41" />
48-
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Contracts" Version="$(VSDebuggerVersion)" />
49-
<PackageVersion Include="Microsoft.VisualStudio.Debugger.UI.Interfaces" Version="$(VSDebuggerVersion)" />
5047
<PackageVersion Include="Microsoft.VisualStudio.Data.Core" Version="17.13.38047-preview.1" />
5148
<PackageVersion Include="Microsoft.VisualStudio.Data.Services" Version="17.13.38055-preview.1" />
5249
<PackageVersion Include="Microsoft.VisualStudio.DataDesign.Common" Version="17.13.38055-preview.1" />
@@ -110,7 +107,8 @@
110107
<PackageVersion Include="Microsoft.Build" Version="17.13.0-preview-24504-04" />
111108

112109
<!-- Hot Reload -->
113-
<PackageVersion Include="Microsoft.VisualStudio.HotReload.Components" Version="17.13.9-preview-0001" />
110+
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Contracts" Version="17.13.0-beta.25272.1" />
111+
<PackageVersion Include="Microsoft.VisualStudio.HotReload.Components" Version="18.0.138-preview-0001" />
114112

115113
<!-- 3rd party -->
116114
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />

eng/imports/VisualStudio.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
<!-- VS SDK -->
2727
<PackageReference Include="Microsoft.Internal.VisualStudio.Interop" />
2828
<PackageReference Include="Microsoft.VisualStudio.ComponentModelHost" />
29-
<PackageReference Include="Microsoft.VisualStudio.Debugger.Contracts" />
30-
<PackageReference Include="Microsoft.VisualStudio.Debugger.UI.Interfaces" />
3129
<PackageReference Include="Microsoft.VisualStudio.Interop" />
3230
<PackageReference Include="Microsoft.VisualStudio.ManagedInterfaces" />
3331
<PackageReference Include="Microsoft.VisualStudio.RpcContracts" />

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Microsoft.VisualStudio.ProjectSystem.Managed.VS.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
</ItemGroup>
2727

2828
<ItemGroup>
29-
<PackageReference Include="Microsoft.VisualStudio.HotReload.Components" />
3029
<PackageReference Include="Microsoft.VisualStudio.ProjectSystem.Query" />
3130
<PackageReference Include="Microsoft.VisualStudio.ProjectSystem.VS" />
3231
<PackageReference Include="IsExternalInit" PrivateAssets="all" />

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/LaunchProfilesDebugLaunchProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.
22

33
using Microsoft.VisualStudio.ProjectSystem.Debug;
4+
using Microsoft.VisualStudio.ProjectSystem.HotReload;
45
using Microsoft.VisualStudio.Shell.Interop;
56
using Microsoft.VisualStudio.Threading;
67

@@ -13,9 +14,9 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Debug;
1314
/// Applies to projects having the <see cref="ProjectCapability.LaunchProfiles"/> capability.
1415
/// </remarks>
1516
[ExportDebugger(ProjectDebugger.SchemaName)]
16-
[Export(typeof(IInternalDebugLaunchProvider))]
17+
[Export(typeof(IProjectHotReloadLaunchProvider))]
1718
[AppliesTo(ProjectCapability.LaunchProfiles)]
18-
internal class LaunchProfilesDebugLaunchProvider : DebugLaunchProviderBase, IDeployedProjectItemMappingProvider, IStartupProjectProvider, IInternalDebugLaunchProvider
19+
internal class LaunchProfilesDebugLaunchProvider : DebugLaunchProviderBase, IDeployedProjectItemMappingProvider, IStartupProjectProvider, IProjectHotReloadLaunchProvider, IDebugLaunchProvider
1920
{
2021
private readonly IVsService<IVsDebuggerLaunchAsync> _vsDebuggerService;
2122
// Launch providers to enforce requirements for debuggable projects

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ProjectLaunchTargetsProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using Microsoft.VisualStudio.Debugger.UI.Interfaces.HotReload;
66
using Microsoft.VisualStudio.IO;
77
using Microsoft.VisualStudio.ProjectSystem.Debug;
8+
using Microsoft.VisualStudio.ProjectSystem.HotReload;
89
using Microsoft.VisualStudio.ProjectSystem.Properties;
910
using Microsoft.VisualStudio.ProjectSystem.Utilities;
10-
using Microsoft.VisualStudio.ProjectSystem.VS.HotReload;
1111
using Microsoft.VisualStudio.Shell.Interop;
1212
using Microsoft.VisualStudio.Threading;
1313
using Newtonsoft.Json;
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.
2+
3+
using Microsoft.VisualStudio.ProjectSystem.HotReload;
4+
using Microsoft.VisualStudio.Shell.Interop;
5+
6+
namespace Microsoft.VisualStudio.ProjectSystem.VS.HotReload;
7+
8+
[Export(typeof(IProjectHotReloadBuildManager))]
9+
[method: ImportingConstructor]
10+
internal sealed class ProjectHotReloadBuildManager(
11+
UnconfiguredProject project,
12+
IProjectThreadingService threadingService,
13+
IVsService<SVsSolutionBuildManager, IVsSolutionBuildManager2> solutionBuildManagerService) : IProjectHotReloadBuildManager
14+
{
15+
private IVsSolutionBuildManager2? _vsSolutionBuildManager2;
16+
17+
/// <summary>
18+
/// Build project and wait for the build to complete.
19+
/// </summary>
20+
public async Task<bool> BuildProjectAsync(CancellationToken cancellationToken)
21+
{
22+
Assumes.NotNull(project.Services.HostObject);
23+
_vsSolutionBuildManager2 ??= await solutionBuildManagerService.GetValueAsync(cancellationToken);
24+
25+
if (threadingService.JoinableTaskContext.IsMainThreadBlocked())
26+
{
27+
throw new InvalidOperationException("This task cannot be blocked on by the UI thread.");
28+
}
29+
30+
// Step 1: Register sbm events
31+
using var solutionBuildCompleteListener = new SolutionBuildCompleteListener();
32+
Verify.HResult(_vsSolutionBuildManager2.AdviseUpdateSolutionEvents(solutionBuildCompleteListener, out uint cookie));
33+
try
34+
{
35+
// Step 2: Build
36+
var projectVsHierarchy = (IVsHierarchy)project.Services.HostObject;
37+
38+
var result = _vsSolutionBuildManager2.StartSimpleUpdateProjectConfiguration(
39+
pIVsHierarchyToBuild: projectVsHierarchy,
40+
pIVsHierarchyDependent: null,
41+
pszDependentConfigurationCanonicalName: null,
42+
dwFlags: (uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD,
43+
dwDefQueryResults: (uint)VSSOLNBUILDQUERYRESULTS.VSSBQR_SAVEBEFOREBUILD_QUERY_YES,
44+
fSuppressUI: 0);
45+
46+
ErrorHandler.ThrowOnFailure(result);
47+
48+
// Step 3: Wait for the build to complete
49+
return await solutionBuildCompleteListener.WaitForSolutionBuildCompletedAsync(cancellationToken);
50+
}
51+
finally
52+
{
53+
_vsSolutionBuildManager2.UnadviseUpdateSolutionEvents(cookie);
54+
}
55+
}
56+
57+
private class SolutionBuildCompleteListener : IVsUpdateSolutionEvents, IDisposable
58+
{
59+
private readonly TaskCompletionSource<bool> _buildCompletedSource = new();
60+
61+
public SolutionBuildCompleteListener()
62+
{
63+
}
64+
65+
public int UpdateSolution_Begin(ref int pfCancelUpdate)
66+
{
67+
return HResult.OK;
68+
}
69+
70+
public int UpdateSolution_Done(int fSucceeded, int fModified, int fCancelCommand)
71+
{
72+
_buildCompletedSource.TrySetResult(fSucceeded != 0);
73+
74+
return HResult.OK;
75+
}
76+
77+
public int UpdateSolution_StartUpdate(ref int pfCancelUpdate)
78+
{
79+
return HResult.OK;
80+
}
81+
82+
public int UpdateSolution_Cancel()
83+
{
84+
_buildCompletedSource.TrySetCanceled();
85+
86+
return HResult.OK;
87+
}
88+
89+
public int OnActiveProjectCfgChange(IVsHierarchy pIVsHierarchy)
90+
{
91+
return HResult.OK;
92+
}
93+
94+
public async Task<bool> WaitForSolutionBuildCompletedAsync(CancellationToken ct = default)
95+
{
96+
using var _ = ct.Register(() =>
97+
{
98+
_buildCompletedSource.TrySetCanceled();
99+
});
100+
101+
try
102+
{
103+
return await _buildCompletedSource.Task;
104+
}
105+
catch (TaskCanceledException)
106+
{
107+
return false;
108+
}
109+
}
110+
111+
public void Dispose()
112+
{
113+
_buildCompletedSource.TrySetCanceled();
114+
}
115+
}
116+
}

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/TypeForwards.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@
1212
[assembly: TypeForwardedTo(destination: typeof(Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies.IProjectDependenciesSubTreeProvider))]
1313
[assembly: TypeForwardedTo(destination: typeof(Microsoft.VisualStudio.ProjectSystem.VS.Tree.IFileIconProvider))]
1414

15-
#pragma warning restore RS0016
15+
[assembly: TypeForwardedTo(typeof(Microsoft.VisualStudio.ProjectSystem.VS.HotReload.IProjectHotReloadAgent))]
16+
[assembly: TypeForwardedTo(typeof(Microsoft.VisualStudio.ProjectSystem.VS.HotReload.IProjectHotReloadNotificationService))]
17+
[assembly: TypeForwardedTo(typeof(Microsoft.VisualStudio.ProjectSystem.VS.HotReload.IProjectHotReloadSession))]
18+
[assembly: TypeForwardedTo(typeof(Microsoft.VisualStudio.ProjectSystem.VS.HotReload.IProjectHotReloadSessionCallback))]
19+
[assembly: TypeForwardedTo(typeof(Microsoft.VisualStudio.ProjectSystem.VS.HotReload.IProjectHotReloadUpdateApplier))]
20+
21+
#pragma warning restore RS0016

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/VSResources.Designer.cs

Lines changed: 0 additions & 145 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)