public bool Initialize(string rawName, ExpandoObject container, ProjectAssetsContext context) { if (!ValidateInitializationArguments(rawName, container, context)) { return(false); } if (!VersionedText.CreateVersionedText(rawName, out var verText, Logger)) { return(false); } Assembly = verText.TextComponent; Version = verText.Version; Dependencies = new List <DependencyInfo>(); var asDict = (IDictionary <string, object>)container; // dependencies are optional if (!asDict.ContainsKey("dependencies")) { return(true); } var depDict = asDict["dependencies"] as ExpandoObject; if (depDict == null) { Logger.Error( $"{nameof( container )} does not have a 'dependencies' property which is an {nameof( ExpandoObject )}"); return(false); } var retVal = true; foreach (var kvp in depDict) { if (kvp.Value is string versionText) { if (VersionedText.TryParseSemanticVersion(versionText, out var version, Logger)) { var newItem = _diCreator(); newItem.Assembly = kvp.Key; newItem.Version = version; Dependencies.Add(newItem); } else { retVal = false; } } }
public virtual bool Initialize(string rawName, ExpandoObject container, ProjectAssetsContext context) { if (!ValidateInitializationArguments(rawName, container, context)) { return(false); } if (!VersionedText.CreateVersionedText(rawName, out var verText, Logger)) { return(false); } if (!GetProperty <string>(container, "type", context, out var libTypeText)) { return(false); } if (!Enum.TryParse <ReferenceType>(libTypeText, true, out var libType)) { Logger.Error( $"Property 'type' ('{libTypeText}') isn't parseable to a {nameof( ReferenceType )}"); return(false); } if (libType != Type) { Logger.Error($"Expected a {Type} library, encountered a {libType} instead"); return(false); } if (!GetProperty <string>(container, "path", context, out var path)) { return(false); } Assembly = verText.TextComponent; Version = verText.Version; Path = path; return(true); }
public virtual string GetAbsolutePath(IEnumerable <string> repositoryPaths, TargetFramework tgtFramework) { if (repositoryPaths == null) { Logger.Error($"Undefined {nameof(repositoryPaths)}"); return(null); } if (tgtFramework == null) { Logger.Error($"Undefined {nameof(tgtFramework)}"); return(null); } foreach (var repositoryPath in repositoryPaths) { var pkgDir = System.IO.Path.GetFullPath(System.IO.Path.Combine(repositoryPath, Path)); if (!Directory.Exists(pkgDir)) { continue; } // look for best match re: version pkgDir = System.IO.Path.Combine(pkgDir, "lib"); if (!Directory.Exists(pkgDir)) { continue; } var fwDirectories = Directory.GetDirectories(pkgDir, tgtFramework.Framework + "*") .Where(dir => VersionedText.CreateVersionedText(System.IO.Path.GetFileName(dir), out var result, Logger)) .Select(dir => { VersionedText.CreateVersionedText(System.IO.Path.GetFileName(dir), out var verText, Logger); return(new { path = dir, version = verText.Version }); }) .OrderByDescending(x => x.version) .ToList(); var match = fwDirectories.FirstOrDefault(x => x.version == tgtFramework.Version) ?? fwDirectories.FirstOrDefault(); if (match == null) { continue; } var filePath = System.IO.Path.Combine(match.path, $"{Assembly}.dll"); if (File.Exists(filePath)) { return(filePath); } // check to see if the "it's already included from elsewhere" marker file is there // in which case return null but don't issue a warning filePath = System.IO.Path.Combine(match.path, "_._"); if (File.Exists(filePath)) { return(null); } } // nuget appears to use directories starting with "runtime" to indicate runtime-only libraries, // typically for other operating systems...suppress warnings associated with such if (Path.IndexOf("runtime", StringComparison.Ordinal) != 0) { Logger.Warning($"Couldn't find '{Path}' in provided repositories"); } return(null); }