コード例 #1
0
ファイル: Executable.cs プロジェクト: cdmihai/cli
        public void GenerateBindingRedirects(LibraryExporter exporter)
        {
            var outputName = _outputPaths.RuntimeFiles.Assembly;

            var existingConfig = new DirectoryInfo(_context.ProjectDirectory)
                .EnumerateFiles()
                .FirstOrDefault(f => f.Name.Equals("app.config", StringComparison.OrdinalIgnoreCase));

            XDocument baseAppConfig = null;

            if (existingConfig != null)
            {
                using (var fileStream = File.OpenRead(existingConfig.FullName))
                {
                    baseAppConfig = XDocument.Load(fileStream);
                }
            }

            var appConfig = exporter.GetAllExports().GenerateBindingRedirects(baseAppConfig);

            if (appConfig == null) { return; }

            var path = outputName + ".config";
            using (var stream = File.Create(path))
            {
                appConfig.Save(stream);
            }
        }
コード例 #2
0
ファイル: Executable.cs プロジェクト: natemcmaster/dotnet-cli
 private static void CopyAllDependencies(string outputPath, LibraryExporter exporter)
 {
     exporter
         .GetDependencies()
         .SelectMany(e => e.RuntimeAssets())
         .CopyTo(outputPath);
 }
コード例 #3
0
ファイル: Executable.cs プロジェクト: natemcmaster/dotnet-cli
        private void MakeCompilationOutputRunnableForCoreCLR(string outputPath, LibraryExporter exporter)
        {
            WriteDepsFileAndCopyProjectDependencies(exporter, _context.ProjectFile.Name, outputPath);

            // TODO: Pick a host based on the RID
            CoreHost.CopyTo(outputPath, _context.ProjectFile.Name + Constants.ExeSuffix);
        }
コード例 #4
0
ファイル: Executable.cs プロジェクト: cdmihai/cli
 public Executable(ProjectContext context, OutputPaths outputPaths, LibraryExporter exporter)
 {
     _context = context;
     _outputPaths = outputPaths;
     _runtimeOutputPath = outputPaths.RuntimeOutputPath;
     _intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath;
     _exporter = exporter;
 }
コード例 #5
0
ファイル: Executable.cs プロジェクト: krytarowski/cli
 public Executable(ProjectContext context, OutputPaths outputPaths, LibraryExporter exporter, string configuration)
 {
     _context = context;
     _outputPaths = outputPaths;
     _runtimeOutputPath = outputPaths.RuntimeOutputPath;
     _intermediateOutputPath = outputPaths.IntermediateOutputDirectoryPath;
     _exporter = exporter;
     _compilerOptions = _context.ProjectFile.GetCompilerOptions(_context.TargetFramework, configuration);
 }
コード例 #6
0
 public LibraryExporter(ProjectContext context, IApplicationInfo applicationInfo)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     _libraryExporter = context.CreateExporter(applicationInfo.ApplicationConfiguration);
     _context         = context;
 }
コード例 #7
0
ファイル: Executable.cs プロジェクト: natemcmaster/dotnet-cli
        private void MakeCompilationOutputRunnableForFullFramework(
            string outputPath,
            string configuration,
            LibraryExporter exporter)
        {
            CopyAllDependencies(outputPath, exporter);

            GenerateBindingRedirects(exporter, configuration);
        }        
コード例 #8
0
ファイル: Executable.cs プロジェクト: natemcmaster/dotnet-cli
        private static void WriteDepsFileAndCopyProjectDependencies(
            LibraryExporter exporter,
            string projectFileName,
            string outputPath)
        {
            exporter
                .GetDependencies(LibraryType.Package)
                .WriteDepsTo(Path.Combine(outputPath, projectFileName + FileNameSuffixes.Deps));

            exporter
                .GetDependencies(LibraryType.Project)
                .SelectMany(e => e.RuntimeAssets())
                .CopyTo(outputPath);
        }                        
コード例 #9
0
        public static DependencyContext Build(CommonCompilerOptions compilerOptions, LibraryExporter libraryExporter, string configuration, NuGetFramework target, string runtime)
        {
            var dependencies = libraryExporter.GetAllExports().Where(export => export.Library.Framework.Equals(target)).ToList();

            // Sometimes we have package and reference assembly with the same name (System.Runtime for example) thats why we
            // deduplicating them prefering reference assembly
            var dependencyLookup = dependencies
                .OrderBy(export => export.Library.Identity.Type == LibraryType.ReferenceAssembly)
                .GroupBy(export => export.Library.Identity.Name)
                .Select(exports => exports.First())
                .Select(export => new Dependency(export.Library.Identity.Name, export.Library.Identity.Version.ToString()))
                .ToDictionary(dependency => dependency.Name);

            return new DependencyContext(target.DotNetFrameworkName, runtime,
                GetCompilationOptions(compilerOptions),
                GetLibraries(dependencies, dependencyLookup, target, configuration, runtime: false).Cast<CompilationLibrary>().ToArray(),
                GetLibraries(dependencies, dependencyLookup, target, configuration, runtime: true).Cast<RuntimeLibrary>().ToArray());
        }
コード例 #10
0
ファイル: Executable.cs プロジェクト: akrisiun/dotnet-cli
        private void WriteDepsFileAndCopyProjectDependencies(LibraryExporter exporter)
        {
            var exports = exporter.GetAllExports().ToList();
            var exportsLookup = exports.ToDictionary(e => e.Library.Identity.Name);
            var platformExclusionList = _context.GetPlatformExclusionList(exportsLookup);
            var filteredExports = exports.FilterExports(platformExclusionList);

            WriteConfigurationFiles(exports, filteredExports, exports, includeDevConfig: true);

            var projectExports = exporter.GetAllProjectTypeDependencies();
            CopyAssemblies(projectExports);
            CopyAssets(projectExports);

            var packageExports = exporter.GetDependencies(LibraryType.Package);
            CopyAssets(packageExports);
        }
コード例 #11
0
        private static void GenerateBindingRedirects(this ProjectContext context, LibraryExporter exporter, string outputPath)
        {
            var existingConfig = new DirectoryInfo(context.ProjectDirectory)
                .EnumerateFiles()
                .FirstOrDefault(f => f.Name.Equals("app.config", StringComparison.OrdinalIgnoreCase));

            XDocument baseAppConfig = null;

            if (existingConfig != null)
            {
                using (var fileStream = File.OpenRead(existingConfig.FullName))
                {
                    baseAppConfig = XDocument.Load(fileStream);
                }
            }

            var appConfig = exporter.GetAllExports().GenerateBindingRedirects(baseAppConfig);

            if (appConfig == null) { return; }

            var path = Path.Combine(outputPath, context.ProjectFile.Name + ".exe.config");
            using (var stream = File.Create(path))
            {
                appConfig.Save(stream);
            }
        }
コード例 #12
0
ファイル: Executable.cs プロジェクト: noahfalk/cli
 public Executable(ProjectContext context, OutputPaths outputPaths, LibraryExporter exporter)
 {
     _context = context;
     _outputPaths = outputPaths;
     _exporter = exporter;
 }
コード例 #13
0
ファイル: Executable.cs プロジェクト: noahfalk/cli
        private static void WriteDepsFileAndCopyProjectDependencies(
            LibraryExporter exporter,
            string projectFileName,
            string outputPath)
        {
            exporter
                .GetDependencies(LibraryType.Package)
                .WriteDepsTo(Path.Combine(outputPath, projectFileName + FileNameSuffixes.Deps));

            var projectExports = exporter.GetDependencies(LibraryType.Project);

            CopyAllDependencies(outputPath, projectExports);
        }
コード例 #14
0
ファイル: Executable.cs プロジェクト: ericstj/cli
        private void WriteDepsFileAndCopyProjectDependencies(LibraryExporter exporter)
        {
            WriteDeps(exporter);

            var projectExports = exporter.GetDependencies(LibraryType.Project);
            CopyAssemblies(projectExports);
            CopyAssets(projectExports);

            var packageExports = exporter.GetDependencies(LibraryType.Package);
            CopyAssets(packageExports);
        }
コード例 #15
0
ファイル: Executable.cs プロジェクト: ericstj/cli
        public void WriteDeps(LibraryExporter exporter)
        {
            var path = Path.Combine(_runtimeOutputPath, _context.ProjectFile.Name + FileNameSuffixes.Deps);
            CreateDirectoryIfNotExists(path);
            File.WriteAllLines(path, exporter
                .GetDependencies(LibraryType.Package)
                .SelectMany(GenerateLines));

            var compilerOptions = _context.ResolveCompilationOptions(_configuration);
            var includeCompile = compilerOptions.PreserveCompilationContext == true;

            var exports = exporter.GetAllExports().ToArray();
            var dependencyContext = new DependencyContextBuilder().Build(
                compilerOptions: includeCompile? compilerOptions: null,
                compilationExports: includeCompile ? exports : null,
                runtimeExports: exports,
                portable: string.IsNullOrEmpty(_context.RuntimeIdentifier),
                target: _context.TargetFramework,
                runtime: _context.RuntimeIdentifier ?? string.Empty);

            var writer = new DependencyContextWriter();
            var depsJsonFile = Path.Combine(_runtimeOutputPath, _context.ProjectFile.Name + FileNameSuffixes.DepsJson);
            using (var fileStream = File.Create(depsJsonFile))
            {
                writer.Write(dependencyContext, fileStream);
            }

        }
コード例 #16
0
ファイル: Executable.cs プロジェクト: krytarowski/cli
        public void WriteDeps(LibraryExporter exporter)
        {
            Directory.CreateDirectory(_runtimeOutputPath);

            var includeCompile = _compilerOptions.PreserveCompilationContext == true;

            var exports = exporter.GetAllExports().ToArray();
            var dependencyContext = new DependencyContextBuilder().Build(
                compilerOptions: includeCompile ? _compilerOptions : null,
                compilationExports: includeCompile ? exports : null,
                runtimeExports: exports,
                portable: string.IsNullOrEmpty(_context.RuntimeIdentifier),
                target: _context.TargetFramework,
                runtime: _context.RuntimeIdentifier ?? string.Empty);

            var writer = new DependencyContextWriter();
            var depsJsonFilePath = Path.Combine(_runtimeOutputPath, _compilerOptions.OutputName + FileNameSuffixes.DepsJson);
            using (var fileStream = File.Create(depsJsonFilePath))
            {
                writer.Write(dependencyContext, fileStream);
            }
        }
コード例 #17
0
ファイル: Executable.cs プロジェクト: akrisiun/dotnet-cli
        public void GenerateBindingRedirects(LibraryExporter exporter)
        {
            var outputName = _outputPaths.RuntimeFiles.Assembly;
            var configFile = outputName + Constants.ConfigSuffix;

            var existingConfig = new DirectoryInfo(_context.ProjectDirectory)
                .EnumerateFiles()
                .FirstOrDefault(f => f.Name.Equals("app.config", StringComparison.OrdinalIgnoreCase));

            if (existingConfig != null)
            {
                File.Copy(existingConfig.FullName, configFile, true);
            }

            List<string> configFiles = new List<string>();
            configFiles.Add(configFile);

            foreach (var export in exporter.GetDependencies())
            {
                var dependencyExecutables = export.RuntimeAssemblyGroups.GetDefaultAssets()
                                                .Where(asset => asset.FileName.ToLower().EndsWith(FileNameSuffixes.DotNet.Exe))
                                                .Select(asset => Path.Combine(_runtimeOutputPath, asset.FileName));

                foreach (var executable in dependencyExecutables)
                {
                    configFile = executable + Constants.ConfigSuffix;
                    configFiles.Add(configFile);
                }
            }

            exporter.GetAllExports().GenerateBindingRedirects(configFiles);
        }
コード例 #18
0
ファイル: Executable.cs プロジェクト: krytarowski/cli
        private void WriteRuntimeConfig(LibraryExporter exporter)
        {
            if (!_context.TargetFramework.IsDesktop())
            {
                // TODO: Suppress this file if there's nothing to write? RuntimeOutputFiles would have to be updated
                // in order to prevent breaking incremental compilation...

                var json = new JObject();
                var runtimeOptions = new JObject();
                json.Add("runtimeOptions", runtimeOptions);

                var redistPackage = _context.RootProject.Dependencies
                    .Where(r => r.Type.Equals(LibraryDependencyType.Platform))
                    .ToList();
                if(redistPackage.Count > 0)
                {
                    if(redistPackage.Count > 1)
                    {
                        throw new InvalidOperationException("Multiple packages with type: \"platform\" were specified!");
                    }
                    var packageName = redistPackage.Single().Name;

                    var redistExport = exporter.GetAllExports()
                        .FirstOrDefault(e => e.Library.Identity.Name.Equals(packageName));
                    if (redistExport == null)
                    {
                        throw new InvalidOperationException($"Platform package '{packageName}' was not present in the graph.");
                    }
                    else
                    {
                        var framework = new JObject(
                            new JProperty("name", redistExport.Library.Identity.Name),
                            new JProperty("version", redistExport.Library.Identity.Version.ToNormalizedString()));
                        runtimeOptions.Add("framework", framework);
                    }
                }

                var runtimeConfigJsonFile =
                    Path.Combine(_runtimeOutputPath, _compilerOptions.OutputName + FileNameSuffixes.RuntimeConfigJson);

                using (var writer = new JsonTextWriter(new StreamWriter(File.Create(runtimeConfigJsonFile))))
                {
                    writer.Formatting = Formatting.Indented;
                    json.WriteTo(writer);
                }
            }
        }
コード例 #19
0
ファイル: Executable.cs プロジェクト: krytarowski/cli
        private void WriteDevRuntimeConfig(LibraryExporter exporter)
        {
            if (_context.TargetFramework.IsDesktop())
            {
                return;
            }

            var json = new JObject();
            var runtimeOptions = new JObject();
            json.Add("runtimeOptions", runtimeOptions);

            AddAdditionalProbingPaths(runtimeOptions);

            var runtimeConfigDevJsonFile =
                    Path.Combine(_runtimeOutputPath, _compilerOptions.OutputName + FileNameSuffixes.RuntimeConfigDevJson);

            using (var writer = new JsonTextWriter(new StreamWriter(File.Create(runtimeConfigDevJsonFile))))
            {
                writer.Formatting = Formatting.Indented;
                json.WriteTo(writer);
            }
        }
コード例 #20
0
ファイル: Executable.cs プロジェクト: akrisiun/dotnet-cli
 public Executable(ProjectContext context, OutputPaths outputPaths, LibraryExporter exporter, string configuration)
     : this(context, outputPaths, outputPaths.RuntimeOutputPath, outputPaths.IntermediateOutputDirectoryPath, exporter, configuration) { }
コード例 #21
0
ファイル: Program.cs プロジェクト: shahid-pk/cli
        private static void EmitHost(ProjectContext runtimeContext, string outputPath, LibraryExporter exporter)
        {
            // Write the Host information file (basically a simplified form of the lock file)
            var lines = new List<string>();
            foreach (var export in exporter.GetAllExports())
            {
                if (export.Library == runtimeContext.RootProject)
                {
                    continue;
                }

                if (export.Library is ProjectDescription)
                {
                    // Copy project dependencies to the output folder
                    CopyFiles(export.RuntimeAssemblies, outputPath);
                    CopyFiles(export.NativeLibraries, outputPath);
                }
                else
                {
                    lines.AddRange(GenerateLines(export, export.RuntimeAssemblies, "runtime"));
                    lines.AddRange(GenerateLines(export, export.NativeLibraries, "native"));
                }
            }

            File.WriteAllLines(Path.Combine(outputPath, runtimeContext.ProjectFile.Name + ".deps"), lines);

            // Copy the host in
            CopyHost(Path.Combine(outputPath, runtimeContext.ProjectFile.Name + Constants.ExeSuffix));
        }
コード例 #22
0
ファイル: Executable.cs プロジェクト: krwq/cli
        private void WriteRuntimeConfig(LibraryExporter exporter)
        {
            if (!_context.TargetFramework.IsDesktop())
            {
                // TODO: Suppress this file if there's nothing to write? RuntimeOutputFiles would have to be updated
                // in order to prevent breaking incremental compilation...

                var json = new JObject();
                var runtimeOptions = new JObject();
                json.Add("runtimeOptions", runtimeOptions);

                WriteFramework(runtimeOptions, exporter);
                WriteRuntimeOptions(runtimeOptions);

                var runtimeConfigJsonFile =
                    Path.Combine(_runtimeOutputPath, _compilerOptions.OutputName + FileNameSuffixes.RuntimeConfigJson);

                using (var writer = new JsonTextWriter(new StreamWriter(File.Create(runtimeConfigJsonFile))))
                {
                    writer.Formatting = Formatting.Indented;
                    json.WriteTo(writer);
                }
            }
        }
コード例 #23
0
ファイル: Executable.cs プロジェクト: krwq/cli
        private void WriteFramework(JObject runtimeOptions, LibraryExporter exporter)
        {
            var redistPackage = _context.RootProject.Dependencies
                      .Where(r => r.Type.Equals(LibraryDependencyType.Platform))
                      .ToList();
            if (redistPackage.Count > 0)
            {
                if (redistPackage.Count > 1)
                {
                    throw new InvalidOperationException("Multiple packages with type: \"platform\" were specified!");
                }
                var packageName = redistPackage.Single().Name;

                var redistExport = exporter.GetAllExports()
                    .FirstOrDefault(e => e.Library.Identity.Name.Equals(packageName));
                if (redistExport == null)
                {
                    throw new InvalidOperationException($"Platform package '{packageName}' was not present in the graph.");
                }
                else
                {
                    var framework = new JObject(
                        new JProperty("name", redistExport.Library.Identity.Name),
                        new JProperty("version", redistExport.Library.Identity.Version.ToNormalizedString()));
                    runtimeOptions.Add("framework", framework);
                }
            }
        }
コード例 #24
0
ファイル: Executable.cs プロジェクト: cdmihai/cli
        private void WriteDepsFileAndCopyProjectDependencies(LibraryExporter exporter)
        {
            exporter
                .GetDependencies(LibraryType.Package)
                .WriteDepsTo(Path.Combine(_runtimeOutputPath, _context.ProjectFile.Name + FileNameSuffixes.Deps));

            var projectExports = exporter.GetDependencies(LibraryType.Project);
            CopyAssemblies(projectExports);
            CopyAssets(projectExports);

            var packageExports = exporter.GetDependencies(LibraryType.Package);
            CopyAssets(packageExports);
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: shahid-pk/cli
        private static void MakeRunnable(ProjectContext runtimeContext, string outputPath, LibraryExporter exporter)
        {
            CopyContents(runtimeContext, outputPath);

            if (runtimeContext.TargetFramework.IsDesktop())
            {
                // On desktop we need to copy dependencies since we don't own the host
                foreach (var export in exporter.GetDependencies())
                {
                    CopyExport(outputPath, export);
                }
            }
            else
            {
                EmitHost(runtimeContext, outputPath, exporter);
            }
        }
コード例 #26
0
        private LibraryExport ExportSingle(LibraryDescription description = null)
        {
            var rootProject = new Project()
            {
                Name = "RootProject",
                _defaultCompilerOptions = new CommonCompilerOptions
                {
                    CompilerName = "csc"
                }
            };

            var rootProjectDescription = new ProjectDescription(
                new LibraryRange(),
                rootProject,
                new LibraryRange[] { },
                new TargetFrameworkInformation(),
                true);

            if (description == null)
            {
                description = rootProjectDescription;
            }
            else
            {
                description.Parents.Add(rootProjectDescription);
            }

            var libraryManager = new LibraryManager(new[] { description }, new DiagnosticMessage[] { }, "");
            var allExports = new LibraryExporter(rootProjectDescription, libraryManager, "config", "runtime", null, "basepath", "solutionroot").GetAllExports();
            var export = allExports.Single();
            return export;
        }