Skip to content

Commit 48b878e

Browse files
committed
Fix: Error if "Solution Items" folder already existed
1 parent c525943 commit 48b878e

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/ExtensionManager.VisualStudio.Abstractions/Solution/IVSSolutionItem.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
namespace ExtensionManager.VisualStudio.Solution;
23

34
/// <summary>
@@ -14,4 +15,9 @@ public interface IVSSolutionItem
1415
/// The absolute file path on disk.
1516
/// </summary>
1617
string? FullPath { get; }
18+
19+
/// <summary>
20+
/// Gets the children of this solution item.
21+
/// </summary>
22+
Task<IReadOnlyList<IVSSolutionItem>> GetChildrenAsync();
1723
}

src/ExtensionManager.VisualStudio.Shared/Solution/VSSolutionItem.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
16
using CT = Community.VisualStudio.Toolkit;
7+
using ThreadHelper = Microsoft.VisualStudio.Shell.ThreadHelper;
28

39
#nullable enable
410

@@ -14,4 +20,20 @@ internal class VSSolutionItem<TItem> : IVSSolutionItem
1420

1521
protected VSSolutionItem(TItem inner)
1622
=> Inner = inner;
23+
24+
public async Task<IReadOnlyList<IVSSolutionItem>> GetChildrenAsync()
25+
{
26+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
27+
28+
return Inner.Children
29+
.Where(x => x is not null)
30+
.Select(x => (IVSSolutionItem)(x switch
31+
{
32+
CT.Solution solution => new VSSolution(solution),
33+
CT.SolutionFolder folder => new VSSolutionFolder(folder),
34+
CT.SolutionItem item => new VSSolutionItem<CT.SolutionItem>(item),
35+
_ => throw new NotImplementedException($"The solution item of type {x!.GetType()} is not supported"),
36+
}))
37+
.ToList();
38+
}
1739
}

src/ExtensionManager/Features/Export/ExportSolutionFeature.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ protected override async Task ShowExportDialogAsync(IManifest manifest, IExportW
2323

2424
protected override async Task OnManifestWrittenAsync(string filePath)
2525
{
26+
const string folderName = "Solution Items";
27+
2628
var solution = await _solutions.GetCurrentOrThrowAsync();
27-
var folder = await solution.AddSolutionFolderAsync("Solution Items");
29+
var solutionChildren = await solution.GetChildrenAsync();
30+
31+
var folder = solutionChildren.SingleOrDefault(x => x.Name == folderName) as IVSSolutionFolder
32+
?? await solution.AddSolutionFolderAsync(folderName);
2833

2934
if (folder is null)
3035
throw new InvalidOperationException("Could not add solution folder");

0 commit comments

Comments
 (0)