C# 编写的插件,启动时如何获得宿主的路径,有多少分给多少

sky-defender 2009-09-07 10:32:17
比如一个工程存在C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\LineCounterAddIn下,启动插件的时候,插件该如何获得这个工程的目录并且遍历目录中的文件?
...全文
139 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
真相重于对错 2009-09-08
  • 打赏
  • 举报
回复
// Before running the following code, be sure that a Visual Basic 
// project is open in Visual Studio.
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;

// Pass the applicationObject member variable to the code example.
createProjectItem(_applicationObject);
}
public void createProjectItem(DTE2 dte)
{
//Adds a new Class to an existing Visual Basic project.
Solution2 soln;
Project prj;
soln = (Solution2)_applicationObject.Solution;
ProjectItem prjItem;
String itemPath;
// Point to the first project (the Visual Basic project).
prj = soln.Projects.Item(1);
// Retrieve the path to the class template.
itemPath = soln.GetProjectItemTemplate("Class.zip", "vbproj");
//Create a new project item based on the template, in this
// case, a Class.
prjItem = prj.ProjectItems.AddFromTemplate(itemPath, "MyNewClass");
}
sky-defender 2009-09-08
  • 打赏
  • 举报
回复
获得工程目录实现了

public void GlobalsExample(DTE2 dte)
{


// Get the path of the open solution

Solution soln = dte.Solution;
string solnName = Path.GetFileNameWithoutExtension(soln.FullName);


MessageBox.Show(soln.FullName);

}
  • 打赏
  • 举报
回复
学习
Jeff20040819 2009-09-08
  • 打赏
  • 举报
回复
UP
jbo126 2009-09-07
  • 打赏
  • 举报
回复
你可以把路径写在配置文件Settings.cs里呀,笨是笨点,但在你找到正克的方法前,不妨先这样用吧!
LeoMaya 2009-09-07
  • 打赏
  • 举报
回复
去参考SharpDevelop吧

110,578

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧