Powershell studio changing powershell module manifest when deployed, resulting in broken module

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 5 years and 3 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.
User avatar
whiggs2
Posts: 38
Last visit: Fri May 13, 2022 11:03 am

Powershell studio changing powershell module manifest when deployed, resulting in broken module

Post by whiggs2 »

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

Ok. So this problem caused me a lot of grief yesterday and today while I was trying to troubleshoot why a powershell module I had created was not working. I have a powershell module which is comprised of powershell scripts which are dot sourced into the current session when the module is imported. The psm1 file contains the below code:
  1. $cred = New-Object System.Management.Automation.PSCredential -ArgumentList $env:USER, (ConvertTo-SecureString $env:PASSWORD -Force -AsPlainText)
  2. Connect-AzureRmAccount -Credential $cred -TenantId $env:TENANT -ServicePrincipal
  3. $ModuleRoot = $PSScriptRoot
  4. $funcs = @(Get-ChildItem -Path "$PSScriptRoot\Functions\*.ps1" -ErrorAction SilentlyContinue)
  5. foreach ($import in $funcs)
  6. {
  7.     Try
  8.     {
  9.         . $import.FullName
  10.     }
  11.     Catch
  12.     {
  13.         Write-Error -Message "Failed to import function $($import.fullname): $_"
  14.     }
  15. }
  16. Export-ModuleMember -Function $funcs.Basename
The problem that I am running into is with the manifest file, which Sapien powershell studio seems to not be able to resist the compulsion to change certain properties when I have set values for them. The property in question is the "FunctionsToExport" property. Even when I go into the manifest file and define the functions which are to be exported (with either the names of the functions or a simple "*" wildcard), powershell studio keeps changing the property back to an empty array when I use the deploy feature to deploy the module to its final destination (the changes are made to both the deployed manifest file and the manifest file in the project). This requires that I, upon deploying the powershell module, open the manifest file when the folder I deployed to opens in explorer and manually configure the FunctionsToExport property EVERY SINGLE TIME I deploy the module since, like I said, powershell studio can't seem to control its compulsive, destructive behavior when it comes to my project files. The module itself does work if all I wanted to do was import it into the current powershell session. But that is not what I am trying to do. I built this module specifically for the purpose of creating, testing, and showcasing a continuous integration powershell pipeline, and when the above property is an empty array as a result of Powershell studio's unnecessary/compulsive modification of the manifest file, the pipeline does not find any of the functions associated with the module. Please fix this, or at least have a "don't screw with my powershell files Powershell Studio" option somewhere.

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Powershell studio changing powershell module manifest when deployed, resulting in broken module

Post by davidc »

Depending on your build settings, this type of code is not necessary in a PowerShell Studio project. But if you wish to use this structure, you can disable the Auto Export Functions feature in the project's properties. For more details, please refer to the following article:

https://www.sapien.com/blog/2018/08/14/powershell-studio-2018-service-release-v5-5-154-and-pscore-support/

Note: Explicitly listing the functions in the manifest will improve performance when PowerShell is discovering commands of the module:

https://www.sapien.com/blog/2016/03/24/exporting-from-modules-a-reminder/
David
SAPIEN Technologies, Inc.
This topic is 5 years and 3 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.