public IEnumerable <RuntimeDependency> GetDependencies(string scriptFile, string[] packageSources)
        {
            var projectFileInfo = _scriptProjectProvider.CreateProjectForScriptFile(scriptFile);

            _restorer.Restore(projectFileInfo, packageSources);
            var pathToAssetsFile = Path.Combine(Path.GetDirectoryName(projectFileInfo.Path), "obj", "project.assets.json");

            return(GetDependenciesInternal(pathToAssetsFile));
        }
Ejemplo n.º 2
0
        public IEnumerable <CompilationDependency> GetDependencies(string targetDirectory, IEnumerable <string> scriptFiles, bool enableScriptNugetReferences, string defaultTargetFramework = "net46")
        {
            var projectFileInfo = _scriptProjectProvider.CreateProject(targetDirectory, scriptFiles, defaultTargetFramework, enableScriptNugetReferences);

            _restorer.Restore(projectFileInfo, packageSources: Array.Empty <string>());
            var pathToAssetsFile  = Path.Combine(Path.GetDirectoryName(projectFileInfo.Path), "obj", "project.assets.json");
            var dependencyContext = _scriptDependencyContextReader.ReadDependencyContext(pathToAssetsFile);
            var result            = new List <CompilationDependency>();

            foreach (var scriptDependency in dependencyContext.Dependencies)
            {
                var compilationDependency = new CompilationDependency(scriptDependency.Name, scriptDependency.Version, scriptDependency.CompileTimeDependencyPaths, scriptDependency.ScriptPaths);
                result.Add(compilationDependency);
            }

            // On .Net Core, we need to fetch the compilation references for framework assemblies separately.
            if (defaultTargetFramework.StartsWith("netcoreapp3", StringComparison.InvariantCultureIgnoreCase) ||
                defaultTargetFramework.StartsWith("net5", StringComparison.InvariantCultureIgnoreCase))
            {
                var compilationreferences = _compilationReferenceReader.Read(projectFileInfo);
                result.Add(new CompilationDependency("Dotnet.Script.Default.Dependencies", "99.0", compilationreferences.Select(cr => cr.Path).ToArray(), Array.Empty <string>()));
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void Restore(ProjectFileInfo projectFileInfo, string[] packageSources)
        {
            var stopwatch = Stopwatch.StartNew();

            _restorer.Restore(projectFileInfo, packageSources);
            _logger.Debug($"Restoring {projectFileInfo.Path} took {stopwatch.ElapsedMilliseconds}ms");
        }
Ejemplo n.º 4
0
        public void Restore(string pathToProjectFile, string[] packageSources)
        {
            var stopwatch = Stopwatch.StartNew();

            _restorer.Restore(pathToProjectFile, packageSources);
            _logger.Debug($"Restoring {pathToProjectFile} took {stopwatch.ElapsedMilliseconds}ms");
        }
 private void Restore(string pathToProjectFile, string[] packageSources)
 {
     if (_restorer.CanRestore)
     {
         _restorer.Restore(pathToProjectFile, packageSources);
         return;
     }
 }
Ejemplo n.º 6
0
        public IEnumerable <CompilationDependency> GetDependencies(string targetDirectory, IEnumerable <string> scriptFiles, bool enableScriptNugetReferences, string defaultTargetFramework = "net46")
        {
            var pathToProjectFile = _scriptProjectProvider.CreateProject(targetDirectory, scriptFiles, defaultTargetFramework, enableScriptNugetReferences);

            _restorer.Restore(pathToProjectFile, packageSources: Array.Empty <string>());
            var pathToAssetsFile  = Path.Combine(Path.GetDirectoryName(pathToProjectFile), "obj", "project.assets.json");
            var dependencyContext = _scriptDependencyContextReader.ReadDependencyContext(pathToAssetsFile);
            var result            = new List <CompilationDependency>();

            foreach (var scriptDependency in dependencyContext.Dependencies)
            {
                var compilationDependency = new CompilationDependency(scriptDependency.Name, scriptDependency.Version, scriptDependency.CompileTimeDependencyPaths, scriptDependency.ScriptPaths);
                result.Add(compilationDependency);
            }
            return(result);
        }
        /// <inheritdoc/>
        public void Restore(string pathToProjectFile, string[] packageSources)
        {
            var projectFile             = new ProjectFile(File.ReadAllText(pathToProjectFile));
            var pathToCachedProjectFile = $"{pathToProjectFile}.cache";

            if (File.Exists(pathToCachedProjectFile))
            {
                _logger.Debug($"Found cached csproj file at: {pathToCachedProjectFile}");
                var cachedProjectFile = new ProjectFile(File.ReadAllText(pathToCachedProjectFile));
                if (projectFile.Equals(cachedProjectFile))
                {
                    _logger.Debug($"Skipping restore. {pathToProjectFile} and {pathToCachedProjectFile} are identical.");
                    return;
                }
                else
                {
                    _logger.Debug($"Cache miss. Deleting stale cache file {pathToCachedProjectFile}");
                    File.Delete(pathToCachedProjectFile);
                    RestoreAndCacheProjectFile();
                }
            }
            else
            {
                RestoreAndCacheProjectFile();
            }

            void RestoreAndCacheProjectFile()
            {
                _restorer.Restore(pathToProjectFile, packageSources);
                if (projectFile.IsCacheable)
                {
                    _logger.Debug($"Caching project file : {pathToCachedProjectFile}");
                    projectFile.Save(pathToCachedProjectFile);
                }
                else
                {
                    _logger.Warning($"Unable to cache {pathToProjectFile}. For caching and optimal performance, ensure that the script(s) references Nuget packages with a pinned version.");
                }
            }
        }