public static void LaunchInNewAppDomain(NuGetDomainStartOptions options) { // Find services platform var platformAssemblyFile = Path.Combine(options.ApplicationBase, typeof(ConsoleApplicationHost).Assembly.GetName().Name + ".dll"); if (!File.Exists(platformAssemblyFile)) { throw new InvalidOperationException("Unable to locate NuGet.Services.Platform.dll in base directory!"); } // Create the AppDomain var setup = new AppDomainSetup() { ApplicationBase = options.ApplicationBase }; var domain = AppDomain.CreateDomain("NuGetServices", null, setup); dynamic agent = domain.CreateInstanceFromAndUnwrap( platformAssemblyFile, typeof(ConsoleApplicationHost).FullName); try { agent.Run(options); } catch (AggregateException aex) { Console.WriteLine(aex.InnerException.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public async Task RunAsync(NuGetDomainStartOptions options) { try { ResolveAssembliesFromDirectory(options.HostApplicationBase); // Load all assemblies in my app domain foreach (var dllFile in Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")) { try { Assembly.Load(Path.GetFileNameWithoutExtension(dllFile)); } catch (Exception) { // Ignore load failures here } } var app = NuGetApp.Create(options); Console.WriteLine(Strings.ConsoleApplicationHost_Running); app.EventStream.Subscribe(ev => { Console.WriteLine("[{0}]({1:000}) {2}", ev.Schema.ProviderName, ev.EventId, ev.FormattedMessage); }); app.Initialize(); if (!await app.Start()) { Console.WriteLine(Strings.ConsoleApplicationHost_FailedToStart); } else { Console.CancelKeyPress += (sender, args) => { args.Cancel = true; app.Shutdown(); }; await app.Run(); } } catch (AggregateException aex) { Console.WriteLine(aex.InnerException.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public async Task RunAsync(NuGetDomainStartOptions options) { try { ResolveAssembliesFromDirectory(options.HostApplicationBase); // Load all assemblies in my app domain foreach (var dllFile in Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")) { try { Assembly.Load(Path.GetFileNameWithoutExtension(dllFile)); } catch (Exception) { // Ignore load failures here } } var app = NuGetApp.Create(options); Console.WriteLine(Strings.ConsoleApplicationHost_Running); app.EventStream.Subscribe(ev => { Console.WriteLine("[{0}]({1:000}) {2}", ev.Schema.ProviderName, ev.EventId, ev.FormattedMessage); }); app.Initialize(); if (!await app.Start()) { Console.WriteLine(Strings.ConsoleApplicationHost_FailedToStart); } else { Console.CancelKeyPress += (sender, args) => { args.Cancel = true; app.Shutdown(); }; await app.Run(); } } catch (AggregateException aex) { Console.WriteLine(aex.InnerException.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void Run(NuGetDomainStartOptions options) { RunAsync(options).Wait(); }
private void LoadAndStartApp(Arguments parsed, NuHostConfig config) { // Create start options NuGetDomainStartOptions options = new NuGetDomainStartOptions() { HostApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase, ApplicationBase = parsed.BaseDirectory }; if (!String.IsNullOrEmpty(parsed.Configuration)) { options.Configuration = JsonConvert.DeserializeObject<Dictionary<string, string>>(parsed.Configuration); } options.AppDescription = new ServiceHostDescription( ServiceHostInstanceName.Parse("nuget-local-0-nuhost_IN" + Process.GetCurrentProcess().Id.ToString()), Environment.MachineName); if (parsed.Services != null) { options.Services = parsed.Services.ToList(); } var urls = parsed.Urls ?? NuGetApp.GetUrls(parsed.HttpPort, parsed.HttpsPort, parsed.HttpPath, localOnly: true); foreach (var url in urls) { options.Urls.Add(url); } // Create the AppDomain var setup = new AppDomainSetup() { ApplicationBase = options.ApplicationBase, ConfigurationFile = config.ClrConfigFile }; var domain = AppDomain.CreateDomain("NuGetServices", null, setup); dynamic agent = domain.CreateInstanceAndUnwrap( "NuGet.Services.Platform", "NuGet.Services.Hosting.ConsoleApplicationHost"); try { agent.Run(options); } catch (AggregateException aex) { Console.WriteLine(aex.InnerException.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void Run(NuGetDomainStartOptions options) { RunAsync(options).Wait(); }
public static void LaunchInNewAppDomain(NuGetDomainStartOptions options) { // Find services platform var platformAssemblyFile = Path.Combine(options.ApplicationBase, typeof(ConsoleApplicationHost).Assembly.GetName().Name + ".dll"); if (!File.Exists(platformAssemblyFile)) { throw new InvalidOperationException("Unable to locate NuGet.Services.Platform.dll in base directory!"); } // Create the AppDomain var setup = new AppDomainSetup() { ApplicationBase = options.ApplicationBase }; var domain = AppDomain.CreateDomain("NuGetServices", null, setup); dynamic agent = domain.CreateInstanceFromAndUnwrap( platformAssemblyFile, typeof(ConsoleApplicationHost).FullName); try { agent.Run(options); } catch (AggregateException aex) { Console.WriteLine(aex.InnerException.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }