Ejemplo n.º 1
0
        public LockFilePatcher(LockFile lockFile)
        {
            _lockFile = lockFile;

            var msbuildProjectLibraries = lockFile.ProjectLibraries.Where(MSBuildDependencyProvider.IsMSBuildProjectLibrary);
            _msbuildTargetLibraries = msbuildProjectLibraries.ToDictionary(GetProjectLibraryKey, l => GetTargetsForLibrary(_lockFile, l));
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
 private void EnsureToolJsonDepsFileExists(
     LockFile toolLockFile,
     string depsPath)
 {
     if (!File.Exists(depsPath))
     {
         GenerateDepsJsonFile(toolLockFile, depsPath);
     }
 }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
0
        private string GetToolDepsFilePath(
            LibraryRange toolLibrary,
            LockFile toolLockFile,
            string depsPathRoot)
        {
            var depsJsonPath = Path.Combine(
                depsPathRoot,
                toolLibrary.Name + FileNameSuffixes.DepsJson);

            EnsureToolJsonDepsFileExists(toolLibrary, toolLockFile, depsJsonPath);

            return(depsJsonPath);
        }
Ejemplo n.º 6
0
        // 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}");
                }
            }
        }
Ejemplo n.º 7
0
        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;
            }
        }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
 public ProjectContextBuilder WithLockFile(LockFile lockFile)
 {
     LockFile = lockFile;
     return this;
 }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 16
0
        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);
                }
            }
        }