private void ButtonBrowse_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Visual Studio project files (*.csproj)|*.csproj|All files (*.*)|*.*"; dialog.Title = "Please select a Visual Studio project file."; if (dialog.ShowDialog() == true) { string fullPathOfCSProj = dialog.FileName; Microsoft.Build.Evaluation.Project project; string projectName; Context.ProjectType projectType; Context.ProjectOutputType projectOutputType; if (TryLoadProjectFromCsproj(fullPathOfCSProj, out project, out projectName, out projectType, out projectOutputType)) { // If the selected project is not of a compatible type, ask for confirmation: if (projectType != Context.ProjectType.Other || System.Windows.MessageBox.Show("The selected project does not appear to be of a supported type (Silverlight, WPF...). Would you like to migrate it anyway?", "Please confirm", MessageBoxButton.OKCancel) != MessageBoxResult.Cancel) { // Check if the selected project has already been added to the list: bool alreadyAdded = false; foreach (Context.ProjectModel projectModel in _context.AllProjects) { if (projectModel.FullPathOfCSProj.ToLower() == fullPathOfCSProj.ToLower()) { alreadyAdded = true; break; } } if (!alreadyAdded) { // Create a new model for the project: var newProjectModel = new Context.ProjectModel() { Name = projectName, FullPathOfCSProj = fullPathOfCSProj, ProjectLoadedWithMsBuild = project, IsSelected = true, DestinationName = AppendCSHTML5ToProjectName(projectName), DestinationProjectType = "CSHTML5", ProjectType = projectType, ProjectOutputType = projectOutputType }; // Add the project: _context.AllProjects.Add(newProjectModel); _context.CandidateProjectsToMigrate.Add(newProjectModel); // Refresh the list of projects: ProjectsDataGrid.ItemsSource = null; ProjectsDataGrid.ItemsSource = _context.CandidateProjectsToMigrate; // Make sure the newly added project is selected: ProjectsDataGrid.SelectedItems.Add(newProjectModel); } else { MessageBox.Show("The selected project is already present in the list."); } } } } }
public Page_ChooseTheProjects(Context context) { InitializeComponent(); _context = context; // Clear the list of projects: _context.AllProjects.Clear(); _context.CandidateProjectsToMigrate.Clear(); // Check if we are running inside VS: if (_context.Solution != null) { // Get the list of projects: List <EnvDTE.Project> allProjects = AllSolutionProjectsSearcher.GetAllProjects(_context.Solution); // Process the list of projects: foreach (EnvDTE.Project project in allProjects) { // Get project information (path, type, etc.): string fullPathOfCSProj; Context.ProjectType projectType; Context.ProjectOutputType projectOutputType; GetProjectInformation(project, context.Solution, out fullPathOfCSProj, out projectType, out projectOutputType); // Create a new model for the project: var projectModel = new Context.ProjectModel() { Name = project.Name, FullPathOfCSProj = fullPathOfCSProj, ProjectLoadedWithEnvDTE = project, IsSelected = false, DestinationName = AppendCSHTML5ToProjectName(project.Name), DestinationProjectType = "CSHTML5", ProjectType = projectType, ProjectOutputType = projectOutputType }; // Add the project: _context.AllProjects.Add(projectModel); // If the project is of type "Silverlight" and the other information is ok, it is a valid candidate for the migration: if (projectType == Context.ProjectType.Silverlight && projectOutputType != Context.ProjectOutputType.Unknown) { _context.CandidateProjectsToMigrate.Add(projectModel); } } // Diplay the candidate projects: ProjectsDataGrid.ItemsSource = _context.CandidateProjectsToMigrate; } else { ProjectsDataGrid.ItemsSource = new List <Context.ProjectModel> { new Context.ProjectModel() { Name = "Test1" }, new Context.ProjectModel() { Name = "Test2" } }; } }