diff options
author | Miguel Costa <miguel.costa@qt.io> | 2018-12-13 15:33:36 +0100 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2018-12-19 14:41:20 +0000 |
commit | 432b21365b778822f14842be711b0e64332a6e93 (patch) | |
tree | 571ecf333b895b88f17bb1987fed33a575a217ea | |
parent | ea8c574be2ecc6e4b46fafa43aad46bb013f54bf (diff) |
Use alternative method to locate VS installation
Will now use the IVsShell interface to locate the Visual Studio
installation folder. Previously, this was done by checking registry keys
that pointed to the location. This method is, however, not very well
documented. Also, as of VS 2019 version 16.0.0 Preview 1.1, the required
registry information is no longer available.
Change-Id: Id85bdbc4cf091f51722f5e05b76a0e9f89f54e39
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
-rw-r--r-- | src/qtprojectlib/HelperFunctions.cs | 17 | ||||
-rw-r--r-- | src/qtvstools/QtVsTools.csproj | 1 | ||||
-rw-r--r-- | src/qtvstools/VisualStudio/VsShell.cs | 61 | ||||
-rw-r--r-- | src/qtvstools/Vsix.cs | 5 |
4 files changed, 82 insertions, 2 deletions
diff --git a/src/qtprojectlib/HelperFunctions.cs b/src/qtprojectlib/HelperFunctions.cs index 9f5880df..48f6d87a 100644 --- a/src/qtprojectlib/HelperFunctions.cs +++ b/src/qtprojectlib/HelperFunctions.cs @@ -1651,7 +1651,20 @@ namespace QtProjectLib return versionWin10SDK; } - private static string GetVCPath() + static string _VCPath; + public static string VCPath + { + set { _VCPath = value; } + get + { + if (!string.IsNullOrEmpty(_VCPath)) + return _VCPath; + else + return GetVCPathFromRegistry(); + } + } + + private static string GetVCPathFromRegistry() { #if VS2017 string vsPath = GetRegistrySoftwareString(@"Microsoft\VisualStudio\SxS\VS7", "15.0"); @@ -1676,7 +1689,7 @@ namespace QtProjectLib bool isQt64Bit = QtVersionManager.The().GetVersionInfo( QtVersionManager.The().GetDefaultVersion()).is64Bit(); - string vcPath = GetVCPath(); + string vcPath = VCPath; if (vcPath == "") return false; diff --git a/src/qtvstools/QtVsTools.csproj b/src/qtvstools/QtVsTools.csproj index 86756cfc..46aa7d6f 100644 --- a/src/qtvstools/QtVsTools.csproj +++ b/src/qtvstools/QtVsTools.csproj @@ -157,6 +157,7 @@ <Compile Include="SR.cs" /> <Compile Include="Translation.cs" /> <Compile Include="TranslationItem.cs" /> + <Compile Include="VisualStudio\VsShell.cs" /> <Compile Include="Vsix.cs" /> <Compile Include="VSQtSettings.cs" /> <Compile Include="VsToolsDialogWindow.cs" /> diff --git a/src/qtvstools/VisualStudio/VsShell.cs b/src/qtvstools/VisualStudio/VsShell.cs new file mode 100644 index 00000000..453db700 --- /dev/null +++ b/src/qtvstools/VisualStudio/VsShell.cs @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt VS Tools. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +using Microsoft.VisualStudio; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.Shell.Interop; + +namespace QtVsTools.VisualStudio +{ + static class VsShell + { + public static string InstallRootDir + { + get + { + Initialize(); + return _InstallRootDir; + } + } + + private static IVsShell vsShell; + private static string _InstallRootDir; + + private static void Initialize() + { + if (vsShell != null) + return; + vsShell = Package.GetGlobalService(typeof(IVsShell)) as IVsShell; + + object objProp; + int res = vsShell.GetProperty((int)__VSSPROPID2.VSSPROPID_InstallRootDir, out objProp); + if (res == VSConstants.S_OK && objProp is string) + _InstallRootDir = objProp as string; + } + } +} diff --git a/src/qtvstools/Vsix.cs b/src/qtvstools/Vsix.cs index 1aecd180..cd7c90d5 100644 --- a/src/qtvstools/Vsix.cs +++ b/src/qtvstools/Vsix.cs @@ -39,6 +39,8 @@ using System.Windows.Forms; namespace QtVsTools { + using VisualStudio; + [Guid(PackageGuid)] [PackageRegistration(UseManagedResourcesOnly = true)] [InstalledProductRegistration("#110", "#112", Version.PRODUCT_VERSION, IconResourceID = 400)] @@ -124,6 +126,9 @@ namespace QtVsTools Dte = (this as IServiceProvider).GetService(typeof(DTE)) as DTE; + if (!string.IsNullOrEmpty(VsShell.InstallRootDir)) + HelperFunctions.VCPath = Path.Combine(VsShell.InstallRootDir, "VC"); + // determine the package installation directory var uri = new Uri(System.Reflection.Assembly .GetExecutingAssembly().EscapedCodeBase); |