I'm trying to handle Visual Studio shutdown in my add-in. The problem is once the shutdown has started various DTE objects methods will no longer work and will instead trigger COMExceptions with E_FAIL error code and so the add-in can no longer work properly.
I therefore need to somehow detect the moment when the shutdown is initiated. There're EnvDTE.DTE.Events.SolutionEvents and EnvDTE.DTE.Events.DTEEvents classes but all the events inside them are marked "infrastructure only" so it looks like I shouldn't subscribe to them.
What's the right way to detect that Visual Studio has started to shut down and so DTE is no longer fully usable?
Visual Studio provides QueryClose method to handle the VS shut down in VS packages.
To use this, override this method in your Package class, and do the actions you want to perform during the shutdown.
Related
I have noticed a frustrating problem during which a standard Winform control will not enter a drag-drop operation during a debug session as it should after calling the control's DoDragDrop method. The source control (from which the drag-drop operation is initiated) acts as if it doesn't support drag-and-drop.
In my case, it turns out that I was running a debug session in a second instance of Visual Studio 2017. When I stopped running that second debug-session instance of Visual Studio (I was able to keep Visual Studio open, I just had to stop my debug session), the drag operation in the first debug-session instance of Visual Studio began working as expected.
Clearly, drag-and-drop should work in two debug sessions open at the same time in two different Visual Studio instances--and sometimes it does on my system. But occasionally something happens (I'm not yet sure what) to "corrupt" the VS IDE or the .NET subsystem that causes a Winform drag operation from no longer functioning.
This behavior occurs even after rebooting and happens in the latest VS Enterprise 2017 IDE (Ver 15.5.6) with .NET 4.7.02556.
I realize that this problem and its solution is rather nebulous but I felt it was enough to be useful here (and I invested a lot of time figuring out what was going on!).
I am writing a VSPackage and want to support starting multiple debugger sessions with a single keypress. Does anyone have any insight into how I can get access to another process's IServiceProvider? Each debugging session runs in it's own Visual Studio process instance.
I'm targeting Visual Studio 2013
Kirill’s blog post outlines how to connect to another instance of VS here:
https://blogs.msdn.microsoft.com/kirillosenkov/2011/08/10/how-to-get-dte-from-visual-studio-process-id/
You can talk from another process to VS through all of the interfaces in the EnvDTE.dll once you have the DTE object from the Running Object Table.
Can I create an extension for Visual Studio that runs in the background as soon as the user opens the Visual Studio IDE? For example, I am building an extension that gets the current active file address in Visual Studio (with C#), but I would like this extension to always run in the background without having to be activated by the user clicking a button or pressing some key combination.
Is this possible, and if so, what is the best way of doing it?
Any help would be greatly appreciated! Regards, Erfan
Since you tagged your question with visual-studio-2010 I assume you are working on an "Add-in" rather than a "VSPackage Extensions".
In this case, you can use the OnConnection event handler.
If you are working on a VSPackage Extensions, you can use the attribute ProvideAutoLoad.
Just search for these, you will find sufficient information. Both ways are also described shortly here under "How can I run my add-in code in a VSPackage?"
For Extension add following attribute to Package class, this will load the extension when a solution is not open in visual studio. I have tested this with VS 2015 and 2017.
[ProvideAutoLoad(UIContextGuids80.NoSolution)]
For VS 2010 and higher the recommended extensibility approach is a package (VS 2015 won't allow add-ins).
To get the package loaded when Visual Studio is loaded see HOWTO: Autoload a Visual Studio package.
Once loaded, your package may be interested in two different kind of selection change events:
To get notified when the selection in the Solution Explorer changes, get the IVsMonitorSelection interface and call the AdviseSelectionEvents/UnadviseSelectionEvents and provide a class that implements the IVsSelectionEvents interface.
To get notified when the active window changes (which can be a document window or a toolwindow), implement the IVsWindowFrameNotify interface.
In my VS add-in, I need to handle key presses (presumably via PreTranslateAccelerator()) before Visual Studio does. Unfortunately, after digging in Shell.Interop, I can't find the location where I would be able to handle them. Can anyone help?
In my project, I use IOleCommandTarget interface to intercept key press in visual studio. There is a method named "QueryStatus" after you implement the IOleCommandTarget. I think you can use this method to handle keypress before visual studio does. You can also decide whether transfer msg chain to VS. I found this article that may help you.http://www.ngedit.com/a_intercept_keys_visual_studio_text_editor.html
which project use to create event receiver for sharepoint 2007 list - sequential workflow or state workflow? i'm using VS 2010
Neither.
Workflows are events which are run via the SharePoint Timer service and can be executed by any server in the farm.
An event receiver is essentially an event handler that will be executed either synchronously or asynchronously (depending on which event you're implementing) on the same server which handled the request that triggered the event receiver.
Visual Studio 2010 does not have much OOTB support for SharePoint 2007. You might consider installing the WSP Builder extensions (note that the proper download is not the recommended download - you'll need the 2010 BETA 1.4). They give new project types which include event receivers. Note though that there are some quirks with those project types but overall they are very helpful to getting the project set up correctly.
Be sure to read the documentation regarding the folder/file layout of your projects. If done correctly, you can use WSPBuilder to generate your WSPs for you.
A quick search revealed this blog post which might help get you started with regard to project structure. I'm sure there are many, many more references available. Happy coding!