public static IEnumerable<FrameworkName> SelectFrameworks(Runtime.Project project, IEnumerable<string> userSelection, FrameworkName fallbackFramework, out string errorMessage) { var specifiedFrameworks = userSelection.ToDictionary(f => f, FrameworkNameHelper.ParseFrameworkName); var projectFrameworks = new HashSet<FrameworkName>( project.GetTargetFrameworks() .Select(c => c.FrameworkName)); IEnumerable<FrameworkName> frameworks = null; if (projectFrameworks.Count > 0) { // Specified target frameworks have to be a subset of the project frameworks if (!ValidateFrameworks(projectFrameworks, specifiedFrameworks, out errorMessage)) { return null; } frameworks = specifiedFrameworks.Count > 0 ? specifiedFrameworks.Values : (IEnumerable<FrameworkName>)projectFrameworks; } else { frameworks = new[] { fallbackFramework }; } errorMessage = string.Empty; return frameworks; }
private void ApplyTargetFramework(XDocument xDoc, Runtime.Project project) { // Get the system.web element var systemWeb = GetOrAddElement(xDoc.Root, "system.web"); var httpRuntime = systemWeb.Element("httpRuntime"); // No httpRuntime element, so create it if (httpRuntime == null) { httpRuntime = new XElement("httpRuntime"); systemWeb.Add(httpRuntime); } // There is an httpRuntime element. The user may have already set this attribute... else if (httpRuntime.Attribute("targetFramework") != null) { // User already had a target framework, leave it alone return; } // Ok, now we have an httpRuntime element and we know we need to set thet targetFramework on it. var bestDnxVersion = project.GetTargetFrameworks() .Where(f => f.FrameworkName.Identifier.Equals(FrameworkNames.LongNames.Dnx)) .OrderByDescending(f => f.FrameworkName.Version) .Select(f => f.FrameworkName.Version) .FirstOrDefault(); if (bestDnxVersion != null) { httpRuntime.SetAttributeValue("targetFramework", bestDnxVersion.ToString()); } }