只是为了明确并关闭这个问题。这是检查 VS 是否正在关闭的代码快照:
// Create 2 variables below
private DTE2 m_applicationObject = null;
DTEEvents m_packageDTEEvents = null;
然后在初始化中添加:
// Link the Event when VS CLOSING
m_packageDTEEvents = ApplicationObject.Events.DTEEvents;
m_packageDTEEvents.OnBeginShutdown += new _dispDTEEvents_OnBeginShutdownEventHandler(HandleVisualStudioShutDown);
您需要的另外两种方法:
public DTE2 ApplicationObject
{
get
{
if (m_applicationObject == null)
{
// Get an instance of the currently running Visual Studio IDE
DTE dte = (DTE)GetService(typeof(DTE));
m_applicationObject = dte as DTE2;
}
return m_applicationObject;
}
}
和
public void HandleVisualStudioShutDown()
{
MessageBox.Show("Exiting Visual Studio. Bye");
}