I'm a programmer in the game industry. I blog primarily about tools and rendering but my posts can run the gamut of my experience so they can be very diverse and awesome. I was a tools programmer for Gamebryo in the past, currently doing interesting animation and machine learning work at Activate3D for the Kinect. I'd like to think of myself as a tools programmer but I wear all kinds of hats. I'm talking beanies, Kangols, fedoras... Scarves, babushkas... Baseball caps, beanies. Yarmulkes.
Posts by Nick Darnell
  1. Oxel: A Tool for Occluder Generation ( Counting comments... )
  2. Global Game Jam 2012 Wrap-Up ( Counting comments... )
  3. Creating Kinect Controls for Angry Birds ( Counting comments... )
  4. Kinect, Anthropometry and You ( Counting comments... )
  5. Making Your Files Merge Friendly ( Counting comments... )
  6. Robust Inside and Outside Solid Voxelization ( Counting comments... )
  7. Trip Report: Gamefest 2011 – Seattle ( Counting comments... )
  8. SWIG: Casting Revisited ( Counting comments... )
  9. Project Photofly Experiment ( Counting comments... )
  10. How I Organize Research ( Counting comments... )
  11. Hierarchical Z-Buffer Occlusion Culling - Generating Occlusion Volumes ( Counting comments... )
  12. Extend Visual Studio! ( Counting comments... )
  13. SWIG and a Miss ( Counting comments... )
  14. Do the Truffle Shuffle to Start ( Counting comments... )
  15. Chaining Compute Shaders ( Counting comments... )
  16. Subsurface Scattering Volumes ( Counting comments... )
  17. Teaching the Toaster to Feel Love [Part 2] ( Counting comments... )
  18. Teaching the Toaster to Feel Love [Part 1] ( Counting comments... )
  19. Redneck Cloud Computing ( Counting comments... )
  20. Documentation [Easy Mode] ( Counting comments... )
  21. The Art of the 48 Hour Game ( Counting comments... )

The Pitch

I don’t want to show you how to add a command button or toolbar to Visual Studio, there are plenty of examples out there for that. I want to provide you with an example showing how writing a Visual Studio extension could benefit your studio’s workflow.

Andy Firth wrote an article on #AltDevBlogADay a few days ago on Extending the Watch Window in Visual Studio via autoexp.dat. It’s a nice introduction article to modifying the autoexp.dat file to auto-expand and format variables in the watch window.

Now, if I take a bunch of time designing a nice formatter to speed up my debugging sessions how do I share it across the company?

Well, the only way is for you to manually merge other peoples additions to the AutoExp.dat file into your own. Which inevitably leads to varying levels of adoption of the formatters and debugging times suffer as a result.

Lets fix this!

We’re going to write an extension to patch the AutoExp.dat file with one collocated with the solution file.


Getting Started

new_vs_packageAfter downloading the Visual Studio 2010 SP1 SDK  you’ll create a new solution using the Visual Studio Package template.  You could have also chosen the Add-in template.  Though the packages are basically just as easy to install in Visual Studio 2010 and they offer much more control should you end up needing it.

The code you’ll start out with will be a bit more verbose than this, but here’s the important bit to get started playing with different capabilities.  Visual Studio is based on a loose coupling service architecture, so to accomplish anything useful you’ll need to find the the service that handles it.  Luckily Microsoft has documented the List of Services.  If I had to pick the “main” service it would be the DTE service.  It manages the majority of the functionally you’ll be interested in playing with.

public sealed class MyPackage : Package
    private DTE m_dte;
    protected override void Initialize()
        // Your package is also a service container
        IServiceContainer serviceContainer = this as IServiceContainer;
        // The DTE object contains most of the goodies you'll want to play with
        m_dte = serviceContainer.GetService(typeof(SDTE)) as DTE;
        // I could also add a service of my own if I wanted
        // serviceContainer.AddService(typeof(MyService), new MyService(), true);


The AutoExp.dat Patcher

Because we’ve decided to look for an AutoExp.dat patcher file beside the solution, lets hook some events so that we know when the solution is opened and closed.

// Must hold a reference to the solution events object or the events wont 
// fire, garbage collection related
m_solutionEvents = m_dte.Events.SolutionEvents;
m_solutionEvents.Opened += SolutionOpened;
m_solutionEvents.AfterClosing += SolutionAfterClosing;
// Most of the events you'll find useful are catagoried under 
// DTE.Events...

Now when the solution is opened we’re going to scan for the patcher file in the same directory as the solution file and we’re going to use it to modify the AutoExp.dat file.

void SolutionOpened()
    string slnFile = m_dte.Solution.FullName;
    string solutionDirectory = Path.GetDirectoryName(slnFile);
    string pathfileName = Path.GetFileNameWithoutExtension(slnFile) + ".autoexp";
    string patchFile = Path.Combine(solutionDirectory, pathfileName);
    if (File.Exists(patchFile))
        string autoExpPatch = File.ReadAllText(patchFile);
        string autoExpPath = Environment.ExpandEnvironmentVariables(
        string blockBegin = "; BEGIN AEP [AutoExpand] (" + pathfileName + ")";
        string blockEnd = "; END AEP [AutoExpand] (" + pathfileName + ")";
        // What follows is a bunch string parsing code that's not relevant to the article.
        // (1) We remove the previous auto expansion block we added, if we added one 
        //     in another session.
        // (2) We insert the new auto expansion patched section from our 
        //     SOLUTION_FILE_NAME.autoexp file.
        // (3) Save the new AutoExp.dat file.

Because our extension isn’t triggered by a command and doesn’t have a UI we need to make sure Visual Studio loads our extension from the start.  You accomplish this by adding the ProvideAutoLoad attribute to the Package class, with the right GUID identifying the time to load the extension.

// --- Microsoft.VisualStudio.VSConstants.UICONTEXT_NoSolution
public sealed class AutoExpPatchPackage : Package



In our test solution I'm going to start without any patch file and this is what I see when hovering over the test variable.


After we add the patch file though and reload the solution we see something completely different.

TestStruct =x=<x,g>, y=<y,g>, z=<z,g>


Voilà we’ve created a simple extension to Visual Studio that could actually improve workflow.  We can now check-in our patcher file into source control, allowing us to share our rules with all of our fellow employees.

The extension I wrote only handles the [AutoExpand] section of the AutoExp.dat file.  With a little bit of work though you could easily handle the other sections.

You could also add some other improvements such as removing the patched portions after the solution is closed to make sure there are no conflicts between versions, if you work on multiple versions of the codebase.

Another improvement would be to automatically re-patch the AutoExp.dat file if you detect a change to the patcher file while the solution is open.



You can download the source code for the AutoExp.dat Patcher here.



Extend Visual Studio! @ nickdarnell.com