Compile time library or module

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

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 10 years and 11 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.
Locked
User avatar
owinsloe
Posts: 161
Last visit: Tue Apr 16, 2024 8:36 pm
Been upvoted: 1 time

Compile time library or module

Post by owinsloe »

Hi, I'm trying to achieve a few things at once and need some guidance or suggestion on the best path.

I want to create a product that has two execution modes, GUI and batch (commandline). However I want both products to share source code (functions) so I do not have to maintain parallel source streams.

The dual execution mode requirement is to allow users to perform manual execution of the product and be assisted via a nice GUI presentation and the commandline is to allow automatic scheduled task runs (user input in this mode is supplied via a series of parameters stored within ini files).

The other requirement is that I want the distribution of the product to be compiled. I do not want the ps1 source scripts to be distributed.

I would really like the ability to examine whether the compiled exe has been supplied commandline arguments and if so run in batch mode and if not fire up the GUI form, but this does not look possible, I'm guessing because of all the form assemblies that have been loaded.

I suspect that I will need to distribute TWO executables (the product is called "refresh") so I'm expecting that I will have a refresh.exe (commandline) and refreshUI.exe (GUI).

Is there a way to compile the same source as GUI and commandline? I'm happy to add additional checking to examine how I have been launched.

If this is not possible what would be the best recommendation to achieve the desired result?

Thanks in advance.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Compile time library or module

Post by Alexander Riedel »

The EXE headers of console applications and windows app are different, so one cannot act as both.

I would suggest to use two executable files as you already pointed out. Examine the command line in the Windows one and launch the command line program is warranted.

If you do it the other way around you get a flashing console window.

Put the common code between the two into a module.
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Compile time library or module

Post by jvierra »

Alex is right if you bootstrap from a forms script but if you bootstrap from a standard sctipt that calls into either you can have only one EXE. Putting everything into a module is, of course, another approach but will not make teh scritp easily portable although I may be missing something.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Compile time library or module

Post by jvierra »

Just to clarify - it can be done in one EXE - I have done it but not with PowerShell Studio. Whether you choose to do it as one or two is up to your requirements.
User avatar
owinsloe
Posts: 161
Last visit: Tue Apr 16, 2024 8:36 pm
Been upvoted: 1 time

Re: Compile time library or module

Post by owinsloe »

Thanks for the responses guys. I have also done this before using Perl (which we're now replacing with PS) and wasnt sure how easy (if at all) it could be done in Primal Forms.

Ok, time for a dumb question...
If I use a module for common functions then the module file needs to be copied with the executable for importing (is this correct).

Or...is there a way that I can import common code at the time I compile the executable so the executable is totally stand-alone....ie. when I distribute to our various servers only the refresh.exe and refershUI.exe will need to be sent?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Compile time library or module

Post by jvierra »

I would maintain a shared source tree and compile the same common module into bot EXEs. (not compiled) A so called compiles module is really just a compressed version of the excluded files that is extracted when the EXE is run. You can place common script modules into a subdir of the EXE dir and the file will be shared but will have only one source.
User avatar
owinsloe
Posts: 161
Last visit: Tue Apr 16, 2024 8:36 pm
Been upvoted: 1 time

Re: Compile time library or module

Post by owinsloe »

@jvierra, thanks again......yes, I had pretty much came to the same conclusion.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Compile time library or module

Post by jvierra »

I tested it to be sure and it works as I would expect it too work.

It is the same with compiled projects. We place common code in a separate location and include it in the project. There are various ways to do this depending on the build and project environments.
This topic is 10 years and 11 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.
Locked