Run script when finished saving file - Visual Studio Extensibility

后端 未结 1 1357
醉话见心
醉话见心 2021-01-27 13:20

Can someone give me some sample code for Visual Studio Extensibility where I can grab the text from a document, when the Save event ends, and run a script in C # with that text

相关标签:
1条回答
  • 2021-01-27 13:41

    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.

    0 讨论(0)
提交回复
热议问题