Run script when finished saving file - Visual Studio Extensibility

我只是一个虾纸丫 提交于 2019-12-02 11:56:11

You can subscribe to the DocumentSaved event:

    events = DTE.Events;
    documentEvents = events.DocumentEvents;
    documentEvents.DocumentSaved += OnDocumentSaved;

In the OnDocumentSaved handler with EnvDTE.Document you can get the document path as doc.FullName.

To get text from EnvDTE.Document:

  TextDocument td = (TextDocument)(doc.Object("TextDocument"));
  var p = td.StartPoint.CreateEditPoint();
  string s = p.GetText(td.EndPoint);

See In VisualStudio DTE, how to get the contents of the ActiveDocument? and https://vlasovstudio.com/visual-commander/extensions.html for complete samples.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!