EXE Build not including module files

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 6 years and 1 month 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.
User avatar
trevor530
Posts: 25
Last visit: Mon Feb 12, 2024 9:27 am

EXE Build not including module files

Post by trevor530 »

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 2017 v5.4.145
32 or 64 bit version of product: 64 bit
Operating system: Windows 10
32 or 64 bit OS: 64

I have built a Windows form project that includes some module files that I have also built. The project contains .psf, .psm1 and .psd1 files. The application runs just fine in Powershell Studio. I am attempting to package the application in to an exe and I notice that the modules and their functions are not being included in to the outputted exe. I have the following settings for my build settings:

Target: Microsoft Windows 64 Bit
Script Engine: SAPIEN PowerShell V5 Host (Windows Forms)
Use STA Mode: Checked
Resolve and include external scripts: Checked
Generate .config file: Unchecked
Execution Restrictions, Operating Systems: Windows 10, Checked

I can provide screenshots of all build settings if needed but they are either blank or defaults

I also notice that in my project I cannot edit the module properties, specifically the Build setting. On all my module files the setting is "Exclude" and is greyed out or otherwise un-editable. Shared is also set to "False". I am sure this is the source of the issue but I do not know how to modify those properties of my module file.
User avatar
trevor530
Posts: 25
Last visit: Mon Feb 12, 2024 9:27 am

Re: EXE Build not including module files

Post by trevor530 »

I moved the "Import-Module ...." lines from Globals.ps1 to Startup.pss and that seemed to do the trick.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: EXE Build not including module files

Post by davidc »

Yes, loading the modules in the Startup.pss / Main function is the recommend method.
David
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: EXE Build not including module files

Post by davidc »

Note: The execution of Globals.ps1 is not guaranteed to run before executing the code of the other files.
David
SAPIEN Technologies, Inc.
User avatar
trevor530
Posts: 25
Last visit: Mon Feb 12, 2024 9:27 am

Re: EXE Build not including module files

Post by trevor530 »

While I thought I had this problem resolved... it appears I still do not.

Do I need to copy the module files to the folder the generated .exe is located? For example:

Code: Select all

App folder
   |_ App.exe
   |_ modules
       |_ module1.psm1
       |_ module2.psm1
Also, why can I not change the properties of the file, specifically the Build property? What prevents me from changing that property?
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 20
Been upvoted: 37 times

Re: EXE Build not including module files

Post by Alexander Riedel »

Module files are never included in a generated executable. It basically goes against the idea of a module. A module is code shared for multiple applications, akin to a dll.
If you want to re-use code between projects AND include that code inside the executable file, put the functions in simple .ps1 files and dot source them from your script. If you check the option "Resolve and include external scripts", dot sourced script will be inserted at the location of the statement before packaging.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 6 years and 1 month 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.