Exemple #1
0
        public void CreateExecutable(ScriptContext context, LogFactory logFactory)
        {
            var tempProjectPath     = _scriptProjectProvider.CreateProjectForScriptFile(context.FilePath);
            var tempProjectDirecory = Path.GetDirectoryName(tempProjectPath);

            var scriptAssemblyPath = CreateScriptAssembly(context, tempProjectDirecory);

            var projectFile = new ProjectFile(File.ReadAllText(tempProjectPath));

            projectFile.AddPackageReference(new PackageReference("Microsoft.CodeAnalysis.Scripting", ScriptingVersion, PackageOrigin.ReferenceDirective));
            projectFile.AddAssemblyReference(scriptAssemblyPath);
            projectFile.Save(tempProjectPath);

            CopyProgramTemplate(tempProjectDirecory);

            var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier;

            var commandRunner = new CommandRunner(logFactory);
            // todo: may want to add ability to return dotnet.exe errors
            var exitcode = commandRunner.Execute("dotnet", $"publish \"{tempProjectPath}\" -c Release -r {runtimeIdentifier} -o {context.WorkingDirectory}");

            if (exitcode != 0)
            {
                throw new Exception($"dotnet publish failed with result '{exitcode}'");
            }
        }
        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));
        }
Exemple #3
0
        public IEnumerable <RuntimeDependency> GetDependencies(string scriptFile, string[] packagesSources)
        {
            var pathToProjectFile = _scriptProjectProvider.CreateProjectForScriptFile(scriptFile);

            return(GetDependenciesInternal(pathToProjectFile, packagesSources));
        }