Open test results from a Visual Studio extension - visual-studio-2010

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.

Related

Viewing a VB6 file in Visual Studio 2010 without trying to "build" it

I have a C#/.Net 4.0 project in Visual Studio 2010. Parts of this project were originally from an old VB6 program that was converted to C#.
Sometimes I need to look at the old VB6 code side-by-side with the C# code, and so it's very convenient to just open and view the file in Visual Studio. V.S. even displays comments and keywords in appropriate colors for easy viewing. To open the VB6 file I'm doing a File>Open>File. The VB6 file has a .cls extension.
The problem is that when I do that it also tries to do background compilation of it, so as soon as I open it, it registers hundreds of errors because VB6 isn't a supported language and even if I do a Build Solution or Rebuild Solution it includes those results in the build so I can't build my C# project when the VB6 file is open.
1. Why does it do this, considering that the VB6 file is not part of the current solution or project?
2. How do I turn it off so I can view the file but not have Visual Studio try to compile it?
Why does it do this?
The cls extension is mapped to the Visual Basic language service. It will interpret any file with that extension as a VB.Net file and process it as such.
The Visual Basic Language service is always compiling files to a degree in the background. It doesn't actually produce EXE / DLL but will go far enough to provide semantic information to the front end. This is used in intellisense, code highlighting, error squiggles, etc ...
How do I turn it off?
Unfortunately you can't. Visual Basic background compilation is not configurable. Hence any file which it believes to be VB.Net code will be processed in the background and errors will be displayed.
The only way to view it without errors is to rename the file to an extension not thought to be VB.Net code (like txt)

Debug an Excel template in 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.

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:

Visual Studio Error: An item with the same key has already been added

When I'm trying to change the default Image of a Control on Windows Forms in Form Designer (no matter where on which control) I get this error:
Error message: An item with the same
key has already been added
I tried to delete and recreate the Resources.resx file.. I assured that only 1 resx file with these keys exist.. (in fact that's my only resource file) but it still does not work.
I have som strings in it and some images. That's all.
Any idea?
I had this problem too. The solution is to never create a .resx file with the name "Resources.resx" because it conflicts with the "Resources.resx" files that can be automatically created in the project's properties dialog.
Just right-click and rename the "Resources.resx" and you should be able to change images perfectly.
If you really want to figure out what is going wrong, you can try and attach a debugger to VS and break while devenv.exe is showing the message box. From the call stack it should be obvious what VS is doing. Here are more details about debugging Visual Studio: http://blogs.msdn.com/kirillosenkov/archive/2008/12/07/how-to-debug-crashes-and-hangs.aspx
If you like, you can post the call stack of the Visual Studio main thread here and I can try to investigate what is going on.
Was getting this error while adding a project to a solution. None of the above metioned scenarios applied but restarting visual studio fixed this. Silly, yes.
Visual studio version - 2015 enterprise.
I had the same issue. But in my case it was because I had twice the same file listed in my resources folder.
Probably a problem after a merge.

Visual Studio integrated custom MSBuild task behaviour

I was looking around the net for a NUnit custom MSBuild task that would run on every build and also nicely play with Visual Studio UI (2008 is my version). I found MSBuild.Community.Tasks project that was great, but failed in Visual Studio integration part.
What I actually wanted to have is get failed tests displayed as warnings/errors in VS's error list window (and also FAILED project build when tests are not successful). So I wrote my own custom MSBuild task that does the job exactly how I wanted it to be.
BUT.
The only problem that I have is that normal VS UI error list behaviour is that when you click on an error it jumps to appropriate source file and highlights the problematic code. I was able to relate file and line number with failed test however I wasn't able in any way to persuade Visual Studio to HIGHLIGHT problematic code for me (when I double click the error). All I get is cursor in the right spot.
I tried all kinds of combinations of line, endLine, column, endColumn method parameters (Log.LogError()), but to no avail. And based on error output by compiler errors it looks like it also provides just line and column (no end values).
Anybody ran against this oddity and solved it?
Update 13 May 2009
You can get this project for free (without method selection) at
http://code.google.com/p/nunitmsbuildvsintegrated/
For this feature, you must create Visual Studio Integrated Package that display custom panel in Visual Studio. This custom panel will be called when your project is built.
Visual Studio Extensibility Developer Center
I have no solution to your exact problem, but have some thoughts.
Are you sure you want to run a full suite of unit tests at the end of each and every build? I personally find it to be a productivity killer. Rather, while working with code I tend to run a small subset tests which cover only the code in question, and this is where tools like ReSharper or TestDriven.NET come into play.
(source: jetbrains.com)

Resources