Skip to content

Commit

Permalink
Added VS 2022 support and fixed VS 2017 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkDaskin committed Feb 13, 2022
1 parent dc8419d commit 3d84584
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 279 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Improvement suggestions are welcome.

## Compatibility

The extension currently works with Visual Studio 2017 - 2019. Support for other versions might be added in future.
The extension currently works with Visual Studio 2017 - 2022. Support for other versions might be added in future.

The extension is compatible with the [Custom Document Well](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.CustomDocumentWell) extension (a component of [Productivity Power Tools 2017](https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ProductivityPowerPack2017)).
The extension is compatible with the [Custom Document Well](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.CustomDocumentWell) extension (a component of [Productivity Power Tools 2017](https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ProductivityPowerPack2017)).

## Building

The extension references few assemblies directly from Visual Studio directory, so Visual Studio 2017 has to be installed to build it. No specific work loads are required.

In case you need to build the extension having only newer version of Visual Studio installed, override the `MinimumVisualStudioVersion` project property (see *VisualStudio.props* for possible values). This will make the extension incompatible with earlier Visual Studio versions.
20 changes: 20 additions & 0 deletions VSTabPath.Interop.Contracts/DteInteropResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Reflection;

namespace VSTabPath.Interop.Contracts
{
// Since VS 17.0, many interop types were moved to different assemblies, so code interacting with them
// must have diferent references for different VS versions. Such code was moved to proxy assemblies.
public static class DteInteropResolver
{
public static IDteInterop Interop { get; }

static DteInteropResolver()
{
var assemblyName = Environment.Is64BitProcess ? "VSTabPath.Interop.X64" : "VSTabPath.Interop.X86";
var assembly = Assembly.Load(assemblyName);
var type = assembly.GetType("VSTabPath.Interop.DteInterop");
Interop = (IDteInterop)Activator.CreateInstance(type);
}
}
}
13 changes: 13 additions & 0 deletions VSTabPath.Interop.Contracts/IDteInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace VSTabPath.Interop.Contracts
{
public interface IDteInterop
{
string GetSolutionRootPath();

event Action SolutionOpened;
event Action<string> SolutionRenamed;
event Action SolutionClosed;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\VSTabPath\Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

</Project>
59 changes: 59 additions & 0 deletions VSTabPath.Interop.Shared/DteInterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.IO;
using System.Linq;
using VSTabPath.Interop.Contracts;

namespace VSTabPath.Interop
{
// ReSharper disable once UnusedMember.Global
public class DteInterop : IDteInterop
{
private readonly DTE2 _dte;

public DteInterop()
{
_dte = (DTE2)Package.GetGlobalService(typeof(SDTE));
}

public string GetSolutionRootPath()
{
ThreadHelper.ThrowIfNotOnUIThread();

var solution = _dte.Solution;
if (solution == null)
return null;

var fullName = solution.FullName;
if (string.IsNullOrEmpty(fullName))
{
// A project has been opened without a solution, so a temporary one is created.
// Use the project root path instead.
fullName = solution.Projects.Cast<Project>().FirstOrDefault()?.FullName;
}

return string.IsNullOrEmpty(fullName) ? null : Path.GetDirectoryName(fullName);
}

public event Action SolutionOpened
{
add => _dte.Events.SolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(value);
remove => _dte.Events.SolutionEvents.Opened -= new _dispSolutionEvents_OpenedEventHandler(value);
}

public event Action<string> SolutionRenamed
{
add => _dte.Events.SolutionEvents.Renamed += new _dispSolutionEvents_RenamedEventHandler(value);
remove => _dte.Events.SolutionEvents.Renamed -= new _dispSolutionEvents_RenamedEventHandler(value);
}

public event Action SolutionClosed
{
add => _dte.Events.SolutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(value);
remove => _dte.Events.SolutionEvents.AfterClosing -= new _dispSolutionEvents_AfterClosingEventHandler(value);
}
}
}
14 changes: 14 additions & 0 deletions VSTabPath.Interop.Shared/VSTabPath.Interop.Shared.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>064a5ff7-b156-4165-9594-9867f5a5d382</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>VSTabPath.Interop</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)DteInterop.cs" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions VSTabPath.Interop.Shared/VSTabPath.Interop.Shared.shproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>064a5ff7-b156-4165-9594-9867f5a5d382</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="VSTabPath.Interop.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
18 changes: 18 additions & 0 deletions VSTabPath.Interop.X64/VSTabPath.Interop.X64.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EnvDTE80" Version="17.0.32112.339" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="17.0.32112.339" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\VSTabPath.Interop.Contracts\VSTabPath.Interop.Contracts.csproj" />
</ItemGroup>

<Import Project="..\VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.projitems" Label="Shared" />

</Project>
18 changes: 18 additions & 0 deletions VSTabPath.Interop.X86/VSTabPath.Interop.X86.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EnvDTE80" Version="8.0.3" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="15.0.26606" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\VSTabPath.Interop.Contracts\VSTabPath.Interop.Contracts.csproj" />
</ItemGroup>

<Import Project="..\VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.projitems" Label="Shared" />

</Project>
37 changes: 35 additions & 2 deletions VSTabPath.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29009.5
# Visual Studio Version 17
VisualStudioVersion = 17.0.32126.317
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSTabPath", "VSTabPath\VSTabPath.csproj", "{E2F60519-D34F-4411-9AB7-7916FC004E9F}"
EndProject
Expand All @@ -12,7 +12,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSTabPath.Tests", "VSTabPath.Tests\VSTabPath.Tests.csproj", "{13611075-94B6-4EA9-B777-D56A83DB16D6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interop", "Interop", "{9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VSTabPath.Interop.Contracts", "VSTabPath.Interop.Contracts\VSTabPath.Interop.Contracts.csproj", "{9F749E75-5CC7-4358-9F65-E73DACCE9439}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VSTabPath.Interop.X86", "VSTabPath.Interop.X86\VSTabPath.Interop.X86.csproj", "{861326D9-89DA-48AA-95AE-B8D39F2C654F}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "VSTabPath.Interop.Shared", "VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.shproj", "{064A5FF7-B156-4165-9594-9867F5A5D382}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VSTabPath.Interop.X64", "VSTabPath.Interop.X64\VSTabPath.Interop.X64.csproj", "{ACD4939F-F3B4-4441-B140-BEFCBA0BE115}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.projitems*{064a5ff7-b156-4165-9594-9867f5a5d382}*SharedItemsImports = 13
VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.projitems*{861326d9-89da-48aa-95ae-b8d39f2c654f}*SharedItemsImports = 5
VSTabPath.Interop.Shared\VSTabPath.Interop.Shared.projitems*{acd4939f-f3b4-4441-b140-befcba0be115}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Expand All @@ -26,10 +41,28 @@ Global
{13611075-94B6-4EA9-B777-D56A83DB16D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13611075-94B6-4EA9-B777-D56A83DB16D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13611075-94B6-4EA9-B777-D56A83DB16D6}.Release|Any CPU.Build.0 = Release|Any CPU
{9F749E75-5CC7-4358-9F65-E73DACCE9439}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F749E75-5CC7-4358-9F65-E73DACCE9439}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F749E75-5CC7-4358-9F65-E73DACCE9439}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F749E75-5CC7-4358-9F65-E73DACCE9439}.Release|Any CPU.Build.0 = Release|Any CPU
{861326D9-89DA-48AA-95AE-B8D39F2C654F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{861326D9-89DA-48AA-95AE-B8D39F2C654F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{861326D9-89DA-48AA-95AE-B8D39F2C654F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{861326D9-89DA-48AA-95AE-B8D39F2C654F}.Release|Any CPU.Build.0 = Release|Any CPU
{ACD4939F-F3B4-4441-B140-BEFCBA0BE115}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACD4939F-F3B4-4441-B140-BEFCBA0BE115}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACD4939F-F3B4-4441-B140-BEFCBA0BE115}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACD4939F-F3B4-4441-B140-BEFCBA0BE115}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9F749E75-5CC7-4358-9F65-E73DACCE9439} = {9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}
{861326D9-89DA-48AA-95AE-B8D39F2C654F} = {9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}
{064A5FF7-B156-4165-9594-9867F5A5D382} = {9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}
{ACD4939F-F3B4-4441-B140-BEFCBA0BE115} = {9BDB0B29-A5FB-464E-A0C1-C4F39FF9FB89}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {73BC04EB-A8B6-4EF6-A137-3E4DC594D994}
EndGlobalSection
Expand Down
5 changes: 2 additions & 3 deletions VSTabPath/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -29,5 +28,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.2.0")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
10 changes: 5 additions & 5 deletions VSTabPath/TabPathPackage.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using Microsoft.VisualStudio.PlatformUI.Shell;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using Microsoft.VisualStudio.PlatformUI.Shell;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;

namespace VSTabPath
Expand All @@ -29,7 +29,7 @@ namespace VSTabPath
/// </para>
/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#110", "#112", "1.2.2", IconResourceID = 400)] // Info on this package for Help/About
[InstalledProductRegistration("#110", "#112", Vsix.Version, IconResourceID = 400)] // Info on this package for Help/About
[Guid(PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
[ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
Expand Down
Loading

0 comments on commit 3d84584

Please sign in to comment.