Example #1
0
        /// <summary>
        /// Get the unit tests extensions
        /// </summary>
        private IEnumerable <string> GetTestExtensionsInternal(string extensionType)
        {
            IEnumerable <string> installedExtensions = new List <string>();

            // Navigate up to the IDE folder
            // In case of xcopyable vstest.console, this functionality is not supported.
            var installContext = new InstallationContext(this.fileHelper);

            if (!installContext.TryGetVisualStudioDirectory(out string vsInstallPath))
            {
                throw new TestPlatformException(string.Format(CultureInfo.CurrentCulture, Resources.VSInstallationNotFound));
            }

            // Adding resolution paths for resolving dependencies.
            var resolutionPaths = installContext.GetVisualStudioCommonLocations(vsInstallPath);

            using (var assemblyResolver = new AssemblyResolver(resolutionPaths))
            {
                object extensionManager;
                object settingsManager;

                settingsManager = SettingsManagerType.GetMethod("CreateForApplication", new Type[] { typeof(String) }).Invoke(null, new object[] { installContext.GetVisualStudioPath(vsInstallPath) });
                if (settingsManager != null)
                {
                    try
                    {
                        // create extension manager
                        extensionManager = Activator.CreateInstance(ExtensionManagerServiceType, settingsManager);

                        if (extensionManager != null)
                        {
                            installedExtensions = ExtensionManagerServiceType.GetMethod("GetEnabledExtensionContentLocations", new Type[] { typeof(String) }).Invoke(
                                extensionManager, new object[] { extensionType }) as IEnumerable <string>;
                        }
                        else
                        {
                            if (EqtTrace.IsWarningEnabled)
                            {
                                EqtTrace.Warning("VSExtensionManager : Unable to create extension manager");
                            }
                        }
                    }
                    finally
                    {
                        // Dispose the settings manager
                        IDisposable disposable = (settingsManager as IDisposable);
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                else
                {
                    if (EqtTrace.IsWarningEnabled)
                    {
                        EqtTrace.Warning("VSExtensionManager : Unable to create settings manager");
                    }
                }
            }

            return(installedExtensions);
        }
Example #2
0
        /// <summary>
        /// Get the unit tests extensions
        /// </summary>
        private IEnumerable <string> GetTestExtensionsInternal(string extensionType)
        {
            IEnumerable <string> installedExtensions = new List <string>();

            // Navigate up to the IDE folder
            // In case of xcopyable vstest.console, this functionality is not supported.
            var    vsInstallPath = new DirectoryInfo(typeof(ITestPlatform).GetTypeInfo().Assembly.GetAssemblyLocation()).Parent?.Parent?.Parent?.FullName;
            string pathToDevenv  = null;

            if (!string.IsNullOrEmpty(vsInstallPath))
            {
                pathToDevenv = Path.Combine(vsInstallPath, DevenvExe);
            }

            if (string.IsNullOrEmpty(pathToDevenv) || !this.fileHelper.Exists(pathToDevenv))
            {
                throw new TestPlatformException(string.Format(CultureInfo.CurrentCulture, Resources.VSInstallationNotFound));
            }

            // Adding resolution paths for resolving dependencies.
            var resolutionPaths = new string[] {
                vsInstallPath,
                Path.Combine(vsInstallPath, PrivateAssembliesDirName),
                Path.Combine(vsInstallPath, PublicAssembliesDirName)
            };

            using (var assemblyResolver = new AssemblyResolver(resolutionPaths))
            {
                object extensionManager;
                object settingsManager;

                settingsManager = SettingsManagerType.GetMethod("CreateForApplication", new Type[] { typeof(String) }).Invoke(null, new object[] { pathToDevenv });
                if (settingsManager != null)
                {
                    try
                    {
                        // create extension manager
                        extensionManager = Activator.CreateInstance(ExtensionManagerServiceType, settingsManager);

                        if (extensionManager != null)
                        {
                            installedExtensions = ExtensionManagerServiceType.GetMethod("GetEnabledExtensionContentLocations", new Type[] { typeof(String) }).Invoke(
                                extensionManager, new object[] { extensionType }) as IEnumerable <string>;
                        }
                        else
                        {
                            if (EqtTrace.IsWarningEnabled)
                            {
                                EqtTrace.Warning("VSExtensionManager : Unable to create extension manager");
                            }
                        }
                    }
                    finally
                    {
                        // Dispose the settings manager
                        IDisposable disposable = (settingsManager as IDisposable);
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                else
                {
                    if (EqtTrace.IsWarningEnabled)
                    {
                        EqtTrace.Warning("VSExtensionManager : Unable to create settings manager");
                    }
                }
            }

            return(installedExtensions);
        }