Switching between test and production modules within a PS script

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 SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
jasonv
Posts: 28
Joined: Tue Jul 19, 2016 8:28 am

Switching between test and production modules within a PS script

Post by jasonv » Tue Aug 27, 2019 10:04 am

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

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

I have a development module that I modify and is located within a specific folder. Lets call it MyModule and it's located in the folder C:\Dev\Modules\. That same module is installed on the system within the default module folder and the PSModulePath environment variable is set to access it.

I need to add a function to MyModule and test it so within a script I have two Import-Module statements as follows...

# Import-Module 'MyModule'
# Uncomment to test the dev module
Import-Module 'C:\Dev\Modules\MyModule'

I comment out the call to the production one and un-comment the call to the development one. Both modules are in the PS Studio cache.

When I enter the new function (exported from the Dev module) into my script it's not detected (colorized). I rebuilt the cache. What else do I need to do?

Please list the repeatable steps for switching between a test module and a production module within a script. I thought I had this working at one point, but now it doesn't.

Thanks.

- Jason

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

User avatar
brittneyr
Site Admin
Posts: 162
Joined: Thu Jun 01, 2017 7:20 am

Re: Switching between test and production modules within a PS script

Post by brittneyr » Tue Aug 27, 2019 11:46 am

To better assist you, can you please answer the following questions:

- Are you only editing and saving the psm1 file, meaning you are not building the module?
- If you aren't building the module, are you updating your manifest (psd1) when changes are made to your functions (i.e updating FunctionsToExport)
- Is the version of your dev module and your production module different?
- Is your dev module path located within PSModulePath?
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
jasonv
Posts: 28
Joined: Tue Jul 19, 2016 8:28 am

Re: Switching between test and production modules within a PS script

Post by jasonv » Tue Aug 27, 2019 12:28 pm

- Are you only editing and saving the psm1 file, meaning you are not building the module?

Yes.

- If you aren't building the module, are you updating your manifest (psd1) when changes are made to your functions (i.e updating FunctionsToExport)

Yes, I update the version number. The function to export line = FunctionsToExport = '*'

- Is the version of your dev module and your production module different?

Yes, I always update the version

- Is your dev module path located within PSModulePath?

No, I add it within the cache editor.

User avatar
brittneyr
Site Admin
Posts: 162
Joined: Thu Jun 01, 2017 7:20 am

Re: Switching between test and production modules within a PS script

Post by brittneyr » Tue Aug 27, 2019 1:43 pm

At the moment I get PrimalSense to color the added functions when having two versions of a module by:
- Opening the cache editor and checking which version of the module I want
- Building the cache:
SPS-CacheEditor.png
SPS-CacheEditor.png (44.73 KiB) Viewed 737 times
- Closing the cache editor
- Closing and reopening PowerShell Studio. It seems the changes to the cache do not take affect until this happens.
- Verify that the version you want to be working with is visible in the Object Browser Panel:
SPS_ObjectPanelVersion.png
SPS_ObjectPanelVersion.png (87.2 KiB) Viewed 737 times
I will talk to the development team to verify if this is the only way this can be done and if so, ask if there is anyway to improve this.
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
jasonv
Posts: 28
Joined: Tue Jul 19, 2016 8:28 am

Re: Switching between test and production modules within a PS script

Post by jasonv » Wed Aug 28, 2019 9:55 am

Yes, I was hoping there was an easier way to do this since I regularly update the module and it would be nice if I can easily switch between the two. If I run the script externally from PS Studio it works as expected. If I install the module and rebuild the cache, Primal Sense then detects the new functions which is interesting because I don't need to select it within the Cache Editor. Maybe it is selected automatically if it is in the PSModulePath.

What is the difference between Build Cache within the Cache Editor and Re-Build Cache from the GUI button and Reload Cache?

Thanks.

- Jason

User avatar
jasonv
Posts: 28
Joined: Tue Jul 19, 2016 8:28 am

Re: Switching between test and production modules within a PS script

Post by jasonv » Wed Aug 28, 2019 10:14 am

Update:

I update one of the module functions and add a new parameter. I added the Dev module to the cache editor and clicked on Build Cache and closed the editor. I then selected Reload Cache and Primal Sense detected the the change and the new parameter was available.

1. Open Cache Editor
2. Import new module
3. Build Cache
4. Close Cache Editor
5. Reload Cache

I haven't tried adding a new function yet.

User avatar
brittneyr
Site Admin
Posts: 162
Joined: Thu Jun 01, 2017 7:20 am

Re: Switching between test and production modules within a PS script

Post by brittneyr » Fri Aug 30, 2019 7:07 am

Rebuild Local Cache rebuilds the cache, including any new modules installed.
Rebuild-Local-Cache.png
Rebuild-Local-Cache.png (30.07 KiB) Viewed 596 times

If you modified the cache with Cache Editor, PowerShell Studio will now prompt you before rebuilding the cache:
Modified-Cache-Warning.png
Modified-Cache-Warning.png (8.18 KiB) Viewed 596 times


Press Yes, to override the manual changes.

Press No, to cancel.

This safety check will help prevent accidentally undoing any manual changes made to the cache.


Reload Cache will reload the cache without making any changes.
Reload-Cache.png
Reload-Cache.png (29.3 KiB) Viewed 596 times

Use this command to reload the cache after making changes with the Cache Editor.

If you build the cache from the cache editor, you will need to reload the cache from the ribbon.

I missed the reload when I gave you my answer to your question, I apologize for any inconvenience.
The steps should be:
1. Change the version of the module in the Cache Editor.
2. Build Cache, then close the Cache Editor.
3. Reload the cache from the ribbon.
Brittney Ryn
SAPIEN Technologies, Inc.