コード例 #1
0
ファイル: VsClient.cs プロジェクト: yannduran/xunit.vsix
        private string GetDevEnvPath()
        {
            var version = new Version(_visualStudioVersion);

            if (version.Major >= 15)
            {
                return(VsSetup.GetDevEnv(version));
            }

            var varName  = "VS" + _visualStudioVersion.Replace(".", "") + "COMNTOOLS";
            var varValue = Environment.GetEnvironmentVariable(varName);

            if (string.IsNullOrEmpty(varValue) || !Directory.Exists(varValue))
            {
                throw new ArgumentException(string.Format("Visual Studio Version '{0}' path was not found in environment variable '{1}'.", _visualStudioVersion, varName));
            }

            // Path is like: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\..\IDE\devenv.exe
            // We need to move up one level and down to IDE for the final devenv path.
            var path = Path.GetFullPath(Path.Combine(varValue, @"..\IDE\devenv.exe"));

            if (!File.Exists(path))
            {
                throw new ArgumentException(string.Format("Visual Studio Version '{0}' executable was not found at the expected location '{1}' according to the environment variable '{2}'.", _visualStudioVersion, path, varName));
            }

            return(path);
        }
コード例 #2
0
ファイル: VsClient.cs プロジェクト: yannduran/xunit.vsix
        public async Task <RunSummary> RunAsync(VsixTestCase vsixTest, IMessageBus messageBus, ExceptionAggregator aggregator)
        {
            // We don't apply retry behavior when a debugger is attached, since that
            // typically means the developer is actually debugging a failing test.
#if !DEBUG
            if (Debugger.IsAttached)
            {
                return(await RunAsyncCore(vsixTest, messageBus, aggregator));
            }
#endif

            var bufferBus = new InterceptingMessageBus();
            var summary   = await RunAsyncCore(vsixTest, bufferBus, aggregator);

            var shouldRecycle = vsixTest.RecycleOnFailure.GetValueOrDefault();

            // Special case for MEF cache corruption, clear cache and restart the test.
            if (summary.Failed != 0 && (
                    (aggregator.HasExceptions && aggregator.ToException().GetType().FullName == "Microsoft.VisualStudio.ExtensibilityHosting.InvalidMEFCacheException") ||
                    (bufferBus.Messages.OfType <IFailureInformation>().Where(fail => fail.ExceptionTypes.Any(type => type == "Microsoft.VisualStudio.ExtensibilityHosting.InvalidMEFCacheException")).Any())
                    ))
            {
                shouldRecycle = true;
                try
                {
                    var path = VsSetup.GetComponentModelCachePath(_devEnvPath, new Version(_visualStudioVersion), _rootSuffix);
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path, true);
                    }
                }
                catch (IOException)
                {
                    s_tracer.TraceEvent(TraceEventType.Warning, 0, "Failed to clear MEF cache after a failed test caused by an InvalidMEFCacheException.");
                }
            }

            if (summary.Failed != 0 && shouldRecycle)
            {
                Recycle();
                aggregator.Clear();
                summary = await RunAsyncCore(vsixTest, messageBus, aggregator);
            }
            else
            {
                // Dispatch messages from the first run to actual bus.
                foreach (var msg in bufferBus.Messages)
                {
                    messageBus.QueueMessage(msg);
                }
            }

            return(summary);
        }