user2423986
user2423986

Reputation: 39

Get path of project created in experimental Instance of Visual Studio

I am developing a Visual Studio extension package. Every time I test run, an experimental instance of VS opens up. I created a project in the experimental instance; how can I get the path of the project created in the experimental instance?

Upvotes: 0

Views: 151

Answers (2)

The first thing you should import EnvDTE (in EnvDTE.dll). Then I declared property ProejectFullName

string ProejectFullName{ get; }

A string representing the full path and name of the project object’s file.

public void GetmyFilePath(DTE2 dte)

{  
    try
    {   // Open a project before running this sample.
        Project prj = dte.Solution.Projects.Item(1);
        Projects prjs;


string msg, msg2 = "Global Variables:";
    msg = "FileName: " + prj.FileName;
    msg += "\nProejectFullName: " + prj.ProejectFullName;
    msg += "\nProject-level access to " + prj.CodeModel.CodeElements.Count.ToString() +
        " CodeElements through the CodeModel";
    prjs = prj.Collection;
    msg += "\nThere are " + prjs.Count.ToString() + " projects in the same collection.";
    msg += "\nApplication containing this project: " + prj.DTE.Name;
    if (prj.Saved)
        msg += "\nThis project hasn't been modified since the last save.";
    else
        msg += "\nThis project has been modified since the last save.";
    msg += "\nProperties: ";
    foreach (Property prop in prj.Properties)
    {
        msg += "\n  " + prop.Name;
    }
    foreach (String s in (Array)prj.Globals.VariableNames)
    {
        msg2 += "\n  " + s;
    }

    MessageBox.Show(msg, "Project Name: " + prj.Name);
    MessageBox.Show(msg2);
}
catch(Exception ex)
{
    MessageBox.Show(ex.Message);
}
}

Upvotes: 0

Carlos Quintero
Carlos Quintero

Reputation: 4414

Given the IVsHierarchy object that represents the project hierarchy, you can use the VSITEMID_ROOT id when calling the GetProperty method with the VSHPROPID_ProjectDir / VSHPROPID_Name properties.

Alternatively, if you have an EnvDTE.Project, then you can use the EnvDTE.Project.FullName property.

Upvotes: 1

Related Questions