Archives

Archives / 2006 / March
  • Simple but handy VS2005 macro for C# code navigation

    Frequently while navigating code in VS2005, I want to go to the definition of the type of a variable. For example, say you're looking at a line of code like this:
    ...
    aVariable = DoSomethingThatReturnsOneOfThese();
    ...

    And you want to jump to the source for the type of aVariable (that is, if aVariable is of type SomeClass, you want to jump the source for SomeClass). As far as I can see, Visual Studio doesn't give you a simple command that does that navigation. So here's a simple macro that does it.

       Sub GoToVariableType()
          DTE.ExecuteCommand("Edit.GoToDefinition")
          DTE.ActiveDocument.Selection.WordLeft()
          DTE.ExecuteCommand("Edit.GoToDefinition")
       End Sub

    Trivial but effective, and it saves me a couple of keystrokes. I map this macro to CTRL-F12 (a shortcut which as far as I can tell is only used by C++ projects).

    Note that this only works if you don't declare multiple variables in one declaration statement. For example, it works with declarations like this:

    SomeClass aVariable;

    but not this:

    SomeClass aVariable, anotherVariable;

  • Satellite assemblies and strong names

    I recently had to investigate how to create satellite resource assemblies for assemblies that are strongly named. Some of the information was surprisingly poorly documented, and required some experimentation to figure out, so I'm posting the results in the hope it might save other people some time.

    Here's what I learned:

    • Satellite assemblies for strong named assemblies must be strong named.

      OK, not that surprising.

    • Satellite assemblies for strong named assemblies must be signed with the same key as the main assembly.

      This is actually a bit of a pain for my company, because we use localization partners that in the past have been able to localize the product pretty much independently from us. With our .NET code, we'll have to sign the final satellite assemblies. Fortunately, the localizers can use  delay signing with skip verification to do all of their development and testing, and we just need to do the final signing.

    • By default, satellite assemblies must have the same version number as the main assembly. You can use the SatelliteContractVersionAttribute to enable the main assembly to be versioned while still maintainng compatibility with existing satellite assemblies (thanks to Joe for pointing out this atttribute).