Пример #1
0
        private void CheckSourcesForCompatibility(
            Framework chosenFramework,
            Architecture chosenPlatform,
            Architecture defaultArchitecture,
            IDictionary <string, Architecture> sourcePlatforms,
            IDictionary <string, Framework> sourceFrameworks,
            IBaseTestEventsRegistrar registrar)
        {
            // Find compatible sources.
            var compatibleSources = InferRunSettingsHelper.FilterCompatibleSources(
                chosenPlatform,
                defaultArchitecture,
                chosenFramework,
                sourcePlatforms,
                sourceFrameworks,
                out var incompatibleSettingWarning);

            // Raise warnings for incompatible sources
            if (!string.IsNullOrEmpty(incompatibleSettingWarning))
            {
                EqtTrace.Warning(incompatibleSettingWarning);
                registrar?.LogWarning(incompatibleSettingWarning);
            }

            // Log compatible sources
            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("Compatible sources list : ");
                EqtTrace.Info(string.Join("\n", compatibleSources.ToArray()));
            }
        }
Пример #2
0
        private bool UpdateFramework(
            XmlDocument document,
            XPathNavigator navigator,
            IList <string> sources,
            IDictionary <string, Framework> sourceFrameworks,
            IBaseTestEventsRegistrar registrar,
            out Framework chosenFramework)
        {
            // Get framework from sources.
            var inferedFramework = inferHelper.AutoDetectFramework(sources, sourceFrameworks);

            // Get framework from runsettings.
            bool updateFramework = IsAutoFrameworkDetectRequired(navigator, out chosenFramework);

            // Update framework if required. For command line scenario update happens in
            // ArgumentProcessor.
            if (updateFramework)
            {
                InferRunSettingsHelper.UpdateTargetFramework(
                    document,
                    inferedFramework?.ToString(),
                    overwrite: true);
                chosenFramework = inferedFramework;
            }

            // Raise warnings for unsupported frameworks.
            if (Constants.DotNetFramework35.Equals(chosenFramework.Name))
            {
                EqtTrace.Warning("TestRequestManager.UpdateRunSettingsIfRequired: throw warning on /Framework:Framework35 option.");
                registrar.LogWarning(Resources.Framework35NotSupported);
            }

            return(updateFramework);
        }
        private bool UpdateRunSettingsIfRequired(string runsettingsXml, List <string> sources, IBaseTestEventsRegistrar registrar, out string updatedRunSettingsXml)
        {
            bool settingsUpdated = false;

            updatedRunSettingsXml = runsettingsXml;
            IDictionary <string, Architecture> sourcePlatforms  = new Dictionary <string, Architecture>();
            IDictionary <string, Framework>    sourceFrameworks = new Dictionary <string, Framework>();

            if (!string.IsNullOrEmpty(runsettingsXml))
            {
                // TargetFramework is full CLR. Set DesignMode based on current context.
                using (var stream = new StringReader(runsettingsXml))
                    using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings))
                    {
                        var document = new XmlDocument();
                        document.Load(reader);
                        var navigator         = document.CreateNavigator();
                        var runConfiguration  = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml);
                        var loggerRunSettings = XmlRunSettingsUtilities.GetLoggerRunSettings(runsettingsXml) ?? new LoggerRunSettings();

                        settingsUpdated |= this.UpdateFramework(document, navigator, sources, sourceFrameworks, registrar, out Framework chosenFramework);

                        // Choose default architecture based on the framework
                        // For .NET core, the default platform architecture should be based on the process.
                        // For a 64 bit process,
                        Architecture defaultArchitecture = Architecture.X86;
                        if (chosenFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 ||
                            chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            var currentProcessName = this.processHelper.GetProcessName(this.processHelper.GetCurrentProcessId());
                            defaultArchitecture = (currentProcessName.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase) && !Environment.Is64BitProcess) ? Architecture.X86: Architecture.X64;
                        }

                        settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, defaultArchitecture, out Architecture chosenPlatform);
                        this.CheckSourcesForCompatibility(chosenFramework, chosenPlatform, sourcePlatforms, sourceFrameworks, registrar);
                        settingsUpdated |= this.UpdateDesignMode(document, runConfiguration);
                        settingsUpdated |= this.UpdateCollectSourceInformation(document, runConfiguration);
                        settingsUpdated |= this.UpdateTargetDevice(navigator, document, runConfiguration);
                        settingsUpdated |= this.AddOrUpdateConsoleLogger(document, runConfiguration, loggerRunSettings);

                        updatedRunSettingsXml = navigator.OuterXml;
                    }
            }

            return(settingsUpdated);
        }
Пример #4
0
        private bool UpdateRunSettingsIfRequired(string runsettingsXml, List <string> sources, IBaseTestEventsRegistrar registrar, out string updatedRunSettingsXml)
        {
            bool settingsUpdated = false;

            updatedRunSettingsXml = runsettingsXml;
            IDictionary <string, Architecture> sourcePlatforms  = new Dictionary <string, Architecture>();
            IDictionary <string, Framework>    sourceFrameworks = new Dictionary <string, Framework>();

            if (!string.IsNullOrEmpty(runsettingsXml))
            {
                // TargetFramework is full CLR. Set DesignMode based on current context.
                using (var stream = new StringReader(runsettingsXml))
                    using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings))
                    {
                        var document = new XmlDocument();
                        document.Load(reader);
                        var navigator         = document.CreateNavigator();
                        var runConfiguration  = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml);
                        var loggerRunSettings = XmlRunSettingsUtilities.GetLoggerRunSettings(runsettingsXml) ?? new LoggerRunSettings();

                        settingsUpdated |= this.UpdateFramework(document, navigator, sources, sourceFrameworks, registrar, out Framework chosenFramework);
                        settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, out Architecture chosenPlatform);
                        this.CheckSourcesForCompatibility(chosenFramework, chosenPlatform, sourcePlatforms, sourceFrameworks, registrar);
                        settingsUpdated |= this.UpdateDesignMode(document, runConfiguration);
                        settingsUpdated |= this.UpdateCollectSourceInformation(document, runConfiguration);
                        settingsUpdated |= this.UpdateTargetDevice(navigator, document, runConfiguration);
                        settingsUpdated |= this.AddOrUpdateConsoleLogger(document, runConfiguration, loggerRunSettings);

                        updatedRunSettingsXml = navigator.OuterXml;
                    }
            }

            return(settingsUpdated);
        }
Пример #5
0
        private bool UpdateRunSettingsIfRequired(
            string runsettingsXml,
            IList <string> sources,
            IBaseTestEventsRegistrar registrar,
            out string updatedRunSettingsXml)
        {
            bool settingsUpdated = false;

            updatedRunSettingsXml = runsettingsXml;
            var sourcePlatforms  = new Dictionary <string, Architecture>();
            var sourceFrameworks = new Dictionary <string, Framework>();

            if (!string.IsNullOrEmpty(runsettingsXml))
            {
                // TargetFramework is full CLR. Set DesignMode based on current context.
                using (var stream = new StringReader(runsettingsXml))
                    using (var reader = XmlReader.Create(
                               stream,
                               XmlRunSettingsUtilities.ReaderSettings))
                    {
                        var document = new XmlDocument();
                        document.Load(reader);
                        var navigator         = document.CreateNavigator();
                        var runConfiguration  = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml);
                        var loggerRunSettings = XmlRunSettingsUtilities.GetLoggerRunSettings(runsettingsXml)
                                                ?? new LoggerRunSettings();

                        settingsUpdated |= this.UpdateFramework(
                            document,
                            navigator,
                            sources,
                            sourceFrameworks,
                            registrar,
                            out Framework chosenFramework);

                        // Choose default architecture based on the framework.
                        // For .NET core, the default platform architecture should be based on the process.
                        Architecture defaultArchitecture = Architecture.X86;
                        if (chosenFramework.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 ||
                            chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0 ||
                            chosenFramework.Name.IndexOf("net5", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
#if NETCOREAPP
                            // We are running in vstest.console that is either started via dotnet.exe
                            // or via vstest.console.exe .NET Core executable. For AnyCPU dlls this
                            // should resolve 32-bit SDK when running from 32-bit dotnet process and
                            // 64-bit SDK when running from 64-bit dotnet process.
                            defaultArchitecture = Environment.Is64BitProcess ? Architecture.X64 : Architecture.X86;
#else
                            // We are running in vstest.console.exe that was built against .NET
                            // Framework. This console prefers 32-bit because it needs to run as 32-bit
                            // to be compatible with QTAgent. It runs as 32-bit both under VS and in
                            // Developer console. Set the default architecture based on the OS
                            // architecture, to find 64-bit dotnet SDK when running AnyCPU dll on 64-bit
                            // system, and 32-bit SDK when running AnyCPU dll on 32-bit OS.
                            // We want to find 64-bit SDK because it is more likely to be installed.
                            defaultArchitecture = Environment.Is64BitOperatingSystem ? Architecture.X64 : Architecture.X86;
#endif
                        }

                        settingsUpdated |= this.UpdatePlatform(
                            document,
                            navigator,
                            sources,
                            sourcePlatforms,
                            defaultArchitecture,
                            out Architecture chosenPlatform);
                        this.CheckSourcesForCompatibility(
                            chosenFramework,
                            chosenPlatform,
                            defaultArchitecture,
                            sourcePlatforms,
                            sourceFrameworks,
                            registrar);
                        settingsUpdated |= this.UpdateDesignMode(document, runConfiguration);
                        settingsUpdated |= this.UpdateCollectSourceInformation(document, runConfiguration);
                        settingsUpdated |= this.UpdateTargetDevice(navigator, document, runConfiguration);
                        settingsUpdated |= this.AddOrUpdateConsoleLogger(document, runConfiguration, loggerRunSettings);

                        updatedRunSettingsXml = navigator.OuterXml;
                    }
            }

            return(settingsUpdated);
        }