Going on one of my previous posts:
viewtopic.php?p=85822#p85822
I have decided to dotsource my functions to share them between my PS Studio apps and other automation scripts.
What I have noticed is that everything works if I run the app normally but when I go into debug mode there appears to be a scoping issue.
On my main form, I assign stuff to $global:PSDefaultParameterValues. This appears to be lost when in a dotsourced function in debug mode.
Also, it appears you cannot set breakpoints in the dotsourced functions.
Don't know if there are ways of dealing with this?
Thanks
David
dot sourcing and debugging
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
dot sourcing and debugging
For debugging with dot sourced files, please try Debugging with Multiple Files (Ctrl+M):
This will open a dialog with a list of files currently open in the editor to include while debugging:
Go to full postRe: dot sourcing and debugging
For debugging with dot sourced files, please try Debugging with Multiple Files (Ctrl+M):
This will open a dialog with a list of files currently open in the editor to include while debugging:
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: dot sourcing and debugging
Hmm. Still have two issues.
I tried the 'multiple files' thing and breakpoints set in dotsourced functions arent actually working.
Also, global variables are not available in the dotsourced functions.
I tried the 'multiple files' thing and breakpoints set in dotsourced functions arent actually working.
Also, global variables are not available in the dotsourced functions.
Re: dot sourcing and debugging
When debugging with the multiple files option, are the breakpoints from the dot sourced files written to the Tools Output pane?
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: dot sourcing and debugging
With my tests, I haven't found any issues with debugging with multiple files with the latest build of PowerShell Studio. I also have not found any issues with global variables and debugging.
Please answer the following:
What build of PowerShell Studio are you using?
Is it just this one dot sourced file or is it all dot sourced files having this issue?
Is the line you where you have the breakpoint set being reached?
Are you using Windows PowerShell or PowerShell 7?
If you have multiple copies/version of the same file that is dot sourced, do you have the correct file open in the editor?
Please answer the following:
What build of PowerShell Studio are you using?
Is it just this one dot sourced file or is it all dot sourced files having this issue?
Is the line you where you have the breakpoint set being reached?
Are you using Windows PowerShell or PowerShell 7?
If you have multiple copies/version of the same file that is dot sourced, do you have the correct file open in the editor?
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: dot sourcing and debugging
What build of PowerShell Studio are you using?
247
Is it just this one dot sourced file or is it all dot sourced files having this issue?
All
Is the line you where you have the breakpoint set being reached?
Yes -absolutely!
Are you using Windows PowerShell or PowerShell 7?
V5.1
If you have multiple copies/version of the same file that is dot sourced, do you have the correct file open in the editor?
Only one copy of each function file exists
Just to further describe the environment.
The project includes a file called commonfunctions.ps1. The 'Shared' property of this file is set to True.
When the full function code was included for all functions, everything worked fine.
I removed the full function code from all functions in Commonfunctions.ps1 and placed them on a server.
Commonfunctions.ps1 now has multiple lines in the format:
When running as normal (without debug) everything works fine regarding globally scoped variables.
247
Is it just this one dot sourced file or is it all dot sourced files having this issue?
All
Is the line you where you have the breakpoint set being reached?
Yes -absolutely!
Are you using Windows PowerShell or PowerShell 7?
V5.1
If you have multiple copies/version of the same file that is dot sourced, do you have the correct file open in the editor?
Only one copy of each function file exists
Just to further describe the environment.
The project includes a file called commonfunctions.ps1. The 'Shared' property of this file is set to True.
When the full function code was included for all functions, everything worked fine.
I removed the full function code from all functions in Commonfunctions.ps1 and placed them on a server.
Commonfunctions.ps1 now has multiple lines in the format:
Code: Select all
. \\<server>\<share>\<filename>
Re: dot sourcing and debugging
Are the functions from the dot sourced files recognized by the editor? If you hover over them, do you see the file information?
Please try the following:
-Set a breakpoint at a function call in your project from one of your dot sourced files.
-Verify that this dot sourced file is open in the editor with same exact path. This can be verified by hovering over the file tab.
-Start debugging with the Debug with Multiple files option with the dot sourced file checked.
-When it hits the breakpoint, step into the function (F11).
-When you stepped into the function, did it switch to that dot sourced file open in the editor? Or does it open a new tab?
Please try the following:
-Set a breakpoint at a function call in your project from one of your dot sourced files.
-Verify that this dot sourced file is open in the editor with same exact path. This can be verified by hovering over the file tab.
-Start debugging with the Debug with Multiple files option with the dot sourced file checked.
-When it hits the breakpoint, step into the function (F11).
-When you stepped into the function, did it switch to that dot sourced file open in the editor? Or does it open a new tab?
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: dot sourcing and debugging
"same exact path" was the clue.
The dotsourced function was \\server\share1\filename
but the file open in the editor was \\server\share2\folder\folder\filename
It was the same file but not the "same exact path"
So when I opened it using the same path it worked!
Thanks
David
The dotsourced function was \\server\share1\filename
but the file open in the editor was \\server\share2\folder\folder\filename
It was the same file but not the "same exact path"
So when I opened it using the same path it worked!
Thanks
David
Re: dot sourcing and debugging
So I had a ps1 file with multiple lines dotsourcing my functions like:
. \\ps\functions$\add-thingy.ps1
...and that all worked fine.
I thought it was more efficient to not specify each line so I changed that ps1 file to remove all the individual dotsourcing lines and run this code:
When I run this in the PS studio console all is fine. But when I build an exe package it doesnt work.
Any ideas?
Thanks
David
. \\ps\functions$\add-thingy.ps1
...and that all worked fine.
I thought it was more efficient to not specify each line so I changed that ps1 file to remove all the individual dotsourcing lines and run this code:
Code: Select all
$functionpath = '\\ps\functions$\'
$functions = Get-ChildItem -path "$functionpath\*.ps1" -name | where { $_ -notlike '*tempPoint*' }
foreach ($function in $functions) {
. ($functionpath + $function)
}
Any ideas?
Thanks
David