Share via


How to: Create a Visual Studio Add-In for the Web Performance Test Results Viewer

This topic applies to:

Visual Studio Ultimate

Visual Studio Premium

Visual Studio Professional 

Visual Studio Express

Topic applies Topic does not apply Topic does not apply Topic does not apply

You can extend the UI for the Web Performance Test Results Viewer by using the following namespaces:

Additionally, you need to add a reference to LoadTestPackage.dll which is located in the %ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies folder.

  • To extend the Web Performance Test Results Viewer's UI, you must create a Visual Studio add-in and a user control. The following procedures explain how to create the add-in, the user control, and how to implement the classes necessary to extend the Web Performance Test Results Viewer's UI.

Create or Open a Solution that Contains an ASP.NET Web Application and a Test Project

To prepare for extending the Web Performance Test Results Viewer

Create a Visual Studio Add-In

An add-in is a compiled DLL that runs in the Visual Studio integrated development environment (IDE). Compilation helps protect your intellectual property and improves performance. Although you can create add-ins manually, you may find it easier to use the Add-In Wizard. This wizard creates a functional but basic add-in that you can run immediately after you create it. After the Add-In Wizard generates the basic program, you can add code to it and customize it.

The Add-In Wizard lets you supply a display name and description for your add-in. Both will appear in Add-In Manager. Optionally, you can have the wizard generate code that adds to the Tools menu a command to open the add-in. You can also choose to display a custom About dialog box for your add-in. When the wizard is finished, you have a new project that has just one class that implements the add-in. That class is named Connect.

You will use the Add-In Manager at the end of this topic.

For more information, see Creating Add-ins and Wizards.

To create an add-in by using the Add-In Wizard

  1. In Solution Explorer, right-click the solution, click Add and then select New Project.

    The New Project dialog box is displayed.

  2. Under Installed Templates, expand Other Project Types and select Extensibility.

  3. In the list of templates, select Visual Studio Add-in.

  4. Under Name, type a name for the add-in. For example, WebPerfTestResultsViewerAddin.

  5. Click OK.

    The Visual Studio Add-in Wizard starts.

  6. Click Next.

  7. On the Select a Programming Language page, select the programming language that you want to use to write the add-in.

    Note

    This topic uses Visual C# for the sample code.

  8. On the Select An Application Host page, select Microsoft Visual Studio 2010 and clear Microsoft Visual Studio 2010 Macros.

  9. Click Next.

  10. Type a name and description for your add-in on the Enter a Name and Description page.

    After the add-in is created, its name and description are displayed in the Available Add-Ins list in Add-In Manager. Add enough detail to the description of your add-in so that users can learn what your add-in does, how it works, and so on.

  11. Click Next.

  12. On the Choose Add-In Options page, select I would like my Add-in to load when the host application starts.

  13. Clear the remaining check boxes.

  14. On the Choosing 'Help About' Information page, you can specify whether you want information about your add-in to be displayed in an About dialog box. If you do want the information to be displayed, select the Yes, I would like my Add-in to offer 'About' box information check box.

    Information that can be added to the Visual Studio About dialog box includes version number, support details, licensing data, and so forth.

  15. Click Next.

  16. The options that you selected are displayed on the Summary page for you to review. If you are satisfied, click Finish to create the add-in. If you want to change something, click the Back button.

    The new solution and project are created and the Connect.cs file for the new add-in is displayed in the Code Editor.

    You will add code to the Connect.cs file after the following procedure which creates a user control that will be referenced by this WebPerfTestResultsViewerAddin project.

After an add-in is created, you must register it with Visual Studio before it can be activated in Add-In Manager. You do this by using an XML file that has an .addin file name extension.

The .addin file describes the information that Visual Studio requires to display the add-in in Add-In Manager. When Visual Studio starts, it looks in the .addin file location for any available .addin files. If it finds any, it reads the XML file and gives Add-In Manager the information that it requires to start the add-in when it is clicked.

The .addin file is created automatically when you create an add-in by using the Add-In Wizard.

For more information, see Add-In Registration.

Add-In File Locations

Two copies of the .addin file are automatically created by the Add-In Wizard, as follows:

.Addin File Location

.Dll File Location

Description

Root project folder

\Documents\Visual Studio 2010\Projects\MyAddin1\MyAddin1\

Local path (MyAddin1.dll)

Used for deployment of the add-in project. Included in the project for ease of editing and has the local path for XCopy-style deployment.

Add-in folder

\Documents\Visual Studio 2010\Addins\

-or-

Shared Documents Location\Addins\

Project debug folder

(For example, \ Documents\Visual Studio 2010

Projects\MyAddin1\MyAddin1\bin\)

Used for running the add-in in the debugging environment. Should always point to the output path of the current build configuration.

Create a Windows Form Control Library Project

The Visual Studio add-in created in the previous procedure references a Windows Forms Control Library project to create an instance of a UserControl class.

For more information, see Windows Forms Controls.

To create a control to be used in the Web Test Results Viewer

  1. In Solution Explorer, right-click the solution, click Add and then select New Project.

    The New Project dialog box is displayed.

  2. Under Installed Templates, expand either Visual Basic or Visual C# and select Windows.

    Note

    This topic uses Visual C# for the sample code.

  3. In the list of templates, select Windows Forms Control Library.

  4. Under Name, type a name for the add-in. For example, WebPerfTestResultsViewerControl.

  5. Click OK.

    The Windows forms control library project WebPerfTestResultsViewerControl is added in Solution Explorer and UserControl1.cs is displayed in design mode.

  6. From the Toolbox, drag a DataGridView onto the surface of userControl1.

  7. Click the action tag glyph (Smart Tag Glyph) on the upper-right corner of the DataGridView and follow these steps:

    1. Click Dock in Parent Container.

    2. Clear the check boxes for Enable Adding, Enable Editing, Enable Deleting and Enable Column Reordering.

    3. Click Add Column.

      The Add Column dialog box is displayed.

    4. In the Type drop-down list, select DataGridViewTextBoxColumn.

    5. Clear the text "Column1" in Header text.

    6. Click Add.

    7. Click Close.

  8. In the Properties window, change the (Name) property of the DataGridView to resultControlDataGridView.

  9. Right-click the design surface and select View Code.

    The UserControl1.cs file is displayed in the Code Editor.

  10. Change the name of the instantiated UserControl class from UserContro1 to resultControl:

    namespace WebPerfTestResultsViewerControl
    {
        public partial class resultControl : UserControl
        {
            public resultControl()
            {
                InitializeComponent();
            }
    

    In the next procedure, you will add code to the WebPerfTestResultsViewerAddin project's Connect.cs file which will reference the resultControl class.

    You will be adding some additional code to the Connect.cs file later.

Add Code to the WebPerfTestResultsViewerAddin

To add code to the Visual Studio Add-in to extend the Web Test Results Viewer

  1. In Solution Explorer, right-click the References node in the WebPerfTestResultsViewerAddin project and select Add Reference.

  2. In the Add Reference dialog box, click the .NET tab.

  3. Scroll down and select Microsoft.VisualStudio.QualityTools.WebTestFramework and System.Windows.Forms.

  4. Click OK.

  5. Right-click the References node again, and select Add Reference.

  6. In the Add Reference dialog box, click the Browse tab.

  7. Click the drop-down for Look in and navigate to %ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies and select the Microsoft.VisualStudio.QualityTools.LoadTestPackage.dll file.

  8. Click OK.

  9. Right-click the WebPerfTestResultsViewerAddin project node, and select Add Reference.

  10. In the Add Reference dialog box, click the Projects tab.

  11. Under Project Name, select the WebPerfTestResultsViewerControl project and click OK.

  12. If the Connect.cs file is not still open, in Solution Explorer, right-click the Connect.cs file in the WebPerfTestResultsViewerAddin project and select View Code.

  13. In the Connect.cs file, add the following Using statements:

    using System.IO;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.LoadTesting;
    using Microsoft.VisualStudio.TestTools.WebTesting;
    using WebPerfTestResultsViewerControl;
    
  14. Scroll down to the bottom of the Connect.cs file. You need to add a list of GUIDs for the UserControl in case more than one instance of the Web Performance Test Results Viewer is open. You will add code later that uses this list.

    A second List of string is used in the OnDiscconection method which you will code later.

            private DTE2 _applicationObject;
            private AddIn _addInInstance;
    
            private Dictionary<Guid, List<UserControl>> m_controls = new Dictionary<Guid, List<UserControl>>();
            private List<string> temporaryFilePaths = new List<string>();
    
  15. The Connect.cs file instantiates a class named Connect from the IDTExtensibility2 class and also includes some methods for implementing the Visual Studio add-in. One of the methods is the OnConnection method, which receives notification that the add-in is being loaded. In the OnConnection method, you will use the LoadTestPackageExt class to create your extensibility package for the Web Performance Test Results Viewer. Add the following code to the OnConnection method:

    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
                {
                _applicationObject = (DTE2)application;
                _addInInstance = (AddIn)addInInst;
    
                // Create a load test packge extensibility class.
                LoadTestPackageExt loadTestPackageExt = _applicationObject.GetObject("Microsoft.VisualStudio.TestTools.LoadTesting.LoadTestPackageExt") as LoadTestPackageExt;
    
                // Process open windows.
                foreach (WebTestResultViewer webTestResultViewer in loadTestPackageExt.WebTestResultViewerExt.ResultWindows)
                {
                    WindowCreated(webTestResultViewer);
                }
    
                // Create event handlers.
                loadTestPackageExt.WebTestResultViewerExt.WindowCreated += new EventHandler<WebTestResultViewerExt.WindowCreatedEventArgs>(WebTestResultViewerExt_WindowCreated);
                loadTestPackageExt.WebTestResultViewerExt.WindowClosed += new EventHandler<WebTestResultViewerExt.WindowClosedEventArgs>(WebTesResultViewer_WindowClosed);
                loadTestPackageExt.WebTestResultViewerExt.SelectionChanged += new EventHandler<WebTestResultViewerExt.SelectionChangedEventArgs>(WebTestResultViewer_SelectedChanged);
            }
    
  16. Add the following code to the connect class to create the WebTestResultViewerExt_WindowCreated method for the loadTestPackageExt.WebTestResultViewerExt.WindowCreated event handler you added in the OnConnection method and for the WindowCreated method that the WebTestResultViewerExt_WindowCreated method calls.

            void WebTestResultViewerExt_WindowCreated(object sender, WebTestResultViewerExt.WindowCreatedEventArgs e)
            {
                // New control added to new result viewer window.
                WindowCreated(e.WebTestResultViewer);
            }
    
    private void WindowCreated(WebTestResultViewer viewer)
            {
                // Instantiate an instance of the resultControl referenced in the WebPerfTestResultsViewerControl project.
                resultControl resultControl = new resultControl();
    
                // Add to the dictionary of open playback windows.
                System.Diagnostics.Debug.Assert(!m_controls.ContainsKey(viewer.TestResultId));
                List<UserControl> userControls = new List<UserControl>();
                userControls.Add(resultControl);
    
                // Add Guid to the m_control List to manage Result viewers and controls.
                m_controls.Add(viewer.TestResultId, userControls);
    
                // Add tabs to the playback control.
                resultControl.Dock = DockStyle.Fill;
                viewer.AddResultPage(new Guid(), "Sample", resultControl);
            }
    
  17. Add the following code to the connect class to create the WebTestResultViewer_SelectedChanged method for the loadTestPackageExt.WebTestResultViewerExt.SelectionChanged event handler you added in the OnConnection method:

            void WebTestResultViewer_SelectedChanged(object sender, WebTestResultViewerExt.SelectionChangedEventArgs e)
            {
                foreach (UserControl userControl in m_controls[e.TestResultId])
                {
                    // Update the userControl in each result viewer.
                    resultControl resultControl = userControl as resultControl;
                    if (resultControl != null)
                        // Call the resultControl's Update method (This will be added in the next procedure).
                        resultControl.Update(e.WebTestRequestResult);
                }
            }
    
  18. Add the following code to the connect class to create the WebTesResultViewer_WindowClosed method for the event handler for the loadTestPackageExt.WebTestResultViewerExt.WindowClosed you added in the OnConnection method:

            void WebTesResultViewer_WindowClosed(object sender, WebTestResultViewerExt.WindowClosedEventArgs e)
            {
                if (m_controls.ContainsKey(e.WebTestResultViewer.TestResultId))
                {
                    m_controls.Remove(e.WebTestResultViewer.TestResultId);
                }
            }
    

    Now that the code has been completed for the Visual Studio add-in, you need to add the Update method to the resultControl in the in the WebPerfTestResultsViewerControl project.

Add Code to the WebPerfTestResultsViewerControl

For more information, see Windows Forms Control Development Basics.

To add code to the user control

  1. In Solution Explorer, right-click the WebPerfTestResultsViewerControl project node and select Properties.

  2. Select the Application tab and then click the Target framework drop-down list and select .NET Framework 4 and close the Properties.

    This is required in order to support the dll references that are needed for extending the Web Performance Test Results Viewer.

  3. In Solution Explorer, in the WebPerfTestResultsViewerControl project, right-click the References node and select Add Reference.

  4. In the Add Reference dialog box, click the .NET tab.

  5. Scroll down and select Microsoft.VisualStudio.QualityTools.WebTestFramework.

  6. Click OK.

  7. In the UserControl1.cs file, add the following Using statements:

    using Microsoft.VisualStudio.TestTools.WebTesting;
    using Microsoft.VisualStudio.TestTools.WebTesting.Rules;
    
  8. Add the Update method that is called and passed a WebTestRequestResult from the WebPerfTestResultsViewerAddin WebTestResultViewer_SelectedChanged method in the Connect.cs file. The Update method populates the DataGridView with various properties passed to it in the WebTestRequestResult.

    public void Update(WebTestRequestResult WebTestResults)
            {
                // Clear the DataGridView when a request is selected.
                resultControlDataGridView.Rows.Clear();
                // Populate the DataGridControl with properties from the WebTestResults.
                this.resultControlDataGridView.Rows.Add("Request: " + WebTestResults.Request.Url.ToString());
                this.resultControlDataGridView.Rows.Add("Response: " + WebTestResults.Response.ResponseUri.ToString());
                foreach (RuleResult ruleResult in WebTestResults.ExtractionRuleResults)
                {
                    this.resultControlDataGridView.Rows.Add("Extraction rule results: " + ruleResult.Message.ToString());
                }
                foreach (RuleResult ruleResult in WebTestResults.ValidationRuleResults)
                {
                    this.resultControlDataGridView.Rows.Add("Validation rule results: " + ruleResult.Message.ToString());
                }
                foreach (WebTestError webTestError in WebTestResults.Errors)
                {
                    this.resultControlDataGridView.Rows.Add("Error: " + webTestError.ErrorType.ToString() + " " + webTestError.ErrorSubtype.ToString() + " " + webTestError.ExceptionText.ToString());
                }
            }
    

Build the WebPerfTestResultsViewerAddin Solution

To build the solution

  • On the Build menu, select Build Solution.

Register the WebPerfTestResultsViewerAddin Add-In

To register the add-in using the Add-in Manager

  1. On the Tools menu, select Add-in Manger.

  2. The Add-in Manager dialog box is displayed.

  3. Select the check box for the WebPerfTestResultsViewerAddin add-in in the Available Add-ins column and clear the check boxes underneath the Startup and Command Line columns.

  4. Click OK.

    For more information, see How to: Control Add-Ins By Using the Add-In Manager.

Run the Web Performance Test Using the Build the WebPerfTestResultsViewerAddin Add-In

To run the new VS Add-In for the Web Test Results Viewer

  1. Run your Web performance test and you will see the WebPerfTestResultsViewerAddin add-in's new tab titled Sample displayed in the Web Performance Test Results Viewer.

  2. Click the tab to see the properties presented in the DataGridView.

Security

To improve security by preventing malicious add-ins from automatically activating, Visual Studio provides settings in a Tools Options page named Add-in/Macros Security.

In addition, this options page allows you to specify the folders in which Visual Studio searches for .AddIn registration files. This improves security by allowing you to limit the locations where .AddIn registration files can be read. This helps prevent malicious .AddIn files from unintentionally being used.

Add-In Security Settings

The settings in the Add-in/Macros Security, Environment, Options Dialog Box that relate to add-in security are as follows:

  • Allow add-in components to load.   Selected by default. When selected, add-ins are allowed to load in Visual Studio. When not selected, add-ins are prohibited from loading in Visual Studio.

  • Allow add-in components to load from a URL.   Not selected by default. When selected, add-ins are allowed to be loaded from external Web sites. When not selected, remote add-ins are prohibited from loading in Visual Studio. If an add-in cannot load for some reason, then it cannot be loaded from the Web. This setting controls only the loading the add-in DLL. The .Addin registration files must always be located on the local system.

  • For more information, see Add-In Security.

See Also

Tasks

How to: Control Add-Ins By Using the Add-In Manager

Walkthrough: Debugging an Add-In Project

Reference

UserControl

Microsoft.VisualStudio.TestTools.LoadTesting

Microsoft.VisualStudio.TestTools.WebTesting

Microsoft.VisualStudio.TestTools.WebTesting.Rules

UserControl

DataGrid

Concepts

Add-In Registration

Automation Object Model Chart

Events in Windows Forms Controls

Other Resources

Creating and Using Custom Plug-ins for Load and Web Performance Tests

Properties in Windows Forms Controls

Developing Custom Windows Forms Controls with the .NET Framework