Esempio n. 1
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);
        }
Esempio n. 2
0
        public void ShouldThrowMeaningfulExceptionWhenPassingAnInvalidAssetsFile()
        {
            var pathToAssetsFile   = Path.Combine(Path.GetTempPath(), "project.assets.json");
            var dependencyResolver = new ScriptDependencyContextReader(TestOutputHelper.CreateTestLogFactory());
            var exception          = Assert.Throws <InvalidOperationException>(() => dependencyResolver.ReadDependencyContext(pathToAssetsFile));

            Assert.Contains("Make sure that the file exists and that it is a valid 'project.assets.json' file.", exception.Message);
        }
Esempio n. 3
0
        public void ShouldThrowMeaningfulExceptionWhenRuntimeTargetIsMissing()
        {
            using (var projectFolder = new DisposableFolder())
            {
                ProcessHelper.RunAndCaptureOutput("dotnet", "new console -n SampleLibrary", projectFolder.Path);
                ProcessHelper.RunAndCaptureOutput("dotnet", "restore", projectFolder.Path);
                var pathToAssetsFile   = Path.Combine(projectFolder.Path, "SampleLibrary", "obj", "project.assets.json");
                var dependencyResolver = new ScriptDependencyContextReader(TestOutputHelper.CreateTestLogFactory());

                var exception = Assert.Throws <InvalidOperationException>(() => dependencyResolver.ReadDependencyContext(pathToAssetsFile));
                Assert.Contains("Make sure that the project file was restored using a RID (runtime identifier).", exception.Message);
            }
        }
        private IEnumerable <RuntimeDependency> GetDependenciesInternal(string pathToAssetsFile)
        {
            var context = _dependencyContextReader.ReadDependencyContext(pathToAssetsFile);
            var result  = new List <RuntimeDependency>();

            foreach (var scriptDependency in context.Dependencies)
            {
                var runtimeAssemblies = scriptDependency.RuntimeDependencyPaths.Select(rdp => new RuntimeAssembly(AssemblyName.GetAssemblyName(rdp), rdp)).ToList();
                var runtimeDependency = new RuntimeDependency(scriptDependency.Name, scriptDependency.Version, runtimeAssemblies, scriptDependency.NativeAssetPaths, scriptDependency.ScriptPaths);
                result.Add(runtimeDependency);
            }

            return(result);
        }
Esempio n. 5
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);
        }