예제 #1
0
        private IEnumerable <RuntimeDependency> GetDependenciesInternal(string pathToProjectOrDll, string[] packageSources = null, bool restorePackages = true)
        {
            packageSources = packageSources ?? new string[0];
            ScriptDependencyInfo dependencyInfo;

            if (restorePackages)
            {
                dependencyInfo = _scriptDependencyInfoProvider.GetDependencyInfo(pathToProjectOrDll, packageSources);
            }
            else
            {
                dependencyInfo = _scriptDependencyInfoProvider.GetDependencyInfo(pathToProjectOrDll);
            }

            var           dependencyContext   = dependencyInfo.DependencyContext;
            List <string> nuGetPackageFolders = dependencyInfo.NugetPackageFolders.ToList();

            nuGetPackageFolders.Add(_scriptEnvironment.NuGetStoreFolder);

            var runtimeDependencies = new List <RuntimeDependency>();

            var runtimeLibraries = dependencyContext.RuntimeLibraries;

            foreach (var runtimeLibrary in runtimeLibraries)
            {
                var runtimeDependency = new RuntimeDependency(runtimeLibrary.Name, runtimeLibrary.Version,
                                                              ProcessRuntimeAssemblies(runtimeLibrary, nuGetPackageFolders.ToArray()),
                                                              ProcessNativeLibraries(runtimeLibrary, nuGetPackageFolders.ToArray()),
                                                              ProcessScriptFiles(runtimeLibrary, nuGetPackageFolders.ToArray()));

                runtimeDependencies.Add(runtimeDependency);
            }

            return(runtimeDependencies);
        }
        public IEnumerable <string> GetDependencies(string targetDirectory, bool enableScriptNugetReferences, string defaultTargetFramework = "net46")
        {
            var pathToProjectFile = _scriptProjectProvider.CreateProject(targetDirectory, defaultTargetFramework,
                                                                         enableScriptNugetReferences);

            if (pathToProjectFile == null)
            {
                return(Array.Empty <string>());
            }

            var dependencyInfo = _scriptDependencyInfoProvider.GetDependencyInfo(pathToProjectFile);

            var dependencyContext = dependencyInfo.DependencyContext;

            var compilationAssemblyResolvers = GetCompilationAssemblyResolvers(dependencyInfo.NugetPackageFolders);

            var resolvedReferencePaths = new HashSet <string>();

            var compileLibraries = dependencyContext.CompileLibraries;

            foreach (var compilationLibrary in compileLibraries)
            {
                _logger.Debug($"Resolving compilation reference paths for {compilationLibrary.Name}");
                var referencePaths = ResolveReferencePaths(compilationLibrary, compilationAssemblyResolvers);
                foreach (var referencePath in referencePaths)
                {
                    resolvedReferencePaths.Add(referencePath);
                }
            }
            return(resolvedReferencePaths);
        }
        private IEnumerable <RuntimeDependency> GetDependenciesInternal(string pathToProjectFile)
        {
            var dependencyInfo = _scriptDependencyInfoProvider.GetDependencyInfo(pathToProjectFile);

            var           dependencyContext   = dependencyInfo.DependencyContext;
            List <string> nuGetPackageFolders = dependencyInfo.NugetPackageFolders.ToList();

            nuGetPackageFolders.Add(RuntimeHelper.GetPathToNuGetStoreFolder());

            var runtimeDependencies = new List <RuntimeDependency>();

            var runtimeLibraries = dependencyContext.RuntimeLibraries;


            foreach (var runtimeLibrary in runtimeLibraries)
            {
                var runtimeDependency = new RuntimeDependency(runtimeLibrary.Name, runtimeLibrary.Version,
                                                              ProcessRuntimeAssemblies(runtimeLibrary, nuGetPackageFolders.ToArray()),
                                                              ProcessNativeLibraries(runtimeLibrary, nuGetPackageFolders.ToArray()),
                                                              ProcessScriptFiles(runtimeLibrary, nuGetPackageFolders.ToArray()));

                runtimeDependencies.Add(runtimeDependency);
            }

            return(runtimeDependencies);
        }
        public IEnumerable <CompilationDependency> GetDependencies(string targetDirectory, bool enableScriptNugetReferences, string defaultTargetFramework = "net46")
        {
            var pathToProjectFile = _scriptProjectProvider.CreateProject(targetDirectory, defaultTargetFramework,
                                                                         enableScriptNugetReferences);

            if (pathToProjectFile == null)
            {
                return(Array.Empty <CompilationDependency>());
            }

            var dependencyInfo = _scriptDependencyInfoProvider.GetDependencyInfo(pathToProjectFile, Array.Empty <string>());

            var dependencyContext = dependencyInfo.DependencyContext;

            var compilationAssemblyResolvers = GetCompilationAssemblyResolvers(dependencyInfo.NugetPackageFolders);


            List <CompilationDependency> result = new List <CompilationDependency>();
            var compileLibraries = dependencyContext.CompileLibraries;

            foreach (var compilationLibrary in compileLibraries)
            {
                var resolvedReferencePaths = new HashSet <string>();
                _logger.Trace($"Resolving compilation reference paths for {compilationLibrary.Name}");
                var referencePaths = ResolveReferencePaths(compilationLibrary, compilationAssemblyResolvers);
                var scripts        =
                    _scriptFilesDependencyResolver.GetScriptFileDependencies(compilationLibrary.Path, dependencyInfo.NugetPackageFolders);
                foreach (var referencePath in referencePaths)
                {
                    resolvedReferencePaths.Add(referencePath);
                }
                var compilationDependency = new CompilationDependency(
                    compilationLibrary.Name,
                    compilationLibrary.Version,
                    resolvedReferencePaths.ToList(),
                    scripts);

                result.Add(compilationDependency);
            }
            return(result);
        }