Using Resolve and include external scripts, how to have a mixture, is it all or nothing?

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
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.
This topic is 4 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
david.adams
Posts: 3
Last visit: Sat Jun 20, 2020 5:38 pm

Using Resolve and include external scripts, how to have a mixture, is it all or nothing?

Post by david.adams »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: Powershell Studio 2019 6.6.165
32 or 64 bit version of product:64
Operating system:
32 or 64 bit OS:windows 10/ windows server 2016

*** Please add details and screenshots as needed below. ***

If you have something like this in your startup.ps1

#Load Supporting Modules
#Logging Reporting Function
Import-module "C:\tools\LogModile.ps1"
#Module Loading Function
Import-module "C:\tools\LoadLibraries.ps1"
#Load Common Functions
Import-module "C:\tools\LoadFunctions.ps1"
#Load Environment Variables
Import-module "C:\tools\LoadEnv.ps1"


And in the build option you select the "Using Resolve and include external scripts" tick box
is it possible to exclude one of the files like the LoadEnv.ps1 so you can import the Environment variables after you have made changes
without having to recompile the executable?
Or is there a better way of doing this?

Many thanks
Dave





DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
User avatar
brittneyr
Site Admin
Posts: 1669
Last visit: Fri Apr 12, 2024 2:35 pm
Answers: 39
Been upvoted: 31 times

Re: Using Resolve and include external scripts, how to have a mixture, is it all or nothing?

Post by brittneyr »

If any changes are made to scripts that are included in your executable, you will need to repackage your script.

From what you have provided, I'm not sure what you are trying to accomplish. Can you please provide more detail and more code?
Brittney
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Mon Apr 15, 2024 3:28 pm
Answers: 20
Been upvoted: 37 times

Re: Using Resolve and include external scripts, how to have a mixture, is it all or nothing?

Post by Alexander Riedel »

Files loaded with Import-Module are not resolved when packaging as an executable.
Only dot sourced file are resolved during packaging if that option is checked.
Alexander Riedel
SAPIEN Technologies, Inc.
david.adams
Posts: 3
Last visit: Sat Jun 20, 2020 5:38 pm

Re: Using Resolve and include external scripts, how to have a mixture, is it all or nothing?

Post by david.adams »

Thank you to both of you,

With regards to your question brittneyr of what I am trying to achieve is:-
I want to create an executable that can be deployed and then run in different debug modes with the switch being held in an environment variable in the LoadEnv.sp1 file.

Thanks Alexander Riedel but I have tested what you had mentioned "Files loaded with Import-Module are not resolved when packaging as an executable."
The program won't run without the information in the LoadEnv.ps1 and I removed the file and ran the executable and it still ran.
I Also created a test executable with an Import-Module and tried change a value in the imported file that was to be displayed in the executable and it did not change from the value at Build time.
Unfortunately it looks to include Import-Module and dot sourced files unless there is a setting somewhere.

Thanks
Dave
david.adams
Posts: 3
Last visit: Sat Jun 20, 2020 5:38 pm

Re: Using Resolve and include external scripts, how to have a mixture, is it all or nothing?

Post by david.adams »

Thanks Alexander
you put me on the right lines, I experimented further and this worked, it did not include the file in the build so I was able to update the environment variables independently of the build
$bb="LoadEnv.ps1"
$aa="C:\tools\env\$bb"
Import-module "$aa"

Many thanks :D
User avatar
Alexander Riedel
Posts: 8488
Last visit: Mon Apr 15, 2024 3:28 pm
Answers: 20
Been upvoted: 37 times

Re: Using Resolve and include external scripts, how to have a mixture, is it all or nothing?

Post by Alexander Riedel »

I am the one who wrote the packager code to include dot sourced scripts. So I can clearly state that Import-Module is not not resolved during packaging. I would know. :D

Generally speaking, in your case, where you want to include a script (.ps1) rather than importing a PowerShell module (.psm1) you would use dot sourcing

. C:\Tools\Env\LoadEnv.ps1

This is opposed to importing a module, which in general is done by name rather than a full path

Import-Module LoadEnvironment

If you where to use a PowerShell module you would include the .psm1 file

Import-Module "C:\Tools\Env\LoadEnv.psm1"

which should also have an equally named .psd1 file that contains the module's meta data, exported functions etc.

All of this wouldn't mean that your packaged exe won't run on another machine as long as the module is there. It just means the code is not included at packaging time and the external reference is not removed.

It is quite possible that you see side effects from PowerShell's Import-Module, which is somewhat erratic how it behaves when a module cannot be found in one location but another.
Since you also do not load actual Powershell modules, but script files with Import-Module, I admit I have no idea how that would behave.
I'll forward that question to someone with more insight into Import-Module.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 4 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.