Debug an Excel template in Visual Studio - visual-studio

I have been working on an Excel 2010 template for some time and I am quite satisfied with it. But the problem is that when I save the file and then reopen it, sometimes Excel crashes and I have no way to know what happens...
The issue is that it is easy to debug the template at its first start as it always debug with a fresh template. But it is not possible to debug the file when you reopen it from the explorer. I want to analyse the behavior of the program when I open a file created from the original template. Is there a way to achieve that?
Thanks.

I found out myself. When I open my Excel file from the explorer, I just need to attach the EXCEL.EXE process to Visual Studio in Tools > Attach to Process...
That was that simple. The only drawback is that I cannot hook on the startup events as Excel needs to appear in the processes list to be attached to Visual Studio.

Related

Creating Visual Studio AddIn run error

This has been happening to me over and over for every single AddIn project I make.
I create the AddIn projet from the template wizard and work on it, coding and debugging for a few hours and then all of a sudden I get:
Error 1 Unable to copy file "obj\Debug\Project1.dll" to "bin\Project1.dll". The process cannot access the file 'bin\Project1.dll' because it is being used by another process.
Does anyone know what is this about?
Happening in VS2008 and VS2010.
Thank you
*Edit: I have found a workaround by closing all instances of VS, deleting the Project1.dll file, selecting NO when VS asks me if I want to delete a reference to the AddIn when opening VS instance again.
I actually came across this today and it took me forever to figure it out. For me I was creating an Addin that automatically loaded when Visual Studio starts. The way I fixed it was by going to:
Tools -> Add-in Manager
Then uncheck the first checkbox near your addin. Keep the "Startup" checkbox checked to continue having debugging of your Addin.
Hope this helps.

Open test results from a Visual Studio extension

I have a Visual Studio extension that runs tests in an external service and gets the results back as a .trx file. In the extension code, how do I display the Test Results window and open the result file there? Similarly as would happen if I clicked the .trx file externally.
Not loading the data into the window directly, but a more general solution is to open the file through ItemOperations:
DTE dte = (DTE)GetService(typeof(DTE));
dte.ItemOperations.OpenFile(pathToTheTrx);
This will of course work with any type of file Visual Studio identifies.
ten years later, I’m doing a very similar thing, I have figured out how to load tests into VS2022 into the test results explorer, but now I’m trying to figure out how to open a selected test directed to the file and line it’s located at.
I wonder if this is even possible, or if that kind of functionality is hidden from end users.

How can I close all the document windows in Visual Studio from an external script?

I'm creating the software for a course. What with exercise start points and worked solutions and both C# and VB I have about 100 VS2010 solutions.
During development I reopen these as neccessary and they get a lot of tweaking. When I'm done I want to leave the solutions with NO documents open. That way when the student opens the solution it's a very clean view, not littered with the files I was last looking at.
Up to VS2008 this was was easy. I simply deleted all the *.suo files - that seems to be where VS stores the window layout. When a solution was opened VS happily created a new SUO file. This approach was suggested in Close all files in visual studio on exit
With VS2010 this causes an annoying dialog...
Security warning for You should only open projects from a trustworthy source
This is completely reproducible.
Open one of the solutions, for which there is no SUO file
VS gives a trust warning. User accepts it. SUO file is created.
Subsequent opening of the SLN don’t report trust problems.
Delete the SUO file.
Reopen the SLN and the trust errors reoccurs.
How can I achieve my ambition of having VS open up with no document windows open, and no security dialog? I really want it to be automated from OUTSIDE VS. Opening all of 100 solutions and manually closing the windows is NOT what I'm looking for.
It's pretty easy to create a macro that will close all windows, but I cannot see a way of starting VS from the command line and getting it to run a macro on startup.
This sounds like you downloaded the project file from an untrusted source. Scott Hanselman wrote a blog post about it. The short story is that if you go to the properties page for the project file (windows explorer -> right click project file -> properties), you can unblock the file with the button at the bottom:

Modify a solution to not load projects from outside of visual studio

If I open a solution, unload a project then reopen the solution visual studio remembers not to not load the project again.
How can I do this outside of visual studio? Which file is this setting stored in?
Visual Studio's annoying conversion wizard won't let me open the solution without converting all the projects, I have already converted the ones I want to work with and want to set the other ones to be unloaded so I am not prompted to convert them.
[edit] As an alternative as the SUO file contains this information which I cannot edit, is there a way to tell visual studio to open a solution but to not load any of the projects? This would be quite useful to know anyway, to quickly open a large solution with many projects.
Its in the Solution User Options file (.suo) which is binary. So you likely won't find an easy way to set it there.

Why would my Visual Studio 2008 close everytime I open a .xaml file?

Visual Studio 2008 has been very stable for months on my computer.
This morning when I double-click on any .xaml file to open it, or even click on the tab of an already opened .xaml file, Visual Studio says "initializing toolbar" in the status bar and then 20 seconds later fully closes the whole application without any error message.
Other files (e.g. .cs class files) I can open fine.
Has anyone experience this or know what I could check/change to be able to use Visual Studio to edit .xaml files again?
MORE INFO: I can also create a new project and create and edit .xaml files fine.
MORE INFO: I can edit .xaml files in other modules (projects) fine.
MORE INFO: Everytime it crashes, this event is registered:
.NET Runtime version 2.0.50727.3053 - Fatal Error in executable module (72555E00) (80131506).
(odd since I have .NET framework 3.5 installed)
MORE INFO: It is only in one module (project) that .xaml files cause Visual Studio to crash. Even creating a new UserControl in that module crashes Visual Studio.
I get this occasionally (with .xaml and .resx files) and find that if I delete the solutions .suo file things work fine again.
[The suo file just contains per user settings like recently opened files etc so it's nothing important and will just be recreated when you next open the solution.]
I've been getting the same issue whenever I try to access project settings for a C# project.
Found additional information about this:
Here: http://blog.fryhard.com/archive/2008/11/26/visual-studio-2008-closes-at-build-outlook-2007-add-in.aspx
And here: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/99e124d0-c5d7-49c0-b1dd-71328f9a6571/
Apparently it's a bug in the core CLR engine that causes the entire CLR to crash if certain types of assemblies are loaded in a certain order.
Most of the time it appears to be directly related to the Visual Studio add-in called PowerCommands - uninstalling PowerCommands will make the problem go away.
And (we hope) it's supposed to be fixed for .Net 4.
This sounds very similar to the issue I had when I first installed VS 2008. Unfortunately, after hours of research, I ended up reinstalling the IDE (with my fingers crossed). No problems since then, but it's obviously not the most enjoyable way to solve the problem.
What is likely happening here is that one of the controls referenced directly on indirectly in your designer is stack overflowing during the designer process. Because the designer is hosted in process a stack overflow by one of the components will take down the designer and VS.
Try attaching a debugger to VS, break on first chance StackOverflow Exceptions and open the designer.

Resources