I have a build script that depends on an older version of one of our modules. Version 1.0.1. I added -MaximumVersion 1.0.1
to the Import-Module
command. When the build script runs it fails and error shows that it is running code in version 2.1.0 of the module.
Import-Module DrilQuip.Build -MaximumVersion 1.0.1 -Force
Creating next version number... The property 'VersionFilePath' cannot be found on this object. Verify that the property exists. At C:\Users\svcTFSBuildProd\Documents\WindowsPowerShell\Modules\DrilQuip.Build\ 2.1.0\DrilQuip.Build.psm1:253 char:5
I have tried with and without the -Force
switch but that makes no difference.
I used Get-Module DrilQuip.Build -ListAvailable
to confirm that version 1.0.1 is present on the computer.
How can I insure that the script imports and uses the older version of the modules?
Update 1
Added -Verbose
switch to get more details about what is happening. Here are the results:
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\DrilQuip.Build\1.0.1\DrilQuip.Build.psd1'. VERBOSE: Populating RepositorySourceLocation property for module DrilQuip.Build.
Creating next version number... The property 'VersionFilePath' cannot be found on this object. Verify that the property exists. At C:\Users\svcTFSBuildProd\Documents\WindowsPowerShell\Modules\DrilQuip.Build\ 2.1.0\DrilQuip.Build.psm1:253 char:5 + $Matches = Select-String -Path $global:BuildConfig.VersionFilePat ...
This shows that the same module has been installed into 2 different locations. The location C:\Users\svcTFSBuildProd... seems to trump the location C:\Program Files\WindowsPowerShell...
I think this has to do with Machine vs User scope on the module installation. I'll go back and remove the User scoped modules and install all versions of the module with Machine scope and see if that helps.
Update 2
I removed all of the versions of the module from user scope folder and then tried the script again. It is still failing but now both versions of the module are coming from the same module folder location.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\DrilQuip.Build\1.0.1\DrilQuip.Build.psd1'. VERBOSE: Populating RepositorySourceLocation property for module DrilQuip.Build. Creating next version number... The property 'VersionFilePath' cannot be found on this object. Verify that the property exists. At C:\Program Files\WindowsPowerShell\Modules\DrilQuip.Build\2.0.4\DrilQuip.Build.psm1:251 char:5
Since the new version is still trumping the max version I requested my theory that user scope trumps machine scope is not the real problem. Something else is going on.
I ran Get-Module -Name DrilQuip.Build -ListAvailable
again and I notice that the ModuleType is different. On version 1.0.1 the type is Manifest but on versions 1.1.1 and 2.0.4 the type is Script. Maybe this difference is causing the problem.
ModuleType Version Name
---------- ------- ----
Script 2.0.4 DrilQuip.Build
Script 1.1.1 DrilQuip.Build
Manifest 1.0.1 DrilQuip.Build
I will remove all of the modules and reinstall them from the repository.