Skip to content

Commit 403e861

Browse files
committed
Dynamic Visual Studio DLL handling: Reorganize Projects
1 parent f1eb39f commit 403e861

25 files changed

+152
-183
lines changed

ExtensionManager.sln

Lines changed: 93 additions & 93 deletions
Large diffs are not rendered by default.

src/ExtensionManager.VisualStudio.Shared/VSAdapterServicesFactoryGenerator.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44

55
using ExtensionManager.VisualStudio.Adapter.Generator;
66

7-
#if V15
8-
namespace ExtensionManager.VisualStudio.V15;
9-
#elif V16
10-
namespace ExtensionManager.VisualStudio.V16;
11-
#elif V17
12-
namespace ExtensionManager.VisualStudio.V17;
13-
#endif
7+
namespace ExtensionManager.VisualStudio;
148

159
internal sealed class VSAdapterServicesFactoryGenerator : VSAdapterServicesFactoryGeneratorBase
1610
{
@@ -21,12 +15,12 @@ public VSAdapterServicesFactoryGenerator(Version visualStudioVersion)
2115

2216
protected override string GetGalleryExtensionBaseTypeName()
2317
{
24-
#if V15 || V16
18+
#if VS2017 || VS2019
2519
return "GalleryOnlineExtension";
26-
#elif V17
20+
#elif VS2022
2721
return "OnlineExtensionBase";
2822
#else
29-
throw new NotImplementedException();
23+
#error Not implemented
3024
#endif
3125
}
3226

@@ -40,17 +34,17 @@ protected override IEnumerable<Assembly> LoadVisualStudioAssemblies()
4034

4135
private IEnumerable<string> GetVisualStudioAssemblyFilePaths(string devenvDirectory)
4236
{
43-
#if V15 || V16
37+
#if VS2017 || VS2019
4438
yield return @$"{devenvDirectory}Microsoft.VisualStudio.ExtensionEngine.dll";
4539
yield return @$"{devenvDirectory}PrivateAssemblies\Microsoft.VisualStudio.ExtensionManager.dll";
4640
yield return @$"{devenvDirectory}PrivateAssemblies\Microsoft.VisualStudio.ExtensionsExplorer.dll";
47-
#elif V17
41+
#elif VS2022
4842
yield return @$"{devenvDirectory}Microsoft.VisualStudio.ExtensionEngine.dll";
4943
yield return @$"{devenvDirectory}Microsoft.VisualStudio.ExtensionEngineContract.dll";
5044
yield return @$"{devenvDirectory}PrivateAssemblies\Microsoft.VisualStudio.ExtensionManager.dll";
5145
yield return @$"{devenvDirectory}PrivateAssemblies\Microsoft.VisualStudio.ExtensionsExplorer.dll";
5246
#else
53-
throw new NotImplementedException();
47+
#error Not implemented
5448
#endif
5549
}
5650
}

src/ExtensionManager.VisualStudio.Shared/VSServicesRegistrar.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
using Microsoft.Extensions.DependencyInjection;
1313

14-
#if V15
15-
namespace ExtensionManager.VisualStudio.V15;
16-
#elif V16
17-
namespace ExtensionManager.VisualStudio.V16;
18-
#elif V17
19-
namespace ExtensionManager.VisualStudio.V17;
14+
#if VS2017
15+
namespace ExtensionManager.VisualStudio.VS2017;
16+
#elif VS2019
17+
namespace ExtensionManager.VisualStudio.VS2019;
18+
#elif VS2022
19+
namespace ExtensionManager.VisualStudio.VS2022;
2020
#endif
2121

2222
public sealed class VSServicesRegistrar : IVSServicesRegistrar

src/ExtensionManager.VisualStudio.Shared/VisualStudioServices.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
using Microsoft.VisualStudio.Shell;
1212
using Microsoft.VisualStudio.Shell.Interop;
1313

14-
#if V15
15-
namespace ExtensionManager.VisualStudio.V15;
16-
#elif V16
17-
namespace ExtensionManager.VisualStudio.V16;
18-
#elif V17_5
19-
namespace ExtensionManager.VisualStudio.V17_5;
20-
#elif V17_7
21-
namespace ExtensionManager.VisualStudio.V17_7;
14+
#if VS2017
15+
namespace ExtensionManager.VisualStudio.VS2017;
16+
#elif VS2019
17+
namespace ExtensionManager.VisualStudio.VS2019;
18+
#elif VS2022
19+
namespace ExtensionManager.VisualStudio.VS2022;
2220
#endif
2321

2422
public sealed class VisualStudioServices : IVisualStudioServices

src/ExtensionManager.VisualStudio.V15/ExtensionManager.VisualStudio.V15.csproj renamed to src/ExtensionManager.VisualStudio.VS2017/ExtensionManager.VisualStudio.VS2017.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VsixTargetVersion>15</VsixTargetVersion>
4+
<VSVersion>2017</VSVersion>
55
</PropertyGroup>
66

77
<ItemGroup>
@@ -17,11 +17,6 @@
1717
</PackageReference>
1818
</ItemGroup>
1919

20-
<ItemGroup>
21-
<ProjectReference Include="..\ExtensionManager.VisualStudio.Adapter.Abstractions\ExtensionManager.VisualStudio.Adapter.Abstractions.csproj" />
22-
<ProjectReference Include="..\ExtensionManager.VisualStudio.Adapter.Generator\ExtensionManager.VisualStudio.Adapter.Generator.csproj" />
23-
</ItemGroup>
24-
2520
<Import Project="..\ExtensionManager.VisualStudio.Shared\ExtensionManager.VisualStudio.Shared.projitems" Label="Shared" />
2621
<Import Project="..\ExtensionManager.VisualStudio.props" />
2722

src/ExtensionManager.VisualStudio.V16/ExtensionManager.VisualStudio.V16.csproj renamed to src/ExtensionManager.VisualStudio.VS2019/ExtensionManager.VisualStudio.VS2019.csproj

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VsixTargetVersion>16</VsixTargetVersion>
4+
<VSVersion>2019</VSVersion>
55
</PropertyGroup>
66

77
<ItemGroup>
@@ -14,12 +14,7 @@
1414
<PrivateAssets>all</PrivateAssets>
1515
</PackageReference>
1616
</ItemGroup>
17-
18-
<ItemGroup>
19-
<ProjectReference Include="..\ExtensionManager.VisualStudio.Adapter.Abstractions\ExtensionManager.VisualStudio.Adapter.Abstractions.csproj" />
20-
<ProjectReference Include="..\ExtensionManager.VisualStudio.Adapter.Generator\ExtensionManager.VisualStudio.Adapter.Generator.csproj" />
21-
</ItemGroup>
22-
17+
2318
<Import Project="..\ExtensionManager.VisualStudio.Shared\ExtensionManager.VisualStudio.Shared.projitems" Label="Shared" />
2419
<Import Project="..\ExtensionManager.VisualStudio.props" />
2520

src/ExtensionManager.VisualStudio.V17/ExtensionManager.VisualStudio.V17.csproj renamed to src/ExtensionManager.VisualStudio.VS2022/ExtensionManager.VisualStudio.VS2022.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VsixTargetVersion>17</VsixTargetVersion>
4+
<VSVersion>2022</VSVersion>
55
</PropertyGroup>
66

77
<ItemGroup>
@@ -16,11 +16,6 @@
1616
</PackageReference>
1717
</ItemGroup>
1818

19-
<ItemGroup>
20-
<ProjectReference Include="..\ExtensionManager.VisualStudio.Adapter.Abstractions\ExtensionManager.VisualStudio.Adapter.Abstractions.csproj" />
21-
<ProjectReference Include="..\ExtensionManager.VisualStudio.Adapter.Generator\ExtensionManager.VisualStudio.Adapter.Generator.csproj" />
22-
</ItemGroup>
23-
2419
<Import Project="..\ExtensionManager.VisualStudio.Shared\ExtensionManager.VisualStudio.Shared.projitems" Label="Shared" />
2520
<Import Project="..\ExtensionManager.VisualStudio.props" />
2621

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
# ExtensionManager.VisualStudio
22

3-
These projects provide a facade around the Visual Studio API, enabling a simple solution for conflicts between DLLs of different Visual Studio versions.
3+
These projects provide a facade around the Visual Studio API, streamlining the handling of different dependency versions.
44

55
## Problems & Solutions
66

77
#### Version conflicts
88

9-
The preview version of Visual Studio internally uses modified implementations that are not compatible with the normal version.
10-
11-
To solve this problem, there are separate projects for each version that define divergent code, as well as a shared project that defines common code.
12-
In particular, retrieving data from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/) poses a challenge because it requires a `GalleryExtension` class,
13-
whose definition and content, however, differ.
9+
Different major versions of Visual Studio require specific dependencies that may not be compatible with each other.
10+
To manage this, separate projects are established for each Visual Studio version to specify their required dependency versions.
11+
A shared project is also maintained to house the common code applicable across all versions.
1412

1513
#### API Facade
1614

17-
To manage the majority of the code in regular SDK-style projects, direct usage of the Visual Studio API is not allowed,
18-
as different Visual Studio versions require different dependencies.
19-
20-
The solution is to use a facade that abstracts the entire Visual Studio API, allowing the majority of the code to only depend on this facade, not the concrete API.
15+
To simplify the codebase in SDK-style projects, direct interaction with the Visual Studio API is limited, due to the need for specific versions of dependencies across different Visual Studio versions.
2116

22-
The `VSFacade` class should be used in a similar manner as the `VS` class from [Community.VisualStudio.Toolkit](https://github.com/VsixCommunity/Community.VisualStudio.Toolkit),
23-
but it is extended with additional functions.
17+
An API facade abstracts away the complexity of the Visual Studio API, enabling the bulk of the code to interact with this facade rather than directly with varying versions of dependencies.
2418

2519
## Projects
2620

2721
| Project | Description |
2822
|---|---|
29-
| ExtensionManager.VisualStudio.Abstractions | Provides the abstraction for the facade and includes the `VSFacade` class |
30-
| ExtensionManager.VisualStudio.V15 | Divergent implementation and referenced DLLs for Visual Studio 2017 |
31-
| ExtensionManager.VisualStudio.V16 | Divergent implementation and referenced DLLs for Visual Studio 2019 |
32-
| ExtensionManager.VisualStudio.V17 | Divergent implementation and referenced DLLs for Visual Studio 2022 |
33-
| ExtensionManager.VisualStudio.Shared | Contains the shared code and the implementation of the `VSFacade` class. |
23+
| ExtensionManager.VisualStudio.Abstractions | Houses the facade abstraction |
24+
| ExtensionManager.VisualStudio.VS2017 | Specifies dependencies for projects targeting Visual Studio 2017 |
25+
| ExtensionManager.VisualStudio.VS2019 | Specifies dependencies for projects targeting Visual Studio 2019 |
26+
| ExtensionManager.VisualStudio.VS2022 | Specifies dependencies for projects targeting Visual Studio 2022 |
27+
| ExtensionManager.VisualStudio.Shared | Contains the implementation of the abstractions |

src/ExtensionManager.VisualStudio.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
<PropertyGroup>
44
<RootNamespace>ExtensionManager.VisualStudio</RootNamespace>
5-
<DefineConstants>$(DefineConstants);V$(VsixTargetVersion)</DefineConstants>
5+
<DefineConstants>$(DefineConstants);VS$(VSVersion)</DefineConstants>
66
</PropertyGroup>
77

88
<ItemGroup>
99
<ProjectReference Include="..\ExtensionManager.VisualStudio.Abstractions\ExtensionManager.VisualStudio.Abstractions.csproj" />
10+
<ProjectReference Include="..\ExtensionManager.VisualStudio.Adapter.Abstractions\ExtensionManager.VisualStudio.Adapter.Abstractions.csproj" />
11+
<ProjectReference Include="..\ExtensionManager.VisualStudio.Adapter.Generator\ExtensionManager.VisualStudio.Adapter.Generator.csproj" />
1012
</ItemGroup>
1113

1214
<ItemGroup>

src/ExtensionManager.Vsix.Shared/ExtensionManagerPackage.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
using System;
22
using System.ComponentModel.Design;
3-
using System.Diagnostics;
43
using System.Diagnostics.CodeAnalysis;
54
using System.IO;
65
using System.Reflection;
76
using System.Runtime.InteropServices;
87
using System.Threading;
9-
using System.Threading.Tasks;
108

119
using Community.VisualStudio.Toolkit;
1210

13-
using EnvDTE;
14-
1511
using ExtensionManager.Features.Export;
1612
using ExtensionManager.Features.Install;
1713
using ExtensionManager.UI;
@@ -64,14 +60,14 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
6460

6561
private static IVSServicesRegistrar CreateVSServiceFactory(Version vsVersion)
6662
{
67-
#if V17
68-
return new VisualStudio.V17.VSServicesRegistrar(vsVersion);
69-
#elif V16
70-
return new VisualStudio.V16.VSServicesRegistrar(vsVersion);
71-
#elif V15
72-
return new VisualStudio.V15.VSServicesRegistrar(vsVersion);
63+
#if VS2022
64+
return new VisualStudio.VS2022.VSServicesRegistrar(vsVersion);
65+
#elif VS2019
66+
return new VisualStudio.VS2019.VSServicesRegistrar(vsVersion);
67+
#elif VS2017
68+
return new VisualStudio.VS2017.VSServicesRegistrar(vsVersion);
7369
#else
74-
throw new InvalidOperationException("Not supported Visual Studio version");
70+
#error Not implemented
7571
#endif
7672
}
7773

0 commit comments

Comments
 (0)