private string GetMostCompatibleItem(NuGetFramework framework, IEnumerable <FrameworkSpecificGroup> items, string mainFile) { var compatibleItems = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, items)?.Items; if (compatibleItems == null) { return(null); } if (mainFile != null) { var f = compatibleItems.FirstOrDefault(x => String.Equals(Path.GetFileName(x), mainFile, StringComparison.CurrentCultureIgnoreCase)); if (f != null) { return(f); } f = compatibleItems.FirstOrDefault(x => String.Equals(Path.GetFileName(x), mainFile + ".exe", StringComparison.CurrentCultureIgnoreCase)); if (f != null) { return(f); } f = compatibleItems.FirstOrDefault(x => String.Equals(Path.GetFileName(x), mainFile + ".dll", StringComparison.CurrentCultureIgnoreCase)); if (f != null) { return(f); } } return(compatibleItems.FirstOrDefault(x => Path.GetExtension(x) == ".dll")); }
private IEnumerable <string> GetFiles(NuGetFramework framework, IEnumerable <FrameworkSpecificGroup> libs, IEnumerable <FrameworkSpecificGroup> tools, IEnumerable <FrameworkSpecificGroup> buildFiles, IEnumerable <FrameworkSpecificGroup> runtimeFiles) { var result = new List <string>(); var items = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, libs)?.Items; if (items != null) { result.AddRange(items); } items = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, tools)?.Items; if (items != null) { result.AddRange(items); } items = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, buildFiles)?.Items; if (items != null) { result.AddRange(items); } items = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, runtimeFiles)?.Items; if (items != null) { result.AddRange(items); } return(result.Where(x => x.Substring(x.Length - 1) != "/")); }
public async Task DeleteFileSafeAsync_WithCancellationToken_ThrowsAsync() { await Assert.ThrowsAsync <OperationCanceledException>(async() => { await MSBuildNuGetProjectSystemUtility.DeleteFileSafeAsync( path: string.Empty, streamFactory: async() => await Task.FromResult(It.IsAny <Stream>()), projectSystem: It.IsAny <IMSBuildProjectSystem>(), cancellationToken: new CancellationToken(canceled: true)); }); }
private IDictionary <string, IEnumerable <string> > GetDeps(IEnumerable <NuGetFramework> frameworks, IEnumerable <FrameworkSpecificGroup> groups) { var result = new Dictionary <string, IEnumerable <string> >(); foreach (var framework in frameworks) { var deps = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, groups)?.Items?.Select(x => ToRefNet(x, framework))?.Where(y => y != null); if (deps != null) { result.Add(framework.GetShortFolderName(), deps); } } return(result); }
public WorkspaceEntry(PackageIdentity identity, string sha256, IEnumerable <PackageDependencyGroup> deps, IEnumerable <FrameworkSpecificGroup> libs, IEnumerable <FrameworkSpecificGroup> tools, IEnumerable <FrameworkSpecificGroup> references, string mainFile) { PackageIdentity = identity; Sha256 = sha256; var coreFramework = NuGetFramework.Parse("netcoreapp5.0"); var netFramework = NuGetFramework.Parse("net70"); var monoFramework = NuGetFramework.Parse("net70"); Core_Files = GetFiles(coreFramework, libs, tools); Net_Files = GetFiles(netFramework, libs, tools); Mono_Files = GetFiles(monoFramework, libs, tools); var depConverted = deps.Select(x => new FrameworkSpecificGroup(x.TargetFramework, x.Packages.Select(y => y.Id.ToLower()))); Core_Deps = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(coreFramework, depConverted)?.Items?.Select(x => ToRef(x, "core")); Net_Deps = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(netFramework, depConverted)?.Items?.Select(x => ToRef(x, "net")); Mono_Deps = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(monoFramework, depConverted)?.Items?.Select(x => ToRef(x, "mono")); CoreLib = GetMostCompatibleItem(coreFramework, references, mainFile); NetLib = GetMostCompatibleItem(netFramework, references, mainFile); MonoLib = GetMostCompatibleItem(monoFramework, references, mainFile); CoreTool = GetMostCompatibleItem(coreFramework, tools, mainFile); NetTool = GetMostCompatibleItem(netFramework, tools, mainFile); MonoTool = GetMostCompatibleItem(monoFramework, tools, mainFile); if (CoreLib == null) { CoreLib = Core_Files?.FirstOrDefault(x => Path.GetExtension(x) == ".dll"); } if (NetLib == null) { NetLib = Net_Files?.FirstOrDefault(x => Path.GetExtension(x) == ".dll"); } if (CoreLib == null) { CoreLib = NetLib; } if (MonoLib == null) { MonoLib = Mono_Files?.FirstOrDefault(x => Path.GetExtension(x) == ".dll"); } }
private IDictionary <string, IEnumerable <string> > GetDepsCore(IEnumerable <NuGetFramework> frameworks, IEnumerable <FrameworkSpecificGroup> groups, IDictionary <string, string> knownDependencies) { var result = new Dictionary <string, IEnumerable <string> >(); var knownDependenciesLower = knownDependencies.Keys.Select(x => x.ToLower()).ToList(); foreach (var framework in frameworks) { var rawDeps = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, groups)?.Items; var knownRawDeps = rawDeps?.Where(knownDependenciesLower.Contains); var deps = knownRawDeps?.Select(x => ToRefCore(x, framework))?.Where(y => y != null); if (deps != null) { result.Add(framework.GetShortFolderName(), deps); } } return(result); }
private IEnumerable <string> GetFiles(NuGetFramework framework, IEnumerable <FrameworkSpecificGroup> libs, IEnumerable <FrameworkSpecificGroup> tools) { var result = new List <string>(); var items = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, libs)?.Items; if (items != null) { result.AddRange(items); } items = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(framework, tools)?.Items; if (items != null) { result.AddRange(items); } return(result); }
public WorkspaceEntry(IDictionary <string, string> knownDependencies, PackageIdentity identity, string sha256, IEnumerable <PackageDependencyGroup> deps, IEnumerable <FrameworkSpecificGroup> libs, IEnumerable <FrameworkSpecificGroup> tools, IEnumerable <FrameworkSpecificGroup> references, IEnumerable <FrameworkSpecificGroup> buildFiles, IEnumerable <FrameworkSpecificGroup> runtimeFiles, string mainFile, string variable, bool nugetSourceCustom) { var netFrameworkTFMs = new string[] { "net45", "net451", "net452", "net46", "net461", "net462", "net47", "net471", "net472", "net48", "netstandard1.0", "netstandard1.1", "netstandard1.2", "netstandard1.3", "netstandard1.4", "netstandard1.5", "netstandard1.6", "netstandard2.0", "netstandard2.1", }; var coreFrameworkTFMs = new string[] { "netcoreapp2.0", "netcoreapp2.1", "netcoreapp3.0", "netcoreapp3.1", }; PackageIdentity = identity; Sha256 = sha256; Variable = variable; NugetSourceCustom = nugetSourceCustom; var coreFrameworks = coreFrameworkTFMs.Select(x => NuGetFramework.Parse(x)); var netFrameworks = netFrameworkTFMs.Select(x => NuGetFramework.Parse(x)); var monoFramework = NuGetFramework.Parse("net70"); Core_Files = GetFiles(coreFrameworks, libs, tools, buildFiles, runtimeFiles); Net_Files = GetFiles(netFrameworks, libs, tools, buildFiles, runtimeFiles); Mono_Files = GetFiles(monoFramework, libs, tools, buildFiles, runtimeFiles); var depConverted = deps.Select(x => new FrameworkSpecificGroup(x.TargetFramework, x.Packages.Select(y => y.Id.ToLower()))); Core_Deps = GetDepsCore(coreFrameworks, depConverted, knownDependencies); Net_Deps = GetDepsNet(netFrameworks, depConverted, knownDependencies); Mono_Deps = MSBuildNuGetProjectSystemUtility.GetMostCompatibleGroup(monoFramework, depConverted)?.Items?.Select(x => ToRefMono(x)); CoreLib = new Dictionary <string, string>(); foreach (var framework in coreFrameworks) { var lib = GetMostCompatibleItem(framework, libs, mainFile); if (!string.IsNullOrEmpty(lib)) { CoreLib.Add(framework.GetShortFolderName(), lib); } } CoreRef = new Dictionary <string, string>(); foreach (var framework in coreFrameworks) { var reflib = GetMostCompatibleItem(framework, references, mainFile); if (!string.IsNullOrEmpty(reflib)) { CoreRef.Add(framework.GetShortFolderName(), reflib); } } NetLib = new Dictionary <string, string>(); foreach (var framework in netFrameworks) { var lib = GetMostCompatibleItem(framework, libs, mainFile); if (!string.IsNullOrEmpty(lib)) { NetLib.Add(framework.GetShortFolderName(), lib); } } NetRef = new Dictionary <string, string>(); foreach (var framework in netFrameworks) { var reflib = GetMostCompatibleItem(framework, references, mainFile); if (!string.IsNullOrEmpty(reflib)) { NetRef.Add(framework.GetShortFolderName(), reflib); } } MonoLib = GetMostCompatibleItem(monoFramework, libs, mainFile); MonoRef = GetMostCompatibleItem(monoFramework, references, mainFile); CoreTool = new Dictionary <string, string>(); foreach (var framework in coreFrameworks) { var tool = GetMostCompatibleItem(framework, tools, mainFile); if (!string.IsNullOrEmpty(tool)) { CoreTool.Add(framework.GetShortFolderName(), tool); } } NetTool = new Dictionary <string, string>(); foreach (var framework in netFrameworks) { var tool = GetMostCompatibleItem(framework, tools, mainFile); if (!string.IsNullOrEmpty(tool)) { NetTool.Add(framework.GetShortFolderName(), tool); } } MonoTool = GetMostCompatibleItem(monoFramework, tools, mainFile); //if (NetLib == null || !NetLib.Any()) // NetLib = Net_Files?.ToDictionary(key => key.Key, val => val.Value.FirstOrDefault(z => Path.GetExtension(z) == ".dll")); //if (CoreLib == null || !CoreLib.Any()) // CoreLib = Core_Files?.ToDictionary(key => key.Key, val => val.Value.FirstOrDefault(z => Path.GetExtension(z) == ".dll")); //if (MonoLib == null) // MonoLib = Mono_Files?.FirstOrDefault(x => Path.GetExtension(x) == ".dll"); }