完成保存文件后运行脚本 - Visual Studio 扩展性 [英] Run script when finished saving file - Visual Studio Extensibility
问题描述
谁能给我一些 Visual Studio 扩展性的示例代码,我可以从文档中获取文本,当 Save 事件结束时,并使用该文本在 C# 中运行脚本(例如,触发某个文件的 Web 服务扩展名).它也可以是一个新按钮(例如,保存在网络服务中).
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 (example, trigger a Web service for certain file extensions). It could also be a new button (for example, save in the web service).
推荐答案
您可以订阅DocumentSaved事件:
events = DTE.Events;
documentEvents = events.DocumentEvents;
documentEvents.DocumentSaved += OnDocumentSaved;
在带有 EnvDTE.Document 的 OnDocumentSaved 处理程序中,您可以将文档路径设为 doc.FullName.
In the OnDocumentSaved handler with EnvDTE.Document you can get the document path as doc.FullName.
从 EnvDTE.Document 获取文本:
To get text from EnvDTE.Document:
TextDocument td = (TextDocument)(doc.Object("TextDocument"));
var p = td.StartPoint.CreateEditPoint();
string s = p.GetText(td.EndPoint);
参见 在 VisualStudio DTE 中,如何获取 ActiveDocument 的内容? 和 https://vlasovstudio.com/visual-commander/extensions.html 获取完整示例.
See In VisualStudio DTE, how to get the contents of the ActiveDocument? and https://vlasovstudio.com/visual-commander/extensions.html for complete samples.
这篇关于完成保存文件后运行脚本 - Visual Studio 扩展性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!