protected override void OnStartup(StartupEventArgs e) { if (e.Args.Length == 0) { ShowErrorMessageBox("Builder not meant to be called directly. Use install-VS2017.bat instead."); Shutdown(); return; } var configuration = new CommandLineBuilderConfiguration(e.Args); var vsPath = configuration.VsPath; if (Directory.Exists(vsPath)) { Paths.VSPath = vsPath; Paths.UpdateVSPath(); } else { // For debugging, set params to something like this: // -VSPath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise ShowErrorMessageBox("Visual Studio path must be provided. (-VSPATH or /VSPATH)"); Shutdown(); return; } BuilderConfiguration = configuration; base.OnStartup(e); }
protected override void OnStartup(StartupEventArgs e) { if (Process.GetProcessesByName("Cosmos.Build.Builder").Skip(1).Any()) { ShowErrorMessageBox("Cannot run more than 1 instance of builder at the same time!"); return; } var configuration = new CommandLineBuilderConfiguration(e.Args); BuilderConfiguration = configuration; MainWindow = new MainWindow(); var visualStudioService = new VisualStudioService(); var visualStudioInstances = visualStudioService.GetInstances(); if (visualStudioInstances.Count == 0) { ShowErrorMessageBox("No Visual Studio instances found!"); return; } ISetupInstance2 visualStudioInstance = null; if (configuration.VsPath != null) { visualStudioInstance = visualStudioInstances.FirstOrDefault( i => String.Equals( Path.GetFullPath(configuration.VsPath), Path.GetFullPath(i.GetInstallationPath()), StringComparison.Ordinal)); } if (visualStudioInstance == null) { if (visualStudioInstances.Count == 1) { visualStudioInstance = visualStudioInstances[0]; } else { var visualStudioInstanceDialogViewModel = new VisualStudioInstanceDialogViewModel(visualStudioService); var visualStudioInstanceDialog = new VisualStudioInstanceDialog(); visualStudioInstanceDialog.DataContext = visualStudioInstanceDialogViewModel; var result = visualStudioInstanceDialog.ShowDialog(); if (!(result ?? false)) { Shutdown(); return; } visualStudioInstance = visualStudioInstanceDialogViewModel.SelectedVisualStudioInstance.SetupInstance; } } var innoSetupService = new InnoSetupService(); var msBuildService = new FullMSBuildService(visualStudioInstance); var dependencyInstallationDialogService = new DialogService <DependencyInstallationDialog, DependencyInstallationDialogViewModel>( () => new DependencyInstallationDialog(), MainWindow); var buildDefinition = new CosmosBuildDefinition(innoSetupService, msBuildService, visualStudioInstance); // show first, or setting owner on dialog windows may fail, as the main window may have not been shown yet. MainWindow.Show(); MainWindow.DataContext = new MainWindowViewModel(dependencyInstallationDialogService, buildDefinition); base.OnStartup(e); }