我想寫一個Visual Studio的加載項,需要在加載解決方案時運行。最終我希望將它作爲一個解決方案插件,以便它只運行需要它的解決方案,但是我想知道是否有任何方法讓用戶加載解決方案時使用我的加載項鉤子?解決方案加載的Visual Studio插件鉤
謝謝。
我想寫一個Visual Studio的加載項,需要在加載解決方案時運行。最終我希望將它作爲一個解決方案插件,以便它只運行需要它的解決方案,但是我想知道是否有任何方法讓用戶加載解決方案時使用我的加載項鉤子?解決方案加載的Visual Studio插件鉤
謝謝。
VCProjectEngineEvents
SolutionLoaded
事件。
編輯:我只能希望別人能拿出一個他們可以發佈的樣本 - 唯一相關的代碼是我不能發佈的東西。
可以使用Saver add-in source code爲例(它是一個附加的標籤Studio插件):
在Saver.cs您訂閱的事件:
solutionEventsSink = new SolutionEventsSink(orderController);
System.IServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
vsSolution = ServiceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsSolution)) as Microsoft.VisualStudio.Shell.Interop.IVsSolution;
vsSolution.AdviseSolutionEvents(solutionEventsSink, out sinkCookie);
在SolutionEventsSink.cs是實際解決事件處理程序:
class SolutionEventsSink : Microsoft.VisualStudio.Shell.Interop.IVsSolutionEvents
太棒了!儘管我對C#有點不熟悉,那麼我可能會因爲一個註冊鉤子的例子而煩惱嗎?謝謝。 – coppro