Visual Studio Developer Center > Visual Studio Forums > Visual Studio Extensibility > How to guess if a VS 2005 project is a test project
Ask a questionAsk a question
 

AnswerHow to guess if a VS 2005 project is a test project

  • Monday, July 04, 2005 10:16 AMCarlos Quintero MVP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Test projects is VS 2005 seem to have 2 type GUIDs, according to the saved project TestProject1.vbproj:

    ...
       <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
     ...

    Given a EnvDTE.Project, how can I guess if it is a test project? Project.Kind seems to return {F184B08F-C81C-45F6-A57F-5ABD9991F28F}, which identifies a VB project. So, I assume that {3AC096D0-A1C2-E12C-1390-A8335801FDAB} identifies a test project, but how can I retrieve that property value from EnvDTE.Project?

    Thanks in advance,

    Carlos Quintero

Answers

  • Thursday, July 07, 2005 12:13 AMMike Wong Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Carlos,

    you are correct {3AC096D0-A1C2-E12C-1390-A8335801FDAB}  identifies the project flavor/subtype for a test project.  One approach could be to open the project file and get the xml element projecttypeguids.  Another approach would be to get the hierarchy and try to cast to IVsAggregatableProject. 

    You would need to download the VSIP SDK and reference some of the interop dlls in C:\Program Files\VSIP 8.0\EnvSDK\common\VSIA if you were working from an add-in.


    Here is some code from a package that describes the above. 

    Guid clsid = Guid.Empty;

    int result;

    Guid g = Guid.Empty;

    IVsSolution vsSolution = (IVsSolution)GetService(typeof(SVsSolution));

    IEnumHierarchies ppEnum;

    vsSolution.GetProjectEnum(1, ref g, out ppEnum);

    IVsHierarchy[] hier = new IVsHierarchy[1];

    uint ct;

    while (ppEnum.Next(1, hier, out ct) == 0)

    {

    Guid projGuid;

    object pVar;

    hier[0].GetGuidProperty(Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_TypeGuid, out projGuid)

    IVsAggregatableProject vsAggProj = hier[0] as IVsAggregatableProject;

    if (vsAggProj != null)
    {
    string
    strGuids;

    vsAggProj.GetAggregateProjectTypeGuids(out strGuids);
    strGuids.Split(....etc);
    strGuids will be a string of guids where the first one is the test project and the second the language project guid.

    From an add-in, we would do something like the following instead of the GetService call above

    Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)applicationObject;
    Guid g = new Guid(typeof(SVsSolution).GUID.ToString());
    IntPtr ptr;
    sp.QueryService(ref g, ref g, out ptr);

    IVsSolution vsSolution = (IVsSolution) Marshal.GetObjectForIUnknown(ptr);

    I hope that helps.  We should also submit a feature request to expose this via the DTE

    thanks!
    mike

All Replies

  • Thursday, July 07, 2005 12:13 AMMike Wong Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Carlos,

    you are correct {3AC096D0-A1C2-E12C-1390-A8335801FDAB}  identifies the project flavor/subtype for a test project.  One approach could be to open the project file and get the xml element projecttypeguids.  Another approach would be to get the hierarchy and try to cast to IVsAggregatableProject. 

    You would need to download the VSIP SDK and reference some of the interop dlls in C:\Program Files\VSIP 8.0\EnvSDK\common\VSIA if you were working from an add-in.


    Here is some code from a package that describes the above. 

    Guid clsid = Guid.Empty;

    int result;

    Guid g = Guid.Empty;

    IVsSolution vsSolution = (IVsSolution)GetService(typeof(SVsSolution));

    IEnumHierarchies ppEnum;

    vsSolution.GetProjectEnum(1, ref g, out ppEnum);

    IVsHierarchy[] hier = new IVsHierarchy[1];

    uint ct;

    while (ppEnum.Next(1, hier, out ct) == 0)

    {

    Guid projGuid;

    object pVar;

    hier[0].GetGuidProperty(Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_TypeGuid, out projGuid)

    IVsAggregatableProject vsAggProj = hier[0] as IVsAggregatableProject;

    if (vsAggProj != null)
    {
    string
    strGuids;

    vsAggProj.GetAggregateProjectTypeGuids(out strGuids);
    strGuids.Split(....etc);
    strGuids will be a string of guids where the first one is the test project and the second the language project guid.

    From an add-in, we would do something like the following instead of the GetService call above

    Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)applicationObject;
    Guid g = new Guid(typeof(SVsSolution).GUID.ToString());
    IntPtr ptr;
    sp.QueryService(ref g, ref g, out ptr);

    IVsSolution vsSolution = (IVsSolution) Marshal.GetObjectForIUnknown(ptr);

    I hope that helps.  We should also submit a feature request to expose this via the DTE

    thanks!
    mike