c#代码自动修改解决方案下任意文件实例
命名空间
using envdte;
using envdte80;
private dte2 _applicationobject;
public void autoaddcontrol(插件 v_form1)
{
//得到当前文件的名称
string v_pathfile = _applicationobject.activedocument.fullname;
//打开文件 "form1.designer.cs"
if (!(v_pathfile.endswith(".cs")))
{
messagebox.show("当前文件不是.cs文件");
return;
}
v_pathfile = system.io.path.changeextension(v_pathfile, ".designer.cs");
_applicationobject.itemoperations.openfile(v_pathfile);
string v_file = system.io.path.getfilename(v_pathfile);
_applicationobject.windows.item(v_file).activate();
//修改文件内容 "form1.designer.cs"
document v_doc = _applicationobject.activedocument;
textselection selection = (textselection)_applicationobject.activedocument.selection;
selection.selectall();
string v_text = selection.text;
v_text = v_form1.changedoc1(v_text);
selection.selectall();
selection.text = "";
selection.insert(v_text);
//保存文件 "form1.designer.cs"
_applicationobject.activedocument.save();
_applicationobject.executecommand("window.closedocumentwindow");
//vssavechangesyes保存并关闭当前活动窗体
//_applicationobject.activewindow.close(vssavechanges.vssavechangesyes);
}