Getting a project’s GUID

OK, this was much harder than it should have been. I was in the process of creating my own custom Silverlight project templates (I don’t consider the default template usable since it requires you to put your business entities in the host web project!).

Anyway, the host web project needs to get a reference to the Silverlight project–specifically the project’s GUID. Here are the steps you need to take to get this information:

  1. Install the Visual Studio 2010 SDK:
  2. Add these assemblies to your project:

    – Microsoft.VisualStudio.Shell.Interop
    – Microsoft.VisualStudio.OLE.Interop

  3. Now you can use the following code to retrieve a project’s GUID:


    Guid projectGuid= Guid.Empty;


    IVsHierarchy hierarchy;


    IServiceProvider serviceProvider = new ServiceProvider(project.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);


    IVsSolution solution = serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsSolution)) as IVsSolution;


    out hierarchy);


    if (hierarchy != null)
    out projectGuid);

Kevin McNeish
President, Oak Leaf Enterprises, Inc.
INETA Speaker
Eight-time recipient Microsoft .NET MVP Award
Chief Software Architect, MM .NET Application Framework

One thought on “Getting a project’s GUID

  1. Hi Kevin,

    Where did you put this code? Did you place it in your IWizard implementation..maybe in the ProjectItemFinishedGenerating method?



Leave a Reply to Myles J Cancel reply

Your email address will not be published. Required fields are marked *