当前位置: 移动技术网 > IT编程>开发语言>c# > c#代码自动修改解决方案下任意文件实例

c#代码自动修改解决方案下任意文件实例

2019年07月18日  | 移动技术网IT编程  | 我要评论
命名空间复制代码 代码如下:using envdte;using envdte80; private dte2 _applicationobject;  

命名空间

复制代码 代码如下:

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);
        }

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网