我正在开发一个 Visual Studio 扩展包。每次我测试运行时,都会打开一个 VS 的实验实例。我在实验实例中创建了一个项目;如何获取在实验实例中创建的项目的路径?
问问题
122 次
2 回答
1
给定表示项目层次结构的IVsHierarchy对象,您可以在使用VSHPROPID_ProjectDir / VSHPROPID_Name 属性调用GetProperty方法时使用 VSITEMID_ROOT id 。
或者,如果您有EnvDTE.Project,则可以使用EnvDTE.Project.FullName属性。
于 2015-03-22T16:49:45.277 回答
0
首先应该导入 EnvDTE(在 EnvDTE.dll 中)。然后我声明了属性 ProejectFullName
string ProejectFullName{ get; }
表示项目对象文件的完整路径和名称的字符串。
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);
}
}
于 2018-03-29T07:53:17.793 回答