public PackageTargetFramework FindClosestTargetFramework(object inputTargetFramework) { var moniker = (inputTargetFramework ?? "").ToString().Trim().ToLowerInvariant(); var tf = TargetFrameworks.FirstOrDefault(x => x.Moniker == moniker); if (tf != null) { return(tf); } tf = TargetFrameworks.LastOrDefault(x => x.Moniker.StartsWith("netstandard2", StringComparison.Ordinal)); if (tf != null) { return(tf); } tf = TargetFrameworks.LastOrDefault(x => x.Moniker.StartsWith("netstandard", StringComparison.Ordinal)); if (tf != null) { return(tf); } tf = TargetFrameworks.LastOrDefault(x => x.Moniker.StartsWith("net", StringComparison.Ordinal)); if (tf != null) { return(tf); } if (tf == null) { tf = TargetFrameworks.FirstOrDefault(); } return(tf); }
FilePath GetOutputDirectory(DotNetProjectConfiguration configuration) { string targetFramework = TargetFrameworks.FirstOrDefault(); FilePath outputDirectory = configuration.OutputDirectory; if (outputDirectory.IsAbsolute) { return(outputDirectory); } else if (outputDirectory == "./") { outputDirectory = Path.Combine("bin", configuration.Name); } return(Project.BaseDirectory.Combine(outputDirectory.ToString(), targetFramework)); }
async Task ReadAsync(HttpClient httpClient, string packageUri) { this.Client = httpClient; var entries = await ReadEntriesAsync(httpClient, packageUri); TargetFrameworks.Clear(); Content.Clear(); Tools.Clear(); Entry nuspecEntry = null; foreach (var e in entries.Where(x => Path.GetFileName(x.FullName) != "_._").OrderBy(x => x.FullName)) { var n = e.FullName; var isBuild = n.StartsWith("build/", StringComparison.InvariantCultureIgnoreCase); var isLib = n.StartsWith("lib/", StringComparison.InvariantCultureIgnoreCase); if ((isBuild || isLib) && (n.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) || n.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase) || n.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase))) { var parts = n.Split('/', StringSplitOptions.RemoveEmptyEntries); string tfm; if (parts.Length >= 3) { tfm = Uri.UnescapeDataString(parts[1].Trim().ToLowerInvariant()); } else { tfm = "net"; } var tf = TargetFrameworks.FirstOrDefault(x => x.Moniker == tfm); if (tf == null) { tf = new PackageTargetFramework(this, httpClient) { Moniker = tfm, }; TargetFrameworks.Add(tf); } if (n.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase)) { var docs = new PackageAssemblyXmlLanguageDocs(e); if (string.IsNullOrEmpty(docs.Error)) { // System.Console.WriteLine(docs.AssemblyName); if (!tf.AssemblyXmlDocs.TryGetValue(docs.AssemblyName, out var allLanguageDocs)) { allLanguageDocs = new PackageAssemblyXmlDocs(docs.AssemblyName); tf.AssemblyXmlDocs[docs.AssemblyName] = allLanguageDocs; } allLanguageDocs.AddLanguage(docs.LanguageCode, docs); } } else if (isBuild) { tf.BuildAssemblies.Add(new PackageAssembly(e, tf)); } else { tf.Assemblies.Add(new PackageAssembly(e, tf)); } } else if (n.EndsWith(".nuspec", StringComparison.InvariantCultureIgnoreCase)) { nuspecEntry = e; } else if (n.StartsWith("content/", StringComparison.InvariantCultureIgnoreCase)) { Content.Add(new PackageFile(e)); } else if (n.StartsWith("tools/", StringComparison.InvariantCultureIgnoreCase)) { Tools.Add(new PackageFile(e)); } else { // System.Console.WriteLine(e); } } if (nuspecEntry != null) { ReadNuspec(nuspecEntry); } TargetFrameworks.Sort((a, b) => string.Compare(a.Moniker, b.Moniker, StringComparison.Ordinal)); }
public PackageTargetFramework FindExactTargetFramework(string moniker) { return(TargetFrameworks.FirstOrDefault(x => x.Moniker == moniker)); }
void Read(MemoryStream bytes, HttpClient httpClient) { SizeInBytes = bytes.Length; Archive = new ZipArchive(bytes, ZipArchiveMode.Read); TargetFrameworks.Clear(); ZipArchiveEntry nuspecEntry = null; foreach (var e in Archive.Entries.Where(x => x.Name != "_._").OrderBy(x => x.FullName)) { var n = e.FullName; var isBuild = n.StartsWith("build/", StringComparison.InvariantCultureIgnoreCase); var isLib = n.StartsWith("lib/", StringComparison.InvariantCultureIgnoreCase); if ((isBuild || isLib) && (n.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) || n.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase) || n.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase))) { var parts = n.Split('/', StringSplitOptions.RemoveEmptyEntries); string tfm; if (parts.Length >= 3) { tfm = Uri.UnescapeDataString(parts[1].Trim().ToLowerInvariant()); } else { tfm = "net"; } var tf = TargetFrameworks.FirstOrDefault(x => x.Moniker == tfm); if (tf == null) { tf = new PackageTargetFramework(this, httpClient) { Moniker = tfm, }; TargetFrameworks.Add(tf); } if (n.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase)) { var docs = new PackageAssemblyXmlDocs(e); if (string.IsNullOrEmpty(docs.Error)) { // System.Console.WriteLine(docs.AssemblyName); tf.AssemblyXmlDocs[docs.AssemblyName] = docs; } } else if (isBuild) { tf.BuildAssemblies.Add(new PackageAssembly(e, tf)); } else { tf.Assemblies.Add(new PackageAssembly(e, tf)); } } else if (n.EndsWith(".nuspec", StringComparison.InvariantCultureIgnoreCase)) { nuspecEntry = e; } else if (n.StartsWith("content/", StringComparison.InvariantCultureIgnoreCase)) { Content.Add(new PackageFile(e)); } else if (n.StartsWith("tools/", StringComparison.InvariantCultureIgnoreCase)) { Tools.Add(new PackageFile(e)); } else { // System.Console.WriteLine(e); } } if (nuspecEntry != null) { ReadNuspec(nuspecEntry); } TargetFrameworks.Sort((a, b) => string.Compare(a.Moniker, b.Moniker, StringComparison.Ordinal)); }
public async Task <IUpdaterResult> ApplyAsync(IUpgradeContext context, ImmutableArray <IProject> inputs, CancellationToken token) { await Task.Yield(); #pragma warning disable CA1031 // Do not catch general exception types try { foreach (var project in inputs) { var filePath = project.FindFiles("Package.appxmanifest").FirstOrDefault(); if (string.IsNullOrEmpty(filePath)) { continue; } var doc = new XmlDocument(); doc.Load(filePath); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("def", "http://schemas.microsoft.com/appx/manifest/foundation/windows10"); nsmgr.AddNamespace("mp", "http://schemas.microsoft.com/appx/2014/phone/manifest"); nsmgr.AddNamespace("uap", "http://schemas.microsoft.com/appx/manifest/uap/windows10"); var root = doc.DocumentElement; var phoneIdentityElement = root.SelectSingleNode("mp:PhoneIdentity", nsmgr); if (phoneIdentityElement != null) { root.RemoveChild(phoneIdentityElement); } var appElement = (XmlElement)root.SelectSingleNode("def:Applications/def:Application[@Id]", nsmgr); appElement.SetAttribute("EntryPoint", "$targetentrypoint$"); var targetDevicesUniversalElement = (XmlElement)root.SelectSingleNode("def:Dependencies/def:TargetDeviceFamily[@Name='Windows.Universal']", nsmgr); var targetFramework = context.CurrentProject !.TargetFrameworks.FirstOrDefault(); if (targetFramework != null && targetFramework.PlatformVersion != null) { var platformVersion = new Version(targetFramework.PlatformVersion.Major == -1 ? 10 : targetFramework.PlatformVersion.Major, targetFramework.PlatformVersion.Minor == -1 ? 0 : targetFramework.PlatformVersion.Minor, targetFramework.PlatformVersion.Build == -1 ? 19041 : targetFramework.PlatformVersion.Build, targetFramework.PlatformVersion.Revision == -1 ? 0 : targetFramework.PlatformVersion.Revision); targetDevicesUniversalElement.SetAttribute("MaxVersionTested", platformVersion !.ToString()); } targetDevicesUniversalElement.SetAttribute("Name", "Windows.Desktop"); doc.Save(filePath); } } // Likely to fail while parsing xml if the format does not match the expected format. // Move on to the next step if it fails catch (Exception) { this._logger.LogError(ErrorMessage); return(new WindowsDesktopUpdaterResult( RuleID, RuleName: Id, FullDescription: Title, false, string.Empty, new List <string>())); } #pragma warning restore CA1031 // Do not catch general exception types return(new WindowsDesktopUpdaterResult( RuleID, RuleName: Id, FullDescription: Title, true, string.Empty, new List <string>())); }