Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions GoogleTestAdapter/Packaging.GTA/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="GoogleTestAdapterVSIX.e57b9720-dfde-4baa-bcb5-0f75772012b4" Version="0.1.0.0" Language="en-US" Publisher="Christian Soltenborn, Jonas Gefele" />
<DisplayName>Google Test Adapter</DisplayName>
<Description xml:space="preserve">Adds support for the C++ unit testing framework Google Tests.</Description>
<MoreInfo>https://github.com/csoltenborn/GoogleTestAdapter</MoreInfo>
<License>LICENSE.txt</License>
<Icon>Resources\Icons\Icon.ico</Icon>
<PreviewImage>Resources\Preview.png</PreviewImage>
<Tags>Unit Test, C++, Google Test, GoogleTest, GTest, Test Explorer, Testing</Tags>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Version="11.0" Id="Microsoft.VisualStudio.Premium" />
<InstallationTarget Version="[11.0,15.0]" Id="Microsoft.VisualStudio.Pro" />
<InstallationTarget Version="[11.0,15.0]" Id="Microsoft.VisualStudio.Enterprise" />
<InstallationTarget Version="[11.0,15.0]" Id="Microsoft.VisualStudio.Ultimate" />
<InstallationTarget Version="[12.0,15.0]" Id="Microsoft.VisualStudio.Community" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,4.6]" />
<Dependency Id="Microsoft.VisualStudio.MPF.11.0" DisplayName="Visual Studio MPF 11.0" d:Source="Installed" Version="11.0" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="TestAdapter" Path="|TestAdapter|" />
<Asset Type="UnitTestExtension" d:Source="Project" d:ProjectName="TestAdapter" Path="|TestAdapter|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0.26004.1,16.0)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core" Version="[15.0.26004.1,16.0)" DisplayName="Visual Studio C++ core features" />
</Prerequisites>
<Metadata>
<Identity Id="GoogleTestAdapterVSIX.e57b9720-dfde-4baa-bcb5-0f75772012b4" Version="0.1.0.0" Language="en-US" Publisher="Christian Soltenborn" />
<DisplayName>Google Test Adapter</DisplayName>
<Description xml:space="preserve">Adds support for the C++ unit testing framework Google Tests.</Description>
<MoreInfo>https://github.com/csoltenborn/GoogleTestAdapter</MoreInfo>
<License>LICENSE.txt</License>
<Icon>Resources\Icons\Icon.ico</Icon>
<PreviewImage>Resources\Preview.png</PreviewImage>
<Tags>Unit Test, C++, Google Test, GoogleTest, GTest, Test Explorer, Testing</Tags>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Version="[12.0,17.0)" Id="Microsoft.VisualStudio.Pro" />
<InstallationTarget Version="[12.0,17.0)" Id="Microsoft.VisualStudio.Enterprise" />
<InstallationTarget Version="[12.0,17.0)" Id="Microsoft.VisualStudio.Ultimate" />
<InstallationTarget Version="[12.0,17.0)" Id="Microsoft.VisualStudio.Community" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,4.7]" />
<Dependency Id="Microsoft.VisualStudio.MPF.11.0" DisplayName="Visual Studio MPF 11.0" d:Source="Installed" Version="11.0" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="TestAdapter" Path="|TestAdapter|" />
<Asset Type="UnitTestExtension" d:Source="Project" d:ProjectName="TestAdapter" Path="|TestAdapter|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="VsPackage.GTA" Path="|VsPackage.GTA|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0.26004.1,17.0)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core" Version="[15.0.26004.1,17.0)" DisplayName="Visual Studio C++ core features" />
</Prerequisites>
</PackageManifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
//------------------------------------------------------------------------------
// <copyright file="PackageRegistrationAttribute.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace Microsoft.VisualStudio.AsyncPackageHelpers {

using System;
using System.Globalization;
using System.IO;
using System.ComponentModel;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

/// <devdoc>
/// This attribute is defined on a package to get it to be registered. It
/// is internal because packages are meant to be registered, so it is
/// implicit just by having a package in the assembly.
/// </devdoc>
[AttributeUsage(AttributeTargets.Class, Inherited=true, AllowMultiple=false)]
public sealed class AsyncPackageRegistrationAttribute : RegistrationAttribute
{
private RegistrationMethod registrationMethod = RegistrationMethod.Default;
private bool useManagedResources = false;
private bool allowsBackgroundLoad = false;
private string satellitePath = null;

/// <devdoc>
/// Select between specifying the Codebase entry or the Assembly entry in the registry.
/// This can be overriden during registration
/// </devdoc>
public RegistrationMethod RegisterUsing
{
get
{
return registrationMethod;
}
set
{
registrationMethod = value;
}
}

/// <summary>
/// For managed resources, there should not be a native ui dll registered.
/// </summary>
public bool UseManagedResourcesOnly
{
get { return useManagedResources; }
set { useManagedResources = value; }
}

/// <summary>
/// Package is safe to load on a background thread.
/// </summary>
public bool AllowsBackgroundLoading
{
get { return allowsBackgroundLoad; }
set { allowsBackgroundLoad = value; }
}

/// <summary>
/// To specify a resource dll located in a different location then the default,
/// set this property. This can be useful if your package is installed in the GAC.
/// If this is not set, the directory where the package is located will be use.
///
/// Note that the dll should be located at the following path:
/// SatellitePath\lcid\PackageDllNameUI.dll
/// </summary>
public string SatellitePath
{
get { return satellitePath; }
set { satellitePath = value; }
}

private string RegKeyName(RegistrationContext context)
{
return String.Format(CultureInfo.InvariantCulture, "Packages\\{0}", context.ComponentType.GUID.ToString("B"));
}

/// <devdoc>
/// Called to register this attribute with the given context. The context
/// contains the location where the registration information should be placed.
/// it also contains such as the type being registered, and path information.
///
/// This method is called both for registration and unregistration. The difference is
/// that unregistering just uses a hive that reverses the changes applied to it.
/// </devdoc>
/// <param name="context">
/// Contains the location where the registration information should be placed.
/// It also contains other information such as the type being registered
/// and path of the assembly.
/// </param>
public override void Register(RegistrationContext context) {
Type t = context.ComponentType;

Key packageKey = null;
try
{
packageKey = context.CreateKey(RegKeyName(context));

//use a friendly description if it exists.
DescriptionAttribute attr = TypeDescriptor.GetAttributes(t)[typeof(DescriptionAttribute)] as DescriptionAttribute;
if (attr != null && !String.IsNullOrEmpty(attr.Description)) {
packageKey.SetValue(string.Empty, attr.Description);
}
else {
packageKey.SetValue(string.Empty, t.Name);
}

packageKey.SetValue("InprocServer32", context.InprocServerPath);
packageKey.SetValue("Class", t.FullName);

// If specified on the command line, let the command line option override
if (context.RegistrationMethod != RegistrationMethod.Default)
{
registrationMethod = context.RegistrationMethod;
}

// Select registration method
switch (registrationMethod)
{
case RegistrationMethod.Assembly:
case RegistrationMethod.Default:
packageKey.SetValue("Assembly", t.Assembly.FullName);
break;

case RegistrationMethod.CodeBase:
packageKey.SetValue("CodeBase", context.CodeBase);
break;
}

Key childKey = null;
if (!useManagedResources)
{
try
{
childKey = packageKey.CreateSubkey("SatelliteDll");

// Register the satellite dll
string satelliteDllPath;
if (SatellitePath != null)
{
// Use provided path
satelliteDllPath = context.EscapePath(SatellitePath);
}
else
{
// Default to package path
satelliteDllPath = context.ComponentPath;
}
childKey.SetValue("Path", satelliteDllPath);
childKey.SetValue("DllName", String.Format(CultureInfo.InvariantCulture, "{0}UI.dll", Path.GetFileNameWithoutExtension(t.Assembly.ManifestModule.Name)));
}
finally
{
if (childKey != null)
childKey.Close();
}
}

if (allowsBackgroundLoad)
{
packageKey.SetValue("AllowsBackgroundLoad", true);
}

if (typeof(IVsPackageDynamicToolOwner).IsAssignableFrom(context.ComponentType) ||
typeof(IVsPackageDynamicToolOwnerEx).IsAssignableFrom(context.ComponentType))
{
packageKey.SetValue("SupportsDynamicToolOwner", Microsoft.VisualStudio.PlatformUI.Boxes.BooleanTrue);
}
}
finally
{
if (packageKey != null)
packageKey.Close();
}
}

/// <devdoc>
/// Unregister this package.
/// </devdoc>
/// <param name="context"></param>
public override void Unregister(RegistrationContext context)
{
context.RemoveKey(RegKeyName(context));
}

}
}
48 changes: 48 additions & 0 deletions GoogleTestAdapter/VsPackage.GTA/AsyncPackage/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell.Interop;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Shell;

namespace Microsoft.VisualStudio.AsyncPackageHelpers
{
public static class ExtensionMethods
{
/// <summary>
/// Helper method to use async/await with IAsyncServiceProvider implementation
/// </summary>
/// <param name="asyncServiceProvider">IAsyncServciceProvider instance</param>
/// <param name="serviceType">Type of the Visual Studio service requested</param>
/// <returns>Service object as type of T</returns>
public static async Task<T> GetServiceAsync<T>(this IAsyncServiceProvider asyncServiceProvider, Type serviceType) where T : class
{
T returnValue = null;

await ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
object serviceInstance = null;
Guid serviceTypeGuid = serviceType.GUID;
serviceInstance = await asyncServiceProvider.QueryServiceAsync(ref serviceTypeGuid);

// We have to make sure we are on main UI thread before trying to cast as underlying implementation
// can be an STA COM object and doing a cast would require calling QueryInterface/AddRef marshaling
// to main thread via COM.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
returnValue = serviceInstance as T;
});

return returnValue;
}

/// <summary>
/// Gets if async package is supported in the current instance of Visual Studio
/// </summary>
/// <param name="serviceProvider">an IServiceProvider instance, usually a Package instance</param>
/// <returns>true if async packages are supported</returns>
public static bool IsAsyncPackageSupported(this IServiceProvider serviceProvider)
{
IAsyncServiceProvider asyncServiceProvider = serviceProvider.GetService(typeof(SAsyncServiceProvider)) as IAsyncServiceProvider;
return asyncServiceProvider != null;
}
}
}
Loading