コード例 #1
0
        private RuntimeFramework SelectRuntimeFrameworkInner(TestPackage package)
        {
            foreach (var subPackage in package.SubPackages)
            {
                SelectRuntimeFrameworkInner(subPackage);
            }

            // Examine the provided settings
            RuntimeFramework currentFramework = RuntimeFramework.CurrentFramework;

            log.Debug("Current framework is " + currentFramework);

            string requestedFrameworkSetting = package.GetSetting(EnginePackageSettings.RuntimeFramework, "");

            if (requestedFrameworkSetting.Length > 0)
            {
                RuntimeFramework requestedFramework;
                if (!RuntimeFramework.TryParse(requestedFrameworkSetting, out requestedFramework))
                {
                    throw new NUnitEngineException("Invalid or unknown framework requested: " + requestedFrameworkSetting);
                }

                log.Debug($"Requested framework for {package.Name} is {requestedFramework}");

                if (!IsAvailable(requestedFramework))
                {
                    throw new NUnitEngineException("Requested framework is not available: " + requestedFrameworkSetting);
                }

                return(requestedFramework);
            }

            log.Debug($"No specific framework requested for {package.Name}");

            string imageTargetFrameworkNameSetting = package.GetSetting(InternalEnginePackageSettings.ImageTargetFrameworkName, "");

            RuntimeFramework targetFramework;

            // HACK: handling the TargetFrameworkName does not currently work outside of windows
            if (Environment.OSVersion.Platform == PlatformID.Win32NT && imageTargetFrameworkNameSetting.Length > 0)
            {
                targetFramework = RuntimeFramework.FromFrameworkName(imageTargetFrameworkNameSetting);

                // TODO: temporary exception thrown until we implement .NET Core
                if (targetFramework.Runtime == Runtime.NetCore)
                {
                    throw new NotImplementedException("The GUI does not yet support .NET Core tests");
                }
            }
            else
            {
                var targetVersion = package.GetSetting(InternalEnginePackageSettings.ImageRuntimeVersion, currentFramework.FrameworkVersion);
                targetFramework = new RuntimeFramework(currentFramework.Runtime, targetVersion);
            }

            if (!IsAvailable(targetFramework))
            {
                log.Debug("Preferred target framework {0} is not available.", targetFramework);
                if (currentFramework.Supports(targetFramework))
                {
                    targetFramework = currentFramework;
                    log.Debug($"Using {currentFramework}");
                }
            }

            package.Settings[EnginePackageSettings.RuntimeFramework] = targetFramework.ToString();

            log.Debug($"Test will use {targetFramework} for {package.Name}");
            return(targetFramework);
        }