diff options
author | Jose <jose@zeroc.com> | 2013-03-08 15:42:18 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2013-03-08 15:42:18 +0100 |
commit | b87aa2d75dcaedceb7c9957bb93fe00b618d2a91 (patch) | |
tree | 40432f9ac2966bfc933c0327cc31fb17a8dae577 | |
parent | Fixed (ICE-5303) VSADDIN does not compile (diff) | |
download | ice-b87aa2d75dcaedceb7c9957bb93fe00b618d2a91.tar.bz2 ice-b87aa2d75dcaedceb7c9957bb93fe00b618d2a91.tar.xz ice-b87aa2d75dcaedceb7c9957bb93fe00b618d2a91.zip |
Fixed ICE-5306 - VS addin NullReferenceException
-rw-r--r-- | vsaddin/src/Builder.cs | 67 | ||||
-rw-r--r-- | vsaddin/src/Util.cs | 3 |
2 files changed, 52 insertions, 18 deletions
diff --git a/vsaddin/src/Builder.cs b/vsaddin/src/Builder.cs index e632522f684..3fa9384c7b7 100644 --- a/vsaddin/src/Builder.cs +++ b/vsaddin/src/Builder.cs @@ -178,31 +178,31 @@ namespace Ice.VisualStudio { _debugStartEvent = application.Events.get_CommandEvents(c.Guid, c.ID); _debugStartEvent.BeforeExecute += - new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironment); + new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentStartupProject); } else if(c.Name.Equals("Debug.StepInto")) { _debugStepIntoEvent = application.Events.get_CommandEvents(c.Guid, c.ID); _debugStepIntoEvent.BeforeExecute += - new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironment); + new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentStartupProject); } else if(c.Name.Equals("ClassViewContextMenus.ClassViewProject.Debug.StepIntonewinstance")) { _debugStepIntoNewInstance = application.Events.get_CommandEvents(c.Guid, c.ID); _debugStepIntoNewInstance.BeforeExecute += - new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironment); + new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentActiveProject); } else if (c.Name.Equals("Debug.StartWithoutDebugging")) { _debugStartWithoutDebuggingEvent = application.Events.get_CommandEvents(c.Guid, c.ID); _debugStartWithoutDebuggingEvent.BeforeExecute += - new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironment); + new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentStartupProject); } else if (c.Name.Equals("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance")) { _debugStartNewInstance = application.Events.get_CommandEvents(c.Guid, c.ID); _debugStartNewInstance.BeforeExecute += - new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironment); + new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentActiveProject); } else if (c.Guid.Equals(Util.refreshCommandGUID) && c.ID == Util.refreshCommandID) { @@ -525,12 +525,21 @@ namespace Ice.VisualStudio } } - public void setDebugEnvironment(string Guid, int ID, object obj, object CustomOut, ref bool done) + public void setDebugEnvironmentStartupProject(string Guid, int ID, object obj, object CustomOut, ref bool done) + { + setDebugEnvironment(getStartupProject()); + } + + public void setDebugEnvironmentActiveProject(string Guid, int ID, object obj, object CustomOut, ref bool done) + { + setDebugEnvironment(getActiveProject()); + } + + public void setDebugEnvironment(Project project) { try { - Project project = getActiveProject(); - if(Util.isSliceBuilderEnabled(project)) + if(project != null && Util.isSliceBuilderEnabled(project)) { if(Util.isCppProject(project)) { @@ -2087,17 +2096,31 @@ namespace Ice.VisualStudio return Util.getSelectedProject(_applicationObject.DTE); } - public Project getActiveProject() + public Project getStartupProject() { - Array projects = null; try { - if(_applicationObject.ActiveSolutionProjects != null) + Array projects = (Array)_applicationObject.Solution.SolutionBuild.StartupProjects; + Project p = Util.getProjectByNameOrFile(_applicationObject.Solution, projects.GetValue(0) as String); + if (p != null) { - projects = (Array)_applicationObject.ActiveSolutionProjects; - if(projects != null && projects.Length > 0) + return p; + } + } + catch (COMException) + { + // + // Ignore could happen if called while solution is being initialized. + // + } + + try + { + if(_applicationObject.Solution.Projects != null) + { + if(_applicationObject.Solution.Projects != null && _applicationObject.Solution.Projects.Count > 0) { - return projects.GetValue(0) as Project; + return _applicationObject.Solution.Projects.Item(1) as Project; } } } @@ -2108,12 +2131,21 @@ namespace Ice.VisualStudio // } + return null; + } + + public Project getActiveProject() + { + Array projects = null; try { - projects = (Array)_applicationObject.Solution.SolutionBuild.StartupProjects; - if(projects != null && projects.Length > 0) + if(_applicationObject.ActiveSolutionProjects != null) { - return projects.GetValue(0) as Project; + projects = (Array)_applicationObject.ActiveSolutionProjects; + if(projects != null && projects.Length > 0) + { + return projects.GetValue(0) as Project; + } } } catch(COMException) @@ -2139,6 +2171,7 @@ namespace Ice.VisualStudio // Ignore could happen if called while solution is being initialized. // } + return null; } diff --git a/vsaddin/src/Util.cs b/vsaddin/src/Util.cs index 6eba2099f05..bded2381568 100644 --- a/vsaddin/src/Util.cs +++ b/vsaddin/src/Util.cs @@ -3148,7 +3148,8 @@ namespace Ice.VisualStudio List<Project> projects = getProjects(solution); foreach(Project p in projects) { - if(p.Name.Equals(name) || + if(p.UniqueName.Equals(name) || + p.Name.Equals(name) || Path.GetFullPath(Path.Combine(Path.GetDirectoryName(solution.FullName), name)).Equals( Path.GetFullPath(p.FullName))) { |