Kevin McNeish Blog

All things iOS, Kindle and .NET

Recent Posts

Tags

News

  • First books in my new book series, "iOS App Development for Non-Programmers" are now available! iBookStore: http://itunes.apple.com/us/book/book-1-diving-in-ios-app-development/id558788074?mt=11 Amazon: http://www.amazon.com/dp/B0097N8XBE Amazon: http://www.amazon.com/dp/B0099RQGMQ

Community

Email Notifications

Archives

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: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=47305cf4-2bea-43c0-91cd-1b853602dcc5&displaylang=en
  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;

    solution.GetProjectOfUniqueName(project.FullName,

    out hierarchy);

     

    if (hierarchy != null)
    {
       solution.GetGuidOfProject(hierarchy,
    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

Leave a Comment

(required) 

(required) 

(optional)
 

(required) 

If you can't read this number refresh your screen
Enter the numbers above: