源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-12-11 12:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c#代码自动修改解决方案下任意文件实例
命名空间
[u]复制代码[/u] 代码如下:
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);         }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部