Login Page - Create Account

Support Board


Date/Time: Fri, 18 Oct 2024 09:15:22 +0000



Post From: VS2022: Pre/Post Build Events DLL Issue

[2024-08-11 15:10:24]
ondafringe - Posts: 277
Someone asked me about all this, so here are the step-by-step instructions that I took in order to set up my custom study project using Visual Studio 2022.

Note: If you are only using Visual Studio as an editor, and you are doing your build from within Sierra Chart, or you are using VSCode, the following -- may not/probably won't -- work. As far as I know, you have to create your custom study project from scratch for the following set up instructions to apply. If you want to know how to create a project from scratch using Visual Studio 2022, let me know and I will write up and post those instructions, as well.

• In “Solution Explorer,” right-click on your project name, and at the very bottom, click on “Properties”
• Under “Configuration Properties > General > Output Directory”
• Provide the path to the Sierra Chart “Data” folder (usually C:\SierraChart\Data\)
• Under “Linker > General > Output File”
• Provide the same path to the Sierra Chart “Data” folder and add $(TargetName)$(TargetExt)
• That usually results in C:\SierraChart\Data\$(TargetName)$(TargetExt)

In order to use Visual Studio to create a custom study to run in Sierra Chart, it is necessary to update your study’s “dll” file without having to close and reopen Sierra Chart and without having to invoke the “Release All DLLs and Deny Load” in Sierra Chart. Visual Studio has Pre-Build and Post-Build Events you can use to facilitate those updates.

You will need:

• Windows Powershell Version 6 (or higher)
• Powershell Tools for Visual Studio 2022

As I understand, all versions of Windows, including Windows 11, only have Version 5.1 (or earlier) installed. To check your version, open Powershell and, at the prompt, type: $PSVersionTable :and press Enter.

If you need to download and install the most recent version of Windows Powershell, the following download link was good as of 2024-08-11.

https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/PowerShell-7.4.4-win-x64.zip

To install the “Powershell Tools for Visual Studio 2022” extension. At the top of Visual Studio:

• Click “Extensions”
• Click “Manage Extensions”
• When the Extension Manager opens, search for “Powershell Tools”
• You should see “Powershell Tools for Visual Studio 2022” in the results
• Click on that extension, and, at the top of the adjacent pane, click Install

Once you have Powershell and the Powershell Tools extension installed:

• In Visual Studio, go to “Solution Explorer,” right-click on your project name, and at the very bottom, click on “Properties”
• Under “Build Events > Pre-Build Event > Command Line”
• Put this: {full path to the powershell .exe file} -File "ReleaseDLL.ps1"
• Example: C:\Powershell\powershell.exe -File "ReleaseDLL.ps1"
• Under “Build Events > Post-Build Event > Comand Line”
• Put this: {full path to the powershell .exe} -File "ReloadeDLL.ps1"
• Example: C:\Powershell\powershell.exe -File "ReloadDLL.ps1"
• Click “Okay” to exit

At the top of Visual Studio, change “Debug” to “Release” – or vice versa – and repeat the above steps.

Note: if you are using the default PowerShell that was installed with Windows, you may not need to provide the full path to Powershell.

I have attached the two Powershell script files; download and put them in the project folder. Open each file using any text editor and change “your.dll” to the name of your DLL.

If you put the ReleaseDLL.ps1 and ReloadDLL.ps1 files in a folder other than the project folder, you will have to provide the full path to those two files in the pre-/post-build events, above.

Make certain you set your Sierra Chart UDP port to the same port indicated in the two Powershell script files:

• Gobal Settings > Sierra Chart Server Settings > UDP Port

The UDP port doesn't have to be the same port I used, just make certain the port you use is the same in all three places.

Hopefully, all this will work for you, as it did for me.
Date Time Of Last Edit: 2024-09-10 21:01:56
attachmentReleaseDLL.ps1 - Attached On 2024-08-11 15:15:08 UTC - Size: 276 B - 92 views
attachmentReloadDLL.ps1 - Attached On 2024-08-11 15:15:16 UTC - Size: 281 B - 70 views