Contact

admin

About Me · Send mail to the author(s) E-mail · Twitter

At GROSSWEBER we practice what we preach. We offer trainings for modern software technologies like Behavior Driven Development, Clean Code and Git. Our staff is fluent in a variety of languages, including English.

Feed Icon

Tags

Open Source Projects

Archives

Blogs of friends

Now playing [?]

Error retrieving information from external service.
Audioscrobbler/Last.fm

ClustrMap

Removing AnkhSVN Commands from Visual Studio

Posted in Visual Studio at Thursday, September 21, 2006 11:49 PM W. Europe Daylight Time

When you install Subversion 1.4.0 on the server and also TortoiseSVN on the client machine, the first time TortoiseSVN touches the repository on the server (for example by showing the log) the local working copy is upgraded to the new format.

Once a working copy is upgraded AnkhSVN, the Visual Studio Add-In for Subversion support refuses to attach to the the solution.

AnkSVN Error

Obviously AnkhSVN is out of date, so you're going to remove it using the uninstaller. The next time you open Visual Studio all traces of AnkhSVN will be gone, right? Unfortunately this is not the case. As you can see in the screenshot below, there's a entry left over in the main menu and several other items in the context menu of the Solution Explorer, all grayed out.

Remaining AnkhSVN Menus

Removing the main menu entry is fairly easy using View/Toolbars/Customize... But how to modify the context menu to get rid those items? The AnkhSVN wiki proposes resetting Visual Studio to the defaults. I believe there's a better solution.

In case you don't want to lose your IDE customizations you may use the VBA macro that does the job by enumerating all Visual Studio toolbars and commands and deleting the ones that start with "Ankh". The script takes a while to run, but wipes all menu items related to AnkhSVN. Tested on Visual Studio .NET 2003 and Visual Studio 2005 after uninstalling AnkhSVN.

Imports System
Imports EnvDTE
Imports System.Diagnostics
' Comment the following line if you're running the macro in Visual Studio .NET 2003.
Imports Microsoft.VisualStudio.CommandBars
Imports Microsoft.Office.Core
 
Public Module RemoveAnkhMenus
    Public Sub RemoveAnkhMenus()
        DeleteAnkhCommandControls()
        DeleteAnkhCommands()
    End Sub
 
    Private Sub DeleteAnkhCommandControls()
        For Each bar As CommandBar In CType(DTE.CommandBars, CommandBars)
            ' Debug.WriteLine(String.Format("Processing : {0}", GetPath(bar)))
 
            RecurseCommandControls(bar.Controls)
        Next
    End Sub
 
    Private Sub RecurseCommandControls(ByVal controls As CommandBarControls)
        For Each control As CommandBarControl In controls
            ' Debug.WriteLine(String.Format("Processing : {0}", GetPath(control)))
 
            ' Recurse childs.
            If control.accChildCount > 0 Then
                If control.Type = MsoControlType.msoControlPopup Then
                    RecurseCommandControls(CType(control, CommandBarPopup).Controls)
                End If
            End If
 
            ' Delete the control if it is related to AnkhSVN.
            DeleteAnkhCommandControl(control)
        Next
    End Sub
 
    Private Sub DeleteAnkhCommandControl(ByVal control As CommandBarControl)
        ' Delete control if it is related to AnkhSVN.
        If control.Caption.StartsWith("Ankh") Then
            Debug.WriteLine(String.Format("Deleting control: {0}", GetPath(control)))
            control.Delete()
        End If
    End Sub
 
    Private Sub DeleteAnkhCommands()
        ' Delete all commands related to AnkhSVN.
        For Each command As Command In DTE.Commands
            If command.Name <> Nothing Then
                If command.Name.StartsWith("Ankh") Then
                    Debug.WriteLine(String.Format("Deleting command: {0}", command.Name))
                    command.Delete()
                End If
            End If
        Next
    End Sub
 
    Private Function GetPath(ByVal control As Object) As String
        If TypeOf (control) Is CommandBarControl Then
            Dim cbc As CommandBarControl
            cbc = CType(control, CommandBarControl)
 
            Return GetPath(cbc.Parent) + "->" + cbc.Caption
        End If
 
        If TypeOf (control) Is CommandBar Then
            Dim cb As CommandBar
            cb = CType(control, CommandBar)
 
            Return GetPath(cb.Parent) + "->" + cb.Name
        End If
 
        Return "DTE"
    End Function
End Module

DownloadDownload the macro file here.

Monday, September 25, 2006 3:20:57 PM (W. Europe Daylight Time, UTC+02:00)
Great to see a macro handle this.

Code similiar to this exists in an msi custom action class in the msi installer. The problem is that it never really worked. We are looking into another way to prevent the problem (removing the commands when then addin is unloaded), but that doesn't help older versions.

PS: Ankh 1.0 RC3 will handle your subversion 1.4.0 working copy
Sander Rijken
Monday, September 25, 2006 3:29:01 PM (W. Europe Daylight Time, UTC+02:00)
Hi Sander,

doesn't the custom action inside the MSI package would have to be run for every user and not just for the one performing the uninstall?

I see another problem with command removal on exit: What if the user decides to put the Ankh menu somewhere else or simply renames (localizes) the items? Then you would end up in two menus.

Alex
Tuesday, September 26, 2006 4:07:06 PM (W. Europe Daylight Time, UTC+02:00)
We only remove the underlying commands, not the UI. VS is supposed to delete all associated UI when a command is deleted.

Since commands cannot be localized or customized, and aren't user-specific, the caveats you mention shouldn't apply.

In theory.
Tuesday, September 26, 2006 6:28:19 PM (W. Europe Daylight Time, UTC+02:00)
Do you remove the underlying commands for every user or just for the one that uninstalls AnkhSVN? I'm working in a LUA environment so I believe the uninstaller doesn't even know about my VS profile and the AnkhSVN commands therein.

That VS removes the menu items once the commands are deleted may be the case, but obviously not for the Admin/LUA/multiuser scenario. Perhaps this scenario isn't seen very often today, I provide the macro for those who don't run their machine under the administrator account all the time.
Sunday, January 20, 2008 8:53:31 PM (W. Europe Standard Time, UTC+01:00)
Hi Alex, I tried this on VS 2008 but VS crashes. Have you tested this on VS 2008 lately?
Al
Sunday, January 20, 2008 11:06:08 PM (W. Europe Standard Time, UTC+01:00)
Al, I didn't test on VS 2008. What's the error message you see?
Saturday, February 23, 2008 7:03:06 PM (W. Europe Standard Time, UTC+01:00)
Hi,
It worked on my VS2008, but when solution explorer was closed.
The only one issue left - it didn't remove "Ankh ->" group menu item from the Solution explorer. The group is empty and menu is grayed out, but anyway I don't like this.

Thanks,
Vladimir
Vladimir
Saturday, February 23, 2008 7:24:10 PM (W. Europe Standard Time, UTC+01:00)
Vladimir, you might want to try this.
Sunday, February 24, 2008 3:18:25 AM (W. Europe Standard Time, UTC+01:00)
Thanks a lot, that worked.
Vladimir
Monday, May 05, 2008 1:58:25 AM (W. Europe Daylight Time, UTC+02:00)
Which twat failed to write a proper uninstaller? This manual uninstall business is ridiculous.
meat
Monday, May 05, 2008 9:48:08 AM (W. Europe Daylight Time, UTC+02:00)
Depends on how you look at it. An uninstaller that runs as Administrator is not really able to modify VS settings (that's where menu the customizations are stored) of other user accounts.
All comments require the approval of the site owner before being displayed.
(will show your gravatar icon)
 
[Captcha]Enter the code shown (prevents robots):

Live Comment Preview