public LockFilePatcher(LockFile lockFile) { _lockFile = lockFile; var msbuildProjectLibraries = lockFile.ProjectLibraries.Where(MSBuildDependencyProvider.IsMSBuildProjectLibrary); _msbuildTargetLibraries = msbuildProjectLibraries.ToDictionary(GetProjectLibraryKey, l => GetTargetsForLibrary(_lockFile, l)); }
private void EnsureToolJsonDepsFileExists( LibraryRange toolLibrary, LockFile toolLockFile, string depsPath) { if (!File.Exists(depsPath)) { var projectContext = new ProjectContextBuilder() .WithLockFile(toolLockFile) .WithTargetFramework(s_toolPackageFramework.ToString()) .Build(); var exporter = projectContext.CreateExporter(Constants.DefaultConfiguration); var dependencyContext = new DependencyContextBuilder() .Build(null, null, exporter.GetAllExports(), true, s_toolPackageFramework, string.Empty); using (var fileStream = File.Create(depsPath)) { var dependencyContextWriter = new DependencyContextWriter(); dependencyContextWriter.Write(dependencyContext, fileStream); } } }
private void EnsureToolJsonDepsFileExists( LockFile toolLockFile, string depsPath) { if (!File.Exists(depsPath)) { GenerateDepsJsonFile(toolLockFile, depsPath); } }
private static IList<LockFileTargetLibrary> GetTargetsForLibrary(LockFile lockFile, LockFileProjectLibrary library) { return lockFile.Targets .SelectMany( t => t.Libraries .Where( l => string.Equals(GetProjectLibraryKey(library), (GetTargetLibraryKey(l))) ) ) .ToList(); }
private string GetToolDepsFilePath( LibraryRange toolLibrary, LockFile toolLockFile, string depsPathRoot) { var depsJsonPath = Path.Combine( depsPathRoot, toolLibrary.Name + FileNameSuffixes.DepsJson); EnsureToolJsonDepsFileExists(toolLibrary, toolLockFile, depsJsonPath); return(depsJsonPath); }
// Need to unit test this, so public public void GenerateDepsJsonFile( LockFile toolLockFile, string depsPath) { Reporter.Verbose.WriteLine($"Generating deps.json at: {depsPath}"); var projectContext = new ProjectContextBuilder() .WithLockFile(toolLockFile) .WithTargetFramework(s_toolPackageFramework.ToString()) .Build(); var exporter = projectContext.CreateExporter(Constants.DefaultConfiguration); var dependencyContext = new DependencyContextBuilder() .Build(null, null, exporter.GetAllExports(), true, s_toolPackageFramework, string.Empty); var tempDepsFile = Path.GetTempFileName(); using (var fileStream = File.Open(tempDepsFile, FileMode.Open, FileAccess.Write)) { var dependencyContextWriter = new DependencyContextWriter(); dependencyContextWriter.Write(dependencyContext, fileStream); } try { File.Copy(tempDepsFile, depsPath); } catch (Exception e) { Reporter.Verbose.WriteLine($"unable to generate deps.json, it may have been already generated: {e.Message}"); } finally { try { File.Delete(tempDepsFile); } catch (Exception e2) { Reporter.Verbose.WriteLine($"unable to delete temporary deps.json file: {e2.Message}"); } } }
public LockFileLookup(LockFile lockFile) { _packages = new Dictionary<Tuple<string, NuGetVersion>, LockFilePackageLibrary>(); _projects = new Dictionary<string, LockFileProjectLibrary>(); foreach (var library in lockFile.PackageLibraries) { _packages[Tuple.Create(library.Name, library.Version)] = library; } foreach (var libary in lockFile.ProjectLibraries) { _projects[libary.Name] = libary; } }
internal ProjectContext( GlobalSettings globalSettings, ProjectDescription rootProject, NuGetFramework targetFramework, string runtimeIdentifier, string packagesDirectory, LibraryManager libraryManager, LockFile lockfile) { GlobalSettings = globalSettings; RootProject = rootProject; TargetFramework = targetFramework; RuntimeIdentifier = runtimeIdentifier; PackagesDirectory = packagesDirectory; LibraryManager = libraryManager; LockFile = lockfile; }
private LockFile GetToolLockFile( LibraryRange toolLibrary, string nugetPackagesRoot) { var lockFilePath = GetToolLockFilePath(toolLibrary, nugetPackagesRoot); if (!File.Exists(lockFilePath)) { return(null); } LockFile lockFile = null; try { lockFile = LockFileReader.Read(lockFilePath); } catch (FileFormatException ex) { throw ex; } return(lockFile); }
internal ProjectContext( GlobalSettings globalSettings, ProjectDescription rootProject, LibraryDescription platformLibrary, NuGetFramework targetFramework, bool isPortable, string runtimeIdentifier, string packagesDirectory, LibraryManager libraryManager, LockFile lockfile, List<DiagnosticMessage> diagnostics) { Identity = new ProjectContextIdentity(rootProject?.Path, targetFramework); GlobalSettings = globalSettings; RootProject = rootProject; PlatformLibrary = platformLibrary; TargetFramework = targetFramework; RuntimeIdentifier = runtimeIdentifier; PackagesDirectory = packagesDirectory; LibraryManager = libraryManager; LockFile = lockfile; IsPortable = isPortable; Diagnostics = diagnostics; }
public ProjectContextBuilder WithLockFile(LockFile lockFile) { LockFile = lockFile; return this; }
private LockFileTarget SelectTarget(LockFile lockFile) { foreach (var runtimeIdentifier in RuntimeIdentifiers) { foreach (var scanTarget in lockFile.Targets) { if (Equals(scanTarget.TargetFramework, TargetFramework) && string.Equals(scanTarget.RuntimeIdentifier, runtimeIdentifier, StringComparison.Ordinal)) { return scanTarget; } } } foreach (var scanTarget in lockFile.Targets) { if (Equals(scanTarget.TargetFramework, TargetFramework) && string.IsNullOrEmpty(scanTarget.RuntimeIdentifier)) { return scanTarget; } } return null; }
// Need to unit test this, so public public void GenerateDepsJsonFile( LockFile toolLockFile, string depsPath) { Reporter.Verbose.WriteLine($"Generating deps.json at: {depsPath}"); var projectContext = new ProjectContextBuilder() .WithLockFile(toolLockFile) .WithTargetFramework(s_toolPackageFramework.ToString()) .Build(); var exporter = projectContext.CreateExporter(Constants.DefaultConfiguration); var dependencyContext = new DependencyContextBuilder() .Build(null, null, exporter.GetAllExports(), true, s_toolPackageFramework, string.Empty); var tempDepsFile = Path.GetTempFileName(); using (var fileStream = File.Open(tempDepsFile, FileMode.Open, FileAccess.Write)) { var dependencyContextWriter = new DependencyContextWriter(); dependencyContextWriter.Write(dependencyContext, fileStream); } try { File.Copy(tempDepsFile, depsPath); } catch (Exception e) { Reporter.Verbose.WriteLine($"unable to generate deps.json, it may have been already generated: {e.Message}"); } finally { try { File.Delete(tempDepsFile); } catch (Exception e2) { Reporter.Verbose.WriteLine($"unable to delete temporary deps.json file: {e2.Message}"); } } }
private void EnsureToolJsonDepsFileExists( LockFile toolLockFile, string depsPath) { if (!File.Exists(depsPath)) { GenerateDepsJsonFile(toolLockFile, depsPath); } }
private string GetToolDepsFilePath( LibraryRange toolLibrary, LockFile toolLockFile, string depsPathRoot) { var depsJsonPath = Path.Combine( depsPathRoot, toolLibrary.Name + FileNameSuffixes.DepsJson); EnsureToolJsonDepsFileExists(toolLockFile, depsJsonPath); return depsJsonPath; }
private void EnsureToolJsonDepsFileExists( LibraryRange toolLibrary, LockFile toolLockFile, string depsPath) { if (!File.Exists(depsPath)) { var projectContext = new ProjectContextBuilder() .WithLockFile(toolLockFile) .WithTargetFramework(s_toolPackageFramework.ToString()) .Build(); var exporter = projectContext.CreateExporter(Constants.DefaultConfiguration); var dependencyContext = new DependencyContextBuilder() .Build(null, null, exporter.GetAllExports(), true, s_toolPackageFramework, string.Empty); using (var fileStream = File.Create(depsPath)) { var dependencyContextWriter = new DependencyContextWriter(); dependencyContextWriter.Write(dependencyContext, fileStream); } } }