public static IList <ProjectItem> GetProjectItems(this Solution solution) { IList <Project> dteProjects = new List <Project>(); try { dteProjects = solution.GetProjects(); _cachedProjects = dteProjects; } catch (Exception ex) { LogManager.ForContext <Solution>().Error(ex, "Failed to get projectitems for solution {FullName}", solution?.FullName); } var projectItems = new List <ProjectItem>(dteProjects.Count); foreach (var project in dteProjects) { try { //var msBuildProject = project.GetMsBuildProject(); var projectItem = new ProjectItem(); UpdateProperties(project, projectItem); projectItems.Add(projectItem); } catch (Exception ex) { LogManager.ForContext <Solution>().Error(ex, "Failed to update project properties for solution {FullName}", solution?.FullName); } } return(projectItems); }
private static void UpdateNameProperties(Project project, ProjectItem projectItem) { try { projectItem.UniqueName = project.UniqueName; projectItem.Name = project.Name; projectItem.FullName = project.FullName; if (IsIntegrationServicesProject(project, projectItem)) { AdjustUniqueNameForExtensionProjects(project, projectItem); } try { projectItem.FullPath = string.IsNullOrWhiteSpace(projectItem.FullName) ? null : Path.GetDirectoryName(projectItem.FullName); } catch (SystemException ex) { // PathTooLongException, ArgumentException (invalid characters). LogManager.ForContext <Solution>().Error(ex, "Failed because path has been to long for {UniqueName}", project?.UniqueName); projectItem.FullPath = null; } projectItem.SolutionFolder = project.GetTreePath(false) ?? @"\"; // TODO: SolutionPath = project.GetTreePath(true); } catch (Exception ex) { LogManager.ForContext <Solution>().Error(ex, "Failed to update name properties for {UniqueName}", project?.UniqueName); } }
private static void AdjustUniqueNameForExtensionProjects(Project project, ProjectItem projectItem) { var directory = Path.GetDirectoryName(project.UniqueName); var directoryName = Path.GetFileName(directory); var csprojName = Path.GetFileName(project.UniqueName); projectItem.UniqueName = Path.Combine(directoryName, csprojName); }
private bool GetProjectItem(BuildProjectContextEntry projectEntry, out ProjectItem projectItem) { projectItem = projectEntry.ProjectItem; if (projectItem != null) { return(true); } string projectFile = projectEntry.FileName; if (ProjectExtensions.IsProjectHidden(projectFile)) { return(false); } IDictionary <string, string> projectProperties = projectEntry.Properties; var project = _viewModel.ProjectsList.FirstOrDefault(x => x.FullName == projectFile); if (BuildScope == BuildScopes.BuildScopeBatch && projectProperties.ContainsKey("Configuration") && projectProperties.ContainsKey("Platform")) { string projectConfiguration = projectProperties["Configuration"]; string projectPlatform = projectProperties["Platform"]; projectItem = FindProjectItemInProjectsByUniqueName(project.UniqueName, projectConfiguration, projectPlatform); if (projectItem == null) { TraceManager.Trace( string.Format("Project Item not found by: UniqueName='{0}', Configuration='{1}, Platform='{2}'.", project.UniqueName, projectConfiguration, projectPlatform), EventLogEntryType.Warning); return(false); } } else { projectItem = FindProjectItemInProjectsByUniqueName(project.UniqueName); if (projectItem == null) { TraceManager.Trace(string.Format("Project Item not found by FullName='{0}'.", projectFile), EventLogEntryType.Warning); return(false); } } projectEntry.ProjectItem = projectItem; return(true); }
public ProjectItem AddProjectToVisibleProjectsByUniqueName(string uniqueName, string configuration, string platform) { ProjectItem currentProject = _viewModel.SolutionItem.AllProjects.FirstOrDefault(item => item.UniqueName == uniqueName && item.Configuration == configuration && PlatformsIsEquals(item.Platform, platform)); if (currentProject == null) { currentProject = _viewModel.SolutionItem.AllProjects.FirstOrDefault(x => x.UniqueName == uniqueName); if (currentProject == null) { throw new InvalidOperationException(); } currentProject = currentProject.GetBatchBuildCopy(configuration, platform); _viewModel.SolutionItem.AllProjects.Add(currentProject); } _viewModel.ProjectsList.Add(currentProject); return(currentProject); }
private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action) { if (action == vsBuildAction.vsBuildActionDeploy) { return; } RegisterLogger(); CurrentBuildState = BuildState.InProgress; BuildStartTime = DateTime.Now; BuildFinishTime = null; BuildAction = (BuildActions)action; switch (scope) { case vsBuildScope.vsBuildScopeSolution: case vsBuildScope.vsBuildScopeBatch: case vsBuildScope.vsBuildScopeProject: BuildScope = (BuildScopes)scope; break; case 0: // Scope may be 0 in case of Clean solution, then Start (F5). BuildScope = (BuildScopes)vsBuildScope.vsBuildScopeSolution; break; default: throw new ArgumentOutOfRangeException("scope"); } if (scope == vsBuildScope.vsBuildScopeProject) { var projContext = _activeProjectContext; switch (projContext.Type) { case vsWindowType.vsWindowTypeSolutionExplorer: ////var solutionExplorer = (UIHierarchy)dte.Windows.Item(Constants.vsext_wk_SProjectWindow).Object; var solutionExplorer = (UIHierarchy)projContext.Object; var items = (Array)solutionExplorer.SelectedItems; switch (items.Length) { case 0: TraceManager.TraceError("Unable to get target projects in Solution Explorer (vsBuildScope.vsBuildScopeProject)"); BuildScopeProject = null; break; case 1: var item = (UIHierarchyItem)items.GetValue(0); var hierachyProjectItem = new ProjectItem(); ViewModelHelper.UpdateProperties((Project)item.Object, hierachyProjectItem); BuildScopeProject = hierachyProjectItem; break; default: BuildScopeProject = null; break; } break; case vsWindowType.vsWindowTypeDocument: var projectItem = new ProjectItem(); ViewModelHelper.UpdateProperties(projContext.Project, projectItem); BuildScopeProject = projectItem; break; default: throw new InvalidOperationException("Unsupported type of active project context for vsBuildScope.vsBuildScopeProject."); } } _buildCancelled = false; _buildCancelledInternally = false; BuildedProjects.Clear(); lock (_buildingProjectsLockObject) { BuildingProjects.Clear(); } BuildedSolution = null; var solution = _packageContext.GetDTE().Solution; BuildingSolution = new BuildedSolution(solution.FullName, solution.FileName); OnBuildBegin(this, EventArgs.Empty); _buildProcessCancellationToken = new CancellationTokenSource(); Task.Factory.StartNew(BuildEvents_BuildInProcess, _buildProcessCancellationToken.Token, _buildProcessCancellationToken.Token); }
private static bool IsIntegrationServicesProject(Project project, ProjectItem projectItem) { return(project.Kind == _GUID_SQL_INTEGRATIONG_SERVICES_PROJECT_KIND ? projectItem.UniqueName == projectItem.FullName : false); }
public static void UpdateProperties(Project project, ProjectItem projectItem, string configuration = null, string platform = null) { if (project != null) { object projObject; try { projObject = project.Object; } catch (Exception ex) { LogManager.ForContext <Solution>().Error(ex, "Failed to load project.Object for project {UniqueName}", project?.UniqueName); projObject = null; } try { if (projObject == null) { projectItem.UniqueName = project.UniqueName; projectItem.Name = project.Name; return; } UpdateNameProperties(project, projectItem); projectItem.Language = project.GetLanguageName(); projectItem.CommonType = ProjectExtensions.GetProjectType(project.Kind, project.DTE.Version /* "12.0" */); } catch (Exception ex) { LogManager.ForContext <Solution>().Error(ex, "Failed to updatename properties project properties for project {UniqueName}", project?.UniqueName); } #region Set ActiveConfiguration (Configuration and Platform) if (configuration != null && platform != null) { projectItem.Configuration = configuration; projectItem.Platform = platform; } else { Configuration config; try { config = project.ConfigurationManager?.ActiveConfiguration; } catch (Exception ex) { LogManager.ForContext <Solution>().Error(ex, "Failed to get active configuration for {UniqueName}", project?.UniqueName); config = null; } if (config != null) { projectItem.Configuration = config.ConfigurationName; projectItem.Platform = config.PlatformName; } else { if (project.ConfigurationManager == null) { LogManager.ForContext <Solution>().Warning("ConfigurationManager for project {UniqueName} was null.", project?.UniqueName); } else if (project.ConfigurationManager.ActiveConfiguration == null) { LogManager.ForContext <Solution>().Warning("ActiveConfiguration for project {UniqueName} was null.", project?.UniqueName); } projectItem.Configuration = @"N\A"; projectItem.Platform = @"N\A"; } } #endregion try { projectItem.Framework = project.GetFrameworkString(); var flavourTypes = project.GetFlavourTypes().ToList(); projectItem.FlavourType = string.Join("; ", flavourTypes); projectItem.MainFlavourType = flavourTypes.FirstOrDefault(); projectItem.OutputType = project.GetOutputType(); projectItem.ExtenderNames = project.GetExtenderNames(); projectItem.RootNamespace = project.GetRootNamespace(); } catch (Exception ex) { LogManager.ForContext <Solution>().Error(ex, "Failed to load settings for project {UniqueName}", project?.UniqueName); } } }
private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action) { if (action == vsBuildAction.vsBuildActionDeploy) { return; } RegisterLogger(); CurrentBuildState = BuildState.InProgress; BuildStartTime = DateTime.Now; BuildFinishTime = null; BuildAction = (BuildActions)action; switch (scope) { case vsBuildScope.vsBuildScopeSolution: case vsBuildScope.vsBuildScopeBatch: case vsBuildScope.vsBuildScopeProject: BuildScope = (BuildScopes)scope; break; case 0: // Scope may be 0 in case of Clean solution, then Start (F5). BuildScope = (BuildScopes)vsBuildScope.vsBuildScopeSolution; break; default: throw new ArgumentOutOfRangeException("scope"); } if (scope == vsBuildScope.vsBuildScopeProject) { var selectedProjects = _packageContext.GetDTE().ActiveSolutionProjects as object[]; if (selectedProjects?.Length == 1) { var projectItem = new ProjectItem(); ViewModelHelper.UpdateProperties((Project)selectedProjects[0], projectItem); BuildScopeProject = projectItem; } } _buildCancelled = false; _buildCancelledInternally = false; BuildedProjects.Clear(); lock (_buildingProjectsLockObject) { BuildingProjects.Clear(); } BuildedSolution = null; var solution = _packageContext.GetDTE().Solution; BuildingSolution = new BuildedSolution(solution.FullName, solution.FileName); OnBuildBegin(this, EventArgs.Empty); _buildProcessCancellationToken = new CancellationTokenSource(); Task.Factory.StartNew(BuildEvents_BuildInProcess, _buildProcessCancellationToken.Token, _buildProcessCancellationToken.Token); }