private async Task OpenChannel(int port, string hostId) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var namedDependencyProvider = new NamedCacheDependencyProvider(); var contexts = new Dictionary <int, ApplicationContext>(); var services = new ServiceProvider(_services); var protocolManager = new ProtocolManager(maxVersion: 2); // This fixes the mono incompatibility but ties it to ipv4 connections var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port)); listenSocket.Listen(10); Console.WriteLine("Listening on port {0}", port); for (; ;) { var acceptSocket = await AcceptAsync(listenSocket); Console.WriteLine("Client accepted {0}", acceptSocket.LocalEndPoint); var stream = new NetworkStream(acceptSocket); var queue = new ProcessingQueue(stream); var connection = new ConnectionContext( contexts, services, cache, cacheContextAccessor, namedDependencyProvider, queue, protocolManager, hostId); queue.OnReceive += message => { // Enumerates all project contexts and return them to the // sender if (message.MessageType == "EnumerateProjectContexts") { WriteProjectContexts(message, queue, contexts); } else { // Otherwise it's a context specific message connection.OnReceive(message); } }; queue.Start(); } }
/// <summary> /// Execute the command /// </summary> /// <returns>Returns 0 for success, otherwise 1.</returns> public int Execute() { var accessor = new CacheContextAccessor(); var cache = new Cache(accessor); var finder = new DependencyFinder(accessor, cache, _environment, _assemblyFolder); ICollection<string> tpa = finder.GetDependencies(Constants.BootstrapperCoreclrManagedName); // ordering the tpa list make it easier to compare the difference UpdateSourceFile(tpa.OrderBy(one => one).ToArray()); return 0; }
/// <summary> /// Execute the command /// </summary> /// <returns>Returns 0 for success, otherwise 1.</returns> public int Execute() { var accessor = new CacheContextAccessor(); var cache = new Cache(accessor); var finder = new DependencyFinder(accessor, cache, _environment, _assemblyFolder); ICollection <string> tpa = finder.GetDependencies(Constants.BootstrapperCoreclrManagedName); // ordering the tpa list make it easier to compare the difference UpdateSourceFile(tpa.OrderBy(one => one).ToArray()); return(0); }
private async Task OpenChannel(int port, string hostId) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var namedDependencyProvider = new NamedCacheDependencyProvider(); var contexts = new Dictionary<int, ApplicationContext>(); var services = new ServiceProvider(_services); // This fixes the mono incompatibility but ties it to ipv4 connections var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port)); listenSocket.Listen(10); Console.WriteLine("Listening on port {0}", port); for (; ;) { var acceptSocket = await AcceptAsync(listenSocket); Console.WriteLine("Client accepted {0}", acceptSocket.LocalEndPoint); var stream = new NetworkStream(acceptSocket); var queue = new ProcessingQueue(stream); var connection = new ConnectionContext( contexts, services, cache, cacheContextAccessor, namedDependencyProvider, queue, hostId); queue.OnReceive += message => { // Enumerates all project contexts and return them to the // sender if (message.MessageType == "EnumerateProjectContexts") { WriteProjectContexts(message, queue, contexts); } else { // Otherwise it's a context specific message connection.OnReceive(message); } }; queue.Start(); } }
private ApplicationHostContext CreateApplicationHostContext() { var accessor = new CacheContextAccessor(); var cache = new Cache(accessor); var hostContext = new ApplicationHostContext( hostServices: null, projectDirectory: _options.Project.ProjectDirectory, packagesDirectory: null, configuration: Configuration, targetFramework: _framework); hostContext.DependencyWalker.Walk(hostContext.Project.Name, hostContext.Project.Version, _framework); return(hostContext); }
public bool Build() { var projectFilesFinder = new Matcher(); // Resolve all the project names var projectFilesToBuild = new List <string>(); foreach (var pattern in _buildOptions.ProjectPatterns) { if (pattern.Contains("*")) { // Requires globbing projectFilesFinder.AddInclude(NormalizeGlobbingPattern(pattern)); } else { projectFilesToBuild.Add(pattern); } } var rootDirectory = Directory.GetCurrentDirectory(); var patternSearchFolder = new DirectoryInfoWrapper(new DirectoryInfo(rootDirectory)); var globbingProjects = projectFilesFinder.Execute(patternSearchFolder).Files.Select(file => Path.Combine(rootDirectory, file)); projectFilesToBuild.AddRange(globbingProjects); var sw = Stopwatch.StartNew(); _cacheContextAccessor = new CacheContextAccessor(); _cache = new Cache(_cacheContextAccessor); var globalSucess = true; foreach (var project in projectFilesToBuild) { var buildSuccess = BuildInternal(project); globalSucess &= buildSuccess; } _buildOptions.Reports.Information.WriteLine($"Total build time elapsed: { sw.Elapsed }"); _buildOptions.Reports.Information.WriteLine($"Total projects built: { projectFilesToBuild.Count }"); return(globalSucess); }
private ApplicationHostContext CreateApplicationHostContext() { var accessor = new CacheContextAccessor(); var cache = new Cache(accessor); var hostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: _options.Project.ProjectDirectory, packagesDirectory: null, configuration: Configuration, targetFramework: _framework, cache: cache, cacheContextAccessor: accessor, namedCacheDependencyProvider: null); hostContext.DependencyWalker.Walk(hostContext.Project.Name, hostContext.Project.Version, _framework); return hostContext; }
public DependencyContext(string projectDirectory, string configuration, FrameworkName targetFramework) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var applicationHostContext = new ApplicationHostContext( hostServices: null, projectDirectory: projectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework); ProjectResolver = applicationHostContext.ProjectResolver; NuGetDependencyResolver = applicationHostContext.NuGetDependencyProvider; ProjectReferenceDependencyProvider = applicationHostContext.ProjectDependencyProvider; DependencyWalker = applicationHostContext.DependencyWalker; FrameworkName = targetFramework; PackagesDirectory = applicationHostContext.PackagesDirectory; }
public int Execute() { var accessor = new CacheContextAccessor(); var cache = new Cache(accessor); var finder = new DependencyFinder(accessor, cache, _environment, _assemblyFolder); var dependencies = new Dictionary <string, HashSet <string> >(); dependencies[KeyRuntime] = new HashSet <string>(); foreach (var name in _runtimeProjects) { dependencies[KeyRuntime].AddRange(finder.GetDependencies(name)); } foreach (var name in _sdkProjects) { dependencies[name] = finder.GetDependencies(name); } foreach (var pair in dependencies.Skip(1)) { pair.Value.ExceptWith(dependencies[KeyRuntime]); } using (var output = _outputFile != null ? new StreamWriter(_outputFile) : Console.Out) { foreach (var root in dependencies) { output.WriteLine("-" + root.Key); foreach (var contract in root.Value) { output.WriteLine(contract); } } output.Write("-"); output.Flush(); } return(0); }
public DependencyContext(string projectDirectory, string configuration, FrameworkName targetFramework) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var applicationHostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: projectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework, cache: cache, cacheContextAccessor: cacheContextAccessor, namedCacheDependencyProvider: new NamedCacheDependencyProvider()); ProjectResolver = applicationHostContext.ProjectResolver; NuGetDependencyResolver = applicationHostContext.NuGetDependencyProvider; ProjectReferenceDependencyProvider = applicationHostContext.ProjectDepencyProvider; DependencyWalker = applicationHostContext.DependencyWalker; FrameworkName = targetFramework; PackagesDirectory = applicationHostContext.PackagesDirectory; }
public bool Build() { Runtime.Project project; if (!Runtime.Project.TryGetProject(_buildOptions.ProjectDir, out project)) { WriteError(string.Format("Unable to locate {0}.'", Runtime.Project.ProjectFileName)); return false; } var sw = Stopwatch.StartNew(); var baseOutputPath = GetBuildOutputDir(_buildOptions); var configurations = _buildOptions.Configurations.DefaultIfEmpty("Debug"); var specifiedFrameworks = _buildOptions.TargetFrameworks .ToDictionary(f => f, Runtime.Project.ParseFrameworkName); var projectFrameworks = new HashSet<FrameworkName>( project.GetTargetFrameworks() .Select(c => c.FrameworkName)); IEnumerable<FrameworkName> frameworks = null; if (projectFrameworks.Count > 0) { // Specified target frameworks have to be a subset of // the project frameworks if (!ValidateFrameworks(projectFrameworks, specifiedFrameworks)) { return false; } frameworks = specifiedFrameworks.Count > 0 ? specifiedFrameworks.Values : (IEnumerable<FrameworkName>)projectFrameworks; } else { frameworks = new[] { _applicationEnvironment.RuntimeFramework }; } if (_buildOptions.GeneratePackages && !ScriptExecutor.Execute(project, "prepack", GetScriptVariable)) { WriteError(ScriptExecutor.ErrorMessage); return false; } if (!ScriptExecutor.Execute(project, "prebuild", GetScriptVariable)) { WriteError(ScriptExecutor.ErrorMessage); return false; } var success = true; var allErrors = new List<string>(); var allWarnings = new List<string>(); var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); PackageBuilder packageBuilder = null; PackageBuilder symbolPackageBuilder = null; // Build all specified configurations foreach (var configuration in configurations) { if (_buildOptions.GeneratePackages) { // Create a new builder per configuration packageBuilder = new PackageBuilder(); symbolPackageBuilder = new PackageBuilder(); InitializeBuilder(project, packageBuilder); InitializeBuilder(project, symbolPackageBuilder); } var configurationSuccess = true; baseOutputPath = Path.Combine(baseOutputPath, configuration); // Build all target frameworks a project supports foreach (var targetFramework in frameworks) { _buildOptions.Reports.Information.WriteLine(); _buildOptions.Reports.Information.WriteLine("Building {0} for {1}", project.Name, targetFramework.ToString().Yellow().Bold()); var errors = new List<string>(); var warnings = new List<string>(); var context = new BuildContext(_hostServices, _applicationEnvironment, cache, cacheContextAccessor, project, targetFramework, configuration, baseOutputPath); context.Initialize(_buildOptions.Reports.Quiet); if (context.Build(warnings, errors)) { if (_buildOptions.GeneratePackages) { context.PopulateDependencies(packageBuilder); context.AddLibs(packageBuilder, "*.dll"); context.AddLibs(packageBuilder, "*.xml"); context.AddLibs(symbolPackageBuilder, "*.*"); } } else { configurationSuccess = false; } allErrors.AddRange(errors); allWarnings.AddRange(warnings); WriteDiagnostics(warnings, errors); } success = success && configurationSuccess; if (_buildOptions.GeneratePackages) { // Create a package per configuration string nupkg = GetPackagePath(project, baseOutputPath); string symbolsNupkg = GetPackagePath(project, baseOutputPath, symbols: true); if (configurationSuccess) { foreach (var sharedFile in project.SharedFiles) { var file = new PhysicalPackageFile(); file.SourcePath = sharedFile; file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile)); packageBuilder.Files.Add(file); } var root = project.ProjectDirectory; foreach (var path in project.SourceFiles) { var srcFile = new PhysicalPackageFile(); srcFile.SourcePath = path; srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path)); symbolPackageBuilder.Files.Add(srcFile); } using (var fs = File.Create(nupkg)) { packageBuilder.Save(fs); _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, nupkg); } if (symbolPackageBuilder.Files.Any()) { using (var fs = File.Create(symbolsNupkg)) { symbolPackageBuilder.Save(fs); } _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, symbolsNupkg); } } } } if (!ScriptExecutor.Execute(project, "postbuild", GetScriptVariable)) { WriteError(ScriptExecutor.ErrorMessage); return false; } if (_buildOptions.GeneratePackages && !ScriptExecutor.Execute(project, "postpack", GetScriptVariable)) { WriteError(ScriptExecutor.ErrorMessage); return false; } sw.Stop(); WriteSummary(allWarnings, allErrors); _buildOptions.Reports.Information.WriteLine("Time elapsed {0}", sw.Elapsed); return success; }
public bool Build() { var projectDiagnostics = new List<ICompilationMessage>(); Runtime.Project project; if (!Runtime.Project.TryGetProject(_buildOptions.ProjectDir, out project, projectDiagnostics)) { LogError(string.Format("Unable to locate {0}.", Runtime.Project.ProjectFileName)); return false; } var sw = Stopwatch.StartNew(); var baseOutputPath = GetBuildOutputDir(_buildOptions); var configurations = _buildOptions.Configurations.DefaultIfEmpty("Debug"); string frameworkSelectionError; var frameworks = FrameworkSelectionHelper.SelectFrameworks(project, _buildOptions.TargetFrameworks, _applicationEnvironment.RuntimeFramework, out frameworkSelectionError); if (frameworks == null) { LogError(frameworkSelectionError); return false; } if (_buildOptions.GeneratePackages && !ScriptExecutor.Execute(project, "prepack", GetScriptVariable)) { LogError(ScriptExecutor.ErrorMessage); return false; } if (!ScriptExecutor.Execute(project, "prebuild", GetScriptVariable)) { LogError(ScriptExecutor.ErrorMessage); return false; } var success = true; var allDiagnostics = new List<ICompilationMessage>(); var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); PackageBuilder packageBuilder = null; PackageBuilder symbolPackageBuilder = null; InstallBuilder installBuilder = null; // Build all specified configurations foreach (var configuration in configurations) { if (_buildOptions.GeneratePackages) { // Create a new builder per configuration packageBuilder = new PackageBuilder(); symbolPackageBuilder = new PackageBuilder(); InitializeBuilder(project, packageBuilder); InitializeBuilder(project, symbolPackageBuilder); installBuilder = new InstallBuilder(project, packageBuilder, _buildOptions.Reports); } var configurationSuccess = true; baseOutputPath = Path.Combine(baseOutputPath, configuration); // Build all target frameworks a project supports foreach (var targetFramework in frameworks) { _buildOptions.Reports.Information.WriteLine(); _buildOptions.Reports.Information.WriteLine("Building {0} for {1}", project.Name, targetFramework.ToString().Yellow().Bold()); var diagnostics = new List<ICompilationMessage>(); var context = new BuildContext(_hostServices, _applicationEnvironment, cache, cacheContextAccessor, project, targetFramework, configuration, baseOutputPath); context.Initialize(_buildOptions.Reports.Quiet); if (context.Build(diagnostics)) { if (_buildOptions.GeneratePackages) { context.PopulateDependencies(packageBuilder); context.AddLibs(packageBuilder, "*.dll"); context.AddLibs(packageBuilder, "*.xml"); context.AddLibs(symbolPackageBuilder, "*.*"); } } else { configurationSuccess = false; } allDiagnostics.AddRange(diagnostics); WriteDiagnostics(diagnostics); } success = success && configurationSuccess; if (_buildOptions.GeneratePackages) { // Create a package per configuration string nupkg = GetPackagePath(project, baseOutputPath); string symbolsNupkg = GetPackagePath(project, baseOutputPath, symbols: true); if (configurationSuccess) { // Generates the application package only if this is an application packages configurationSuccess = installBuilder.Build(baseOutputPath); success = success && configurationSuccess; } if (configurationSuccess) { foreach (var sharedFile in project.Files.SharedFiles) { var file = new PhysicalPackageFile(); file.SourcePath = sharedFile; file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile)); packageBuilder.Files.Add(file); } var root = project.ProjectDirectory; foreach (var path in project.Files.SourceFiles) { var srcFile = new PhysicalPackageFile(); srcFile.SourcePath = path; srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path)); symbolPackageBuilder.Files.Add(srcFile); } using (var fs = File.Create(nupkg)) { packageBuilder.Save(fs); _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, nupkg); } if (symbolPackageBuilder.Files.Any()) { using (var fs = File.Create(symbolsNupkg)) { symbolPackageBuilder.Save(fs); } _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, symbolsNupkg); } } } } if (!ScriptExecutor.Execute(project, "postbuild", GetScriptVariable)) { LogError(ScriptExecutor.ErrorMessage); return false; } if (_buildOptions.GeneratePackages && !ScriptExecutor.Execute(project, "postpack", GetScriptVariable)) { LogError(ScriptExecutor.ErrorMessage); return false; } sw.Stop(); if (projectDiagnostics.Any()) { // Add a new line to separate the project diagnostics information from compilation diagnostics _buildOptions.Reports.Information.WriteLine(); projectDiagnostics.ForEach(d => LogWarning(d.FormattedMessage)); } allDiagnostics.AddRange(projectDiagnostics); WriteSummary(allDiagnostics); _buildOptions.Reports.Information.WriteLine("Time elapsed {0}", sw.Elapsed); return success; }
public bool Build() { Runtime.Project project; if (!Runtime.Project.TryGetProject(_buildOptions.ProjectDir, out project)) { WriteError(string.Format("Unable to locate {0}.'", Runtime.Project.ProjectFileName)); return(false); } var sw = Stopwatch.StartNew(); var baseOutputPath = GetBuildOutputDir(_buildOptions); var configurations = _buildOptions.Configurations.DefaultIfEmpty("Debug"); var specifiedFrameworks = _buildOptions.TargetFrameworks .ToDictionary(f => f, Runtime.Project.ParseFrameworkName); var projectFrameworks = new HashSet <FrameworkName>( project.GetTargetFrameworks() .Select(c => c.FrameworkName)); IEnumerable <FrameworkName> frameworks = null; if (projectFrameworks.Count > 0) { // Specified target frameworks have to be a subset of // the project frameworks if (!ValidateFrameworks(projectFrameworks, specifiedFrameworks)) { return(false); } frameworks = specifiedFrameworks.Count > 0 ? specifiedFrameworks.Values : (IEnumerable <FrameworkName>)projectFrameworks; } else { frameworks = new[] { _applicationEnvironment.RuntimeFramework }; } if (_buildOptions.GeneratePackages && !ScriptExecutor.Execute(project, "prepack", GetScriptVariable)) { WriteError(ScriptExecutor.ErrorMessage); return(false); } if (!ScriptExecutor.Execute(project, "prebuild", GetScriptVariable)) { WriteError(ScriptExecutor.ErrorMessage); return(false); } var success = true; var allErrors = new List <string>(); var allWarnings = new List <string>(); var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); PackageBuilder packageBuilder = null; PackageBuilder symbolPackageBuilder = null; // Build all specified configurations foreach (var configuration in configurations) { if (_buildOptions.GeneratePackages) { // Create a new builder per configuration packageBuilder = new PackageBuilder(); symbolPackageBuilder = new PackageBuilder(); InitializeBuilder(project, packageBuilder); InitializeBuilder(project, symbolPackageBuilder); } var configurationSuccess = true; baseOutputPath = Path.Combine(baseOutputPath, configuration); // Build all target frameworks a project supports foreach (var targetFramework in frameworks) { _buildOptions.Reports.Information.WriteLine(); _buildOptions.Reports.Information.WriteLine("Building {0} for {1}", project.Name, targetFramework.ToString().Yellow().Bold()); var errors = new List <string>(); var warnings = new List <string>(); var context = new BuildContext(_hostServices, _applicationEnvironment, cache, cacheContextAccessor, project, targetFramework, configuration, baseOutputPath); context.Initialize(_buildOptions.Reports.Quiet); if (context.Build(warnings, errors)) { if (_buildOptions.GeneratePackages) { context.PopulateDependencies(packageBuilder); context.AddLibs(packageBuilder, "*.dll"); context.AddLibs(packageBuilder, "*.xml"); context.AddLibs(symbolPackageBuilder, "*.*"); } } else { configurationSuccess = false; } allErrors.AddRange(errors); allWarnings.AddRange(warnings); WriteDiagnostics(warnings, errors); } success = success && configurationSuccess; if (_buildOptions.GeneratePackages) { // Create a package per configuration string nupkg = GetPackagePath(project, baseOutputPath); string symbolsNupkg = GetPackagePath(project, baseOutputPath, symbols: true); if (configurationSuccess) { foreach (var sharedFile in project.SharedFiles) { var file = new PhysicalPackageFile(); file.SourcePath = sharedFile; file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile)); packageBuilder.Files.Add(file); } var root = project.ProjectDirectory; foreach (var path in project.SourceFiles) { var srcFile = new PhysicalPackageFile(); srcFile.SourcePath = path; srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path)); symbolPackageBuilder.Files.Add(srcFile); } using (var fs = File.Create(nupkg)) { packageBuilder.Save(fs); _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, nupkg); } if (symbolPackageBuilder.Files.Any()) { using (var fs = File.Create(symbolsNupkg)) { symbolPackageBuilder.Save(fs); } _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, symbolsNupkg); } } } } if (!ScriptExecutor.Execute(project, "postbuild", GetScriptVariable)) { WriteError(ScriptExecutor.ErrorMessage); return(false); } if (_buildOptions.GeneratePackages && !ScriptExecutor.Execute(project, "postpack", GetScriptVariable)) { WriteError(ScriptExecutor.ErrorMessage); return(false); } sw.Stop(); WriteSummary(allWarnings, allErrors); _buildOptions.Reports.Information.WriteLine("Time elapsed {0}", sw.Elapsed); return(success); }
public bool Build() { var projectDiagnostics = new List <ICompilationMessage>(); Runtime.Project project; if (!Runtime.Project.TryGetProject(_buildOptions.ProjectDir, out project, projectDiagnostics)) { LogError(string.Format("Unable to locate {0}.", Runtime.Project.ProjectFileName)); return(false); } var sw = Stopwatch.StartNew(); var baseOutputPath = GetBuildOutputDir(_buildOptions); var configurations = _buildOptions.Configurations.DefaultIfEmpty("Debug"); string frameworkSelectionError; var frameworks = FrameworkSelectionHelper.SelectFrameworks(project, _buildOptions.TargetFrameworks, _applicationEnvironment.RuntimeFramework, out frameworkSelectionError); if (frameworks == null) { LogError(frameworkSelectionError); return(false); } if (_buildOptions.GeneratePackages && !ScriptExecutor.Execute(project, "prepack", GetScriptVariable)) { LogError(ScriptExecutor.ErrorMessage); return(false); } if (!ScriptExecutor.Execute(project, "prebuild", GetScriptVariable)) { LogError(ScriptExecutor.ErrorMessage); return(false); } var success = true; var allDiagnostics = new List <ICompilationMessage>(); var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); PackageBuilder packageBuilder = null; PackageBuilder symbolPackageBuilder = null; InstallBuilder installBuilder = null; // Build all specified configurations foreach (var configuration in configurations) { if (_buildOptions.GeneratePackages) { // Create a new builder per configuration packageBuilder = new PackageBuilder(); symbolPackageBuilder = new PackageBuilder(); InitializeBuilder(project, packageBuilder); InitializeBuilder(project, symbolPackageBuilder); installBuilder = new InstallBuilder(project, packageBuilder, _buildOptions.Reports); } var configurationSuccess = true; baseOutputPath = Path.Combine(baseOutputPath, configuration); // Build all target frameworks a project supports foreach (var targetFramework in frameworks) { _buildOptions.Reports.Information.WriteLine(); _buildOptions.Reports.Information.WriteLine("Building {0} for {1}", project.Name, targetFramework.ToString().Yellow().Bold()); var diagnostics = new List <ICompilationMessage>(); var context = new BuildContext(_hostServices, _applicationEnvironment, cache, cacheContextAccessor, project, targetFramework, configuration, baseOutputPath); context.Initialize(_buildOptions.Reports.Quiet); if (context.Build(diagnostics)) { if (_buildOptions.GeneratePackages) { context.PopulateDependencies(packageBuilder); context.AddLibs(packageBuilder, "*.dll"); context.AddLibs(packageBuilder, "*.xml"); context.AddLibs(symbolPackageBuilder, "*.*"); } } else { configurationSuccess = false; } allDiagnostics.AddRange(diagnostics); WriteDiagnostics(diagnostics); } success = success && configurationSuccess; if (_buildOptions.GeneratePackages) { // Create a package per configuration string nupkg = GetPackagePath(project, baseOutputPath); string symbolsNupkg = GetPackagePath(project, baseOutputPath, symbols: true); if (configurationSuccess) { // Generates the application package only if this is an application packages configurationSuccess = installBuilder.Build(baseOutputPath); success = success && configurationSuccess; } if (configurationSuccess) { foreach (var sharedFile in project.Files.SharedFiles) { var file = new PhysicalPackageFile(); file.SourcePath = sharedFile; file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile)); packageBuilder.Files.Add(file); } var root = project.ProjectDirectory; foreach (var path in project.Files.SourceFiles) { var srcFile = new PhysicalPackageFile(); srcFile.SourcePath = path; srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path)); symbolPackageBuilder.Files.Add(srcFile); } using (var fs = File.Create(nupkg)) { packageBuilder.Save(fs); _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, nupkg); } if (symbolPackageBuilder.Files.Any()) { using (var fs = File.Create(symbolsNupkg)) { symbolPackageBuilder.Save(fs); } _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, symbolsNupkg); } } } } if (!ScriptExecutor.Execute(project, "postbuild", GetScriptVariable)) { LogError(ScriptExecutor.ErrorMessage); return(false); } if (_buildOptions.GeneratePackages && !ScriptExecutor.Execute(project, "postpack", GetScriptVariable)) { LogError(ScriptExecutor.ErrorMessage); return(false); } sw.Stop(); if (projectDiagnostics.Any()) { // Add a new line to separate the project diagnostics information from compilation diagnostics _buildOptions.Reports.Information.WriteLine(); projectDiagnostics.ForEach(d => LogWarning(d.FormattedMessage)); } allDiagnostics.AddRange(projectDiagnostics); WriteSummary(allDiagnostics); _buildOptions.Reports.Information.WriteLine("Time elapsed {0}", sw.Elapsed); return(success); }
private void Initialize(DefaultHostOptions options, IServiceProvider hostServices) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var namedCacheDependencyProvider = new NamedCacheDependencyProvider(); _applicationHostContext = new ApplicationHostContext( hostServices, _projectDirectory, options.PackageDirectory, options.Configuration, _targetFramework, cache, cacheContextAccessor, namedCacheDependencyProvider); Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory); Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory); Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory); _project = _applicationHostContext.Project; if (Project == null) { throw new Exception("Unable to locate " + Project.ProjectFileName); } if (options.WatchFiles) { var watcher = new FileWatcher(_applicationHostContext.RootDirectory); _watcher = watcher; watcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } else { _watcher = NoopWatcher.Instance; } _applicationHostContext.AddService(typeof(IApplicationShutdown), _shutdown); // TODO: Get rid of this and just use the IFileWatcher _applicationHostContext.AddService(typeof(IFileMonitor), _watcher); _applicationHostContext.AddService(typeof(IFileWatcher), _watcher); if (options.CompilationServerPort.HasValue) { // Using this ctor because it works on mono, this is hard coded to ipv4 // right now. Mono will eventually have the dualmode overload var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, options.CompilationServerPort.Value)); var networkStream = new NetworkStream(socket); _applicationHostContext.AddService(typeof(IDesignTimeHostCompiler), new DesignTimeHostCompiler(_shutdown, _watcher, networkStream), includeInManifest: false); // Change the project reference provider Project.DefaultLanguageService = new TypeInformation( typeof(DefaultHost).GetTypeInfo().Assembly.GetName().Name, typeof(DesignTimeHostProjectReferenceProvider).FullName); } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; }