10

I've a script file containing a class definition. Using the new V5 Powershell syntax. I've another script file that dot source the class and uses it. I'm testing that file in the console.

On clean startup of the console it will load the class correctly. I then make some changes to the class and saved them back to file. Re-running the script does not appear to pick the changes up. It is as though once loaded into the console, the class is immutable and will not be parsed and reloaded.

This really hurt when developing, since I have to spin up a new console after any change to a class.

Is there a way to force Powershell to reload classes each time it sees them?

This occur in code debugged both in Powershell ISE and in the Powershell console (using vscode).

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Dov Reshef
  • 101
  • 4

1 Answers1

2

This is a known issue with classes in Powershell, and looks like the issue remains unresolved at this time of writing.

To workaround this today, you either need to start a new interactive session (which you don't want to do), or load your development class in a child instance of Powershell:

powershell.exe -Command { Your-Code }

# Alternatively, write a script to test your newly updated class
powershell.exe -File \path\to\Test-ClassScript.ps1
codewario
  • 19,553
  • 20
  • 90
  • 159