My experience with ISE "caching" of old files:
The behaviour of ISE is different for PS modules ( .psm1 ) and simple PS scripts ( ps1 ). I am using PS&ISE with Win10Pro.
A)
My experience with modules ( . PSM1 )
- Load a module file "hello.psm1" already placed in a proper module
directory
"C:\Users\MyUserName\Documents\WindowsPowerShell\Modules\Hello" by
ISE
- Execute a function by "Run Selection" ( you may not execute
modules by "Run Script" )
- Modify the file, e.g. the output of the
function 'Write-Host "Hello World!"' to 'Write-Host "Hello"' and save the
file.
- Execute a function by "Run selection", and it will execute the
old function, with old output, e.g. "Hello World!". This is also true
if I repeat the "Run Selection" command.
- Just if I leave ISE and load it again, the new function is executed by "Run Selection".
B)
My experience with scripts ( .PS1 ).
- If I execute "Run Selection", the same behaviour as with modules.
- If I execute once "Run Script" and by that the function is called, the current version of the function is executed. Of course I call the function ( e.g. on line number 100 ) in the file "after" it is defined ( e.g. in lines 10-20 ). By this, there is no caching.
- Especially and consequently, if I execute once "Run Script", while the executed code doesn't call the function, and then execute my function by "Run Selection", the current version of the function is executed.
C)
Here is my workaround to make module development more comfortable:
- Simple scripts may be executed by "Run script".
- If I want to develop a module ( .PSM1 ), I name it as simple script ( .PS1 ) during the development phase. I place the file ( e.g. "hello.ps1" ) already in
the proper module folder, e.g. "C:\Users\MyUserName\Documents\WindowsPowerShell\Modules\Hello" for a module "Hello". Of course by this I can´t execute the functions as module functions from PowerShell console. I just want to use ISE to call functions for testing.
- As modules are not executed as script, there is no executable code in the file, but just functions ( AFAIK ). So I may safely execute a "Run Script" on my script.
So if I modify a module file under ISE development, I always first execute "Run Script", before I execute a function by "Run Selection".
By this I always execute the current version of a function.
Though my problem was a little bit different, this question and the answers were very helpful for me to find a solution. It is hard to find such questions about ISE "caching" and so helpful answers.
Sincerely
Rolf