Login Page - Create Account

Support Board


Date/Time: Fri, 18 Oct 2024 09:16:06 +0000



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

[2024-06-23 22:39:14]
ondafringe - Posts: 277
I have an older project built with VS2019 Community that used simple PowerShell scripts in the Pre/Post Build Events so I could update a DLL without having to shutdown and restart SC. It worked without issue, and after updating that project to VS2022 Community, it continues to work without issue: DLL file can be released, updated, and reloaded without having to shut down and restart SC.

I created a new project using VS2022, copied my two PowerShell scripts from the old project folder into the new project folder, updated the Pre/Post Build Events to reflect the new location of the PowerShell scripts, and local host and UDP port remained the same. I've tried everything I can think of, but I just can't get it to work. Keep getting the error that the DLL file "can't be opened" or "can't be opened for writing."

What I was, and still am, using is what @PeterSt posted in this thread (see Post #21).
ACSIL - DLL cannot be opened for writing

Here is how things are setup at present, which, except for file names and paths, is the same as what I used before.

ReleaseDLL.ps1:

$client = new-object net.sockets.udpclient(0)

$peerIP = "127.0.0.1"

$peerPort = "22904"

$send = [text.encoding]::ascii.getbytes("RELEASE_ALL_DLLS")

[void] $client.send($send, $send.length, $peerIP, $peerPort)

$client.close()


LoadDLL.ps1:

$client = new-object net.sockets.udpclient(0)

$peerIP = "127.0.0.1"

$peerPort = "22904"

$send = [text.encoding]::ascii.getbytes("ALLOW_LOAD_ALL_DLLS")

[void] $client.send($send, $send.length, $peerIP, $peerPort)

$client.close()

Pre-Build Event
powershell -executionPolicy bypass -file "D:\Documents\Visual Studio 2022\ProjectFolder\ReleaseDLL.ps1"

Post-Build Event
powershell -executionPolicy bypass -file "D:\Documents\Visual Studio 2022\ProjectFolder\LoadDLL.ps1"

=========================================

I have the latest updates for VS2022 installed, and I'm using the latest version of SC (or very close to the latest version). I've double-checked that the UDP port in SC is still set to 22904. I've run the PowerShell scripts from the Command Line without issues.

I can occasionally get it to work if I jump through a number of hoops, such as, close the new project, open the old project, rebuild the old project, close the old project, reopen the new project, and rebuild the new project. Sometimes that works. Sometimes it doesn't.

There's bound to be something I've overlooked, or a typo, or who-knows-what, but as of now, I'm stumped.

If any of you code gurus who use Visual Studio have any idea as to what the problem could be, please let me know.

If worse comes to worse, I'll just have to go back to building from inside SC.
Date Time Of Last Edit: 2024-06-24 03:21:58