Exemplo n.º 1
0
        /// <summary>
        /// Validate if TargetFrameworkVersion in run settings has valid value.
        /// </summary>
        public static bool TryGetFrameworkXml(XPathNavigator runSettingsNavigator, out string frameworkXml)
        {
            frameworkXml = XmlUtilities.GetNodeXml(runSettingsNavigator, TargetFrameworkNodePath);

            if (frameworkXml == null)
            {
                return(true);
            }

            Func <string, bool> validator = (string xml) =>
            {
                if (Framework.FromString(xml) != null)
                {
                    // Allow TargetFrameworkMoniker values like .NETFramework,Version=v4.5, ".NETCoreApp,Version=v1.0
                    return(true);
                }

                var value = (FrameworkVersion)Enum.Parse(typeof(FrameworkVersion), xml, true);

                if (!Enum.IsDefined(typeof(FrameworkVersion), value) || value == FrameworkVersion.None)
                {
                    return(false);
                }

                return(true);
            };

            return(XmlUtilities.IsValidNodeXmlValue(frameworkXml, validator));
        }
Exemplo n.º 2
0
        public static bool TryGetPlatformXml(XPathNavigator runSettingsNavigator, out string platformXml)
        {
            platformXml = XmlUtilities.GetNodeXml(runSettingsNavigator, TargetPlatformNodePath);

            if (platformXml == null)
            {
                return(true);
            }

            Func <string, bool> validator = (string xml) =>
            {
                var value = (Architecture)Enum.Parse(typeof(Architecture), xml, true);

                if (!Enum.IsDefined(typeof(Architecture), value) || value == Architecture.Default || value == Architecture.AnyCPU)
                {
                    return(false);
                }

                return(true);
            };

            return(XmlUtilities.IsValidNodeXmlValue(platformXml, validator));
        }