Logo
BUG: Toolwindow guid attribute value hardcoded in code generated by Visual Studio package wizard

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2010
Date: February 2015   Microsoft Visual Studio 2012
      Microsoft Visual Studio 2013

Introduction

When you use the Visual Studio Package wizard to create a package with a toolwindow, the following code is generated:

  • In the Guids.cs file, GuidList class, a constant such as the following is declared:

    public const string guidToolWindowPersistanceString = "f28795f3-04f8-435f-972d-97e172e1a10c"
  • In the MyToolWindow.cs file, MyToolWindow class, the class is decorated with a Guid attribute that hardcodes the guid value:

[Guid("f28795f3-04f8-435f-972d-97e172e1a10c")]
public class MyToolWindow : ToolWindowPane

As a result, the constant is unused in the whole code and the guid value is duplicated. The best practice is to use the constant in the Guid attribute:

[Guid(GuidList.guidToolWindowPersistanceString)]
public class MyToolWindow : ToolWindowPane

More Information

This is a bug in the code templates that the package wizard uses:

  • VB.NET: \VSSDK\VisualStudioIntegration\Tools\Wizards\Templates\1033\VB\MyToolWindow.vb
  • C#: \VSSDK\VisualStudioIntegration\Tools\Wizards\Templates\1033\CS\MyToolWindow.cslWindow.cs

which use (C#):

[Guid("%ToolGuid%")]
public class MyToolWindow : ToolWindowPane

instead of:

[Guid(GuidList.guidToolWindowPersistanceString)]
public class MyToolWindow : ToolWindowPane



Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)