Share this page

# Create and view Vuser Scripts in Visual Studio

The basic IDE add-ins for Visual Studio let you create a Vuser script in Visual Studio in VB, C++, or C#. In Visual Studio, you can also view Vuser scripts created in VuGen.

In this topic:

## Create a script in Visual Studio

To create your script, you first install Visual Studio add-in. Then, use one of the predefined templates.

Prerequisites:

- Visual Studio must be installed in the default location.

- We recommend installing the appropriate UWP (Universal Windows Platform) before installing the add-in. For example, install UWP 2022 before installing LRVS2022IDEAddInSetup.exe.

To create a Vuser script in Visual Studio:

1. Install the IDE add-in for your version of Microsoft Visual Studio from the installation package's Additional Components folder. For example, Additional Components\IDE Add-Ins\LRVS<version>IDEAddInSetup.exe.

2. In Visual Studio, select the appropriate template from the Installed Templates VB|C++|C# .NET Vuser. Visual Studio creates a new project with one class and a template for a Vuser, and the script file, <name>.usr. The template contains three sections, Initialize, Actions, and Terminate.

   The following example shows a Visual C# template:

       public int Initialize()
             {
                 // TO DO: Add virtual user's initialization routines
                   return lr.PASS;
             }
             public int Actions()
             {
                 // TO DO: Add virtual user's business process actions
                 return lr.PASS;
             }
             public int Terminate()
             {
                 // TO DO: Add virtual user's termination routines
                 return lr.PASS;
             }

3. Add code to the template, in the TODO sections.

4. Open the Object Browser (View menu). Expand the OpenText Professional Performance Engineering node (for example Interop.LoadRunner) to see the elements. Add the required elements to your script, such as transactions, rendezvous points, and messages.

5. Expand the Toolbar menu, Vuser, and enhance your script with runtime settings and parameters. For more information, see the runtime settings General > Run Logic or the Parameter List dialog box.

6. Use the Vuser menu to replay the script and test its functionality.

7. Select Vuser > Create Load Scenario, to create a Controller scenario using this .usr file.

8. You can also build the project as a DLL file, which is then saved in the same folder as the project. You can reference this DLL directly from a Controller scenario.

9. For Visual Studio 2022, when creating C++ Vuser projects, manually update the following in Visual Studio:

   - Set the solution configuration to Release

   - Set the solution platform to x86

Back to top

## View a script in Visual Studio

Visual Studio provides you with additional tools to view, edit, and debug your Vuser scripts. You can add breakpoints, view variable values, add assembly references, and edit the script using Visual Studio's IntelliSense. You can also run the script in a step-by-step mode for debugging.

When you save a script, VuGen creates a Visual Studio solution file, Script.sln, in your script's folder. You can open the solution file in Visual Studio .NET and view all of its components in the Solution Explorer.

To open the Vuser script in Visual Studio, select Design > Open Script in Visual Studio or click the Visual Studio button on the VuGen toolbar.

Note: By default, the Vuser script opens in the latest version of Visual Studio that is installed on your computer. For example, if you have both Visual Studio 2017 and 2019 installed, the script is converted and opened in Visual Studio 2019.

Double-click the appropriate section in the Solution Explorer, such as vuser_init.cs, to view the contents of the script.

Note: VuGen automatically loads all of the necessary references that were required during recording. You can add additional references for use during compilation and replay through the Solution Explorer. Select the Reference node and select Add Reference from the right-click menu.

Click on globals.cs or globals.vb in the Solution Explorer to view a list of the variables defined and used by your script.

Back to top

## Known issues

Item | Description
--- | ---
Visual C++ language | When using the 2017/2019/2022 Visual Studio add-ins, the Visual C ++ language must be installed in order to work with C++ .NET Vuser projects.
VS2022 add-in | Due to a Visual Studio 2022 cache issue, the template might not show up the first time you try to access it in Visual Studio 2022. Resolution: Restart Visual Studio.
Register .NET assembly | When using Visual Studio and add-ins to create C# and VB .NET scripts, Visual Studio creates .NET assemblies that need to be registered in the system before their run. Registration of the .NET assembly requires administrative permissions. Resolution: Enable UAC and register the .NET assembly before running the test using one of these methods: Run Visual Studio "As Administrator" and provide administrative credentials when prompted. In Project Settings, ensure that the Register for COM interop option is set (Project > Properties > Build > Register for COM interop). Visual Studio automatically registers the test DLL as a .NET assembly every time it builds the project. Run Visual Studio without administrative permissions, and manually register the test DLL after it is built. To do so, run Windows Console with administrative permissions and run the following command: %WINDIR%\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe <TargetDLLwithPath> /codebase (ignore the warning issued when you run this command). For example, you might replace <TargetDLLwithPath> with c:\users\qatest\documents\visual studio 2019\Projects\MyProject\User1\MyProjectUser1.dll. You do not need to register the DLL after every build. It is enough to register it once after making changes in the COM interfaces defined in the DLL.
VB project | If you have an issue creating a VB project in Visual Studio 2017/2019/2022, use this workaround: Create a VBVBWizards folder under ..\Microsoft Visual Studio\<version>\Enterprise. Copy the folders 1033 and LrVbVuserClass found under ..\Microsoft Visual Studio\<version>\Enterprise\VB\VBWizards, and paste them into the VBVBWizards folder. Restart Visual Studio. The VB project should now be created successfully.
Threads | Although .NET-based and Java protocols support creating threads, we recommend that you do not use background threads in real load testing scenarios because: Threads can degrade tests scalability. Threads can affect performance measurements. The utility functions' behavior is undetermined if called from any thread except the Vuser main thread which runs the vuser_init, Action, and vuser_end actions. This applies to all functions named lr*.

Back to top

See also:

- Create Java Vuser scripts in external IDEs
- Develop a unit test using Visual Studio (NUnit Test)

https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 26.1 All View Local Help Center View Online Help Center Version: