Skip to content

Commit 4030c23

Browse files
authored
Generalize project system interactions to CPS (#717)
We can share behavior across all CPS projects for handling files additions/removals. CPS is much more efficient for bulk edits - they work from the file system automatically, so we don't have to do batched edits on the UI thread in VS. This is something we should take advantage of for as many project types as possible, not limited to DotNetCoreWeb. Addresses #710
1 parent 0234c50 commit 4030c23

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/LibraryManager.Vsix/Constants.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ internal static class Constants
1414
public const string ErrorCodeLink = "https://github.com/aspnet/LibraryManager/wiki/Error-codes#{0}";
1515
public const string WAP = "{349C5851-65DF-11DA-9384-00065B846F21}";
1616
public const string WebsiteProject = "{E24C65DC-7377-472B-9ABA-BC803B73C61A}";
17+
/// <summary>
18+
/// Project capability for .NET web projects. Used only for UI context rules.
19+
/// </summary>
1720
public const string DotNetCoreWebCapability = "DotNetCoreWeb";
21+
/// <summary>
22+
/// Project capability for CPS-based projects. Used to determine how to add/remove items to the project.
23+
/// </summary>
24+
public const string CpsCapability = "CPS";
1825
}
1926
}

src/LibraryManager.Vsix/Contracts/HostInteraction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public async Task<bool> DeleteFilesAsync (IEnumerable<string> relativeFilePaths,
8585

8686
//Delete from project
8787
Project project = VsHelpers.GetDTEProjectFromConfig(_configFilePath);
88-
bool isCoreProject = await VsHelpers.IsDotNetCoreWebProjectAsync(project);
88+
bool isCpsProject = await VsHelpers.IsCpsProject(project);
8989

90-
if (!isCoreProject)
90+
if (!isCpsProject)
9191
{
9292
var logAction = new Action<string, LogLevel>((message, level) => { Logger.Log(message, level); });
9393
bool deleteFromProject = await VsHelpers.DeleteFilesFromProjectAsync(project, absolutePaths, logAction, cancellationToken);

src/LibraryManager.Vsix/Shared/VsHelpers.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static async Task AddFileToProjectAsync(this Project project, string file
109109
{
110110
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
111111

112-
if (IsCapabilityMatch(project, Constants.DotNetCoreWebCapability))
112+
if (IsCapabilityMatch(project, Constants.CpsCapability))
113113
{
114114
return;
115115
}
@@ -140,7 +140,7 @@ public static async Task AddFilesToProjectAsync(Project project, IEnumerable<str
140140
{
141141
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
142142

143-
if (project == null || IsCapabilityMatch(project, Constants.DotNetCoreWebCapability))
143+
if (project == null || IsCapabilityMatch(project, Constants.CpsCapability))
144144
{
145145
return;
146146
}
@@ -244,11 +244,14 @@ public static bool IsKind(this Project project, params string[] kindGuids)
244244
return false;
245245
}
246246

247-
public static async Task<bool> IsDotNetCoreWebProjectAsync(Project project)
247+
/// <summary>
248+
/// Returns whether the DTE project is a CPS-based project
249+
/// </summary>
250+
public static async Task<bool> IsCpsProject(Project project)
248251
{
249252
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
250253

251-
if (project == null || IsCapabilityMatch(project, Constants.DotNetCoreWebCapability))
254+
if (project == null || IsCapabilityMatch(project, Constants.CpsCapability))
252255
{
253256
return true;
254257
}

0 commit comments

Comments
 (0)