Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

AU module may not be automatically available when installed via Chocolatey #15

Closed
ferventcoder opened this issue Aug 25, 2016 · 18 comments
Labels

Comments

@ferventcoder
Copy link

There is a pattern seen in Chocolatey packages that manage PowerShell modules. I would like to see that done with the au package (which I realize is in a different repository).

I'd really like to choco install au and have it import the module to the proper location, right now I don't see the ability to immediately use what I've installed, which IMHO means the package is incomplete.

There are others as well.

@majkinetor
Copy link
Owner

Mhm... I am not sure why is it not working for you. It should just works because ~\Documents\WindowsPowershell\Modules is a default user location which is already present in the $env:PSModulePath which means that it will autoload when you request a function from it.

As an example, this is an install on Win 8.1 machine that didn't have it before:

PS C:\Users\tanja> gmo au
PS C:\Users\tanja> gmo au -ListAvailable
PS C:\Users\tanja> cinst au
Chocolatey detected you are not running from an elevated command shell
 (cmd/powershell).

 You may experience errors - many functions/packages
 require admin rights. Only advanced users should run choco w/out an
 elevated shell. When you open the command shell, you should ensure
 that you do so with "Run as Administrator" selected.

 Downloading au 64 bit
   from 'https://github.com/majkinetor/au/archive/2016.8.15.zip'
 Hashes match.
 Extracting C:\Users\tanja\AppData\Local\Temp\chocolatey\au\2016.8.15\auInstall.zip to C:\ProgramData\chocolatey\lib\au\tools...
 7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
 Processing archive: C:\Users\tanja\AppData\Local\Temp\chocolatey\au\2016.8.15\auInstall.zip
 Extracting  au-2016.8.15
 Extracting  au-2016.8.15\AU.psd1
 Extracting  au-2016.8.15\AU.psm1
 Extracting  au-2016.8.15\Get-AUPackages.ps1
 Extracting  au-2016.8.15\Push-Package.ps1
 Extracting  au-2016.8.15\README.md
 Extracting  au-2016.8.15\Test-Package.ps1
 Extracting  au-2016.8.15\Update-AUPackages.ps1
 Extracting  au-2016.8.15\Update-Package.ps1
 Extracting  au-2016.8.15\update.gif
 Everything is Ok
 Folders: 1
 Files: 9
 Size:       339859
 Compressed: 293426
 C:\ProgramData\chocolatey\lib\au\tools
 The install of au was successful.

Chocolatey installed 1/1 package(s). 0 package(s) failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\Users\tanja> gau
PS C:\Users\tanja> update
No nuspec file
At C:\Users\tanja\Documents\WindowsPowerShell\Modules\au\2016.8.15\Update-Package.ps1:254 char:24
+     if (!$nuspecFile) {throw 'No nuspec file' }
+                        ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (No nuspec file:String) [], RuntimeException
    + FullyQualifiedErrorId : No nuspec file

For some reason it didn't even fail non admin shell.

@majkinetor
Copy link
Owner

Perhaps your $Env:PSModulePath doesn't contain default paths ?

@ferventcoder
Copy link
Author

PowerShell 3 has less paths in PSModulePath than Posh v4+. I think it something with my local computer though.

@majkinetor
Copy link
Owner

Do you have any idea why it passed without admin shell ? On my other Win 10 it failed... UAC is set to dfaults on both machines...

@ComFreek
Copy link
Contributor

Two or three days ago when I installed au, I had to to run Install-Module au after cinst au as well! au could previously not be found as a module.

My system:

  • Windows 10 Pro 64-bit (without Anniversary update back then)
  • PS Version 5.1.14393.82

@majkinetor
Copy link
Owner

@ComFreek

The Install-Module by default puts it in a machine location. Could you give me your $Env:PsModulePath to check it out ?

I installed it on my Win10 (same spec as yours) without a problem.

It might be a posh 5 problem that I encounter from time to time - some modules do not seem to get autoloaded sometimes...

@majkinetor
Copy link
Owner

@ComFreek

Also, please give the output of the gmo au -ListAvaialable.

@ferventcoder ferventcoder reopened this Aug 26, 2016
@ComFreek
Copy link
Contributor

PS C:\WINDOWS\system32> $Env:PsModulePath
D:\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> gmo au -ListAvailable


    Verzeichnis: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2016.8.15  AU                                  {Get-AUPackages, Push-Package, Test-Package, Update-AUPackages...}


PS C:\WINDOWS\system32>

I have now cuninst au, deleted the AU directory from the path given by gmo above and reinstalled AU using Install-Module au (without Chocolatey!). Strangely enough, this time it worked as intended.

@majkinetor
Copy link
Owner

@ComFreek

As I expected, your user specific module directory is not there and thats why it didn't work via chocolatey. It worked via Install-Module as it installs by default in machine location as shown.

Now, I must look into this - why user specific folder isn't included in PsModulePath. Perhaps you need to install something there via Install-Module -Scope user for it to get there.

In any way, I declare this as a bug and will see to install into machine location by default as current user folder is unreliable.

@majkinetor majkinetor added the bug label Aug 27, 2016
@majkinetor majkinetor changed the title Installation with Chocolatey should set up au for use (import the module) AU module may not be automatically available when installed via Chocolatey Aug 27, 2016
@majkinetor
Copy link
Owner

Fixing a Missing Path in PSModulePath article details about this and provides script:

#Save the current value in the $p variable.
$p = [Environment]::GetEnvironmentVariable('PSModulePath','User')
#Add the new path to the $p variable. Begin with a semi-colon separator.
$p += ";$Home\Documents\WindowsPowerShell\Modules"
#Add the paths in $p to the PSModulePath value.
[Environment]::SetEnvironmentVariable('PSModulePath',$p,'User')

Microsoft itself says:

By default, the PSModulePath environment variable value contains the following system and user module directories, but you can add to and edit the value.

  • $PSHome\Modules (%Windir%\System32\WindowsPowerShell\v1.0\Modules)
  • $Home\Documents\WindowsPowerShell\Modules (%UserProfile%\Documents\WindowsPowerShell\Modules)
  • $Env:ProgramFiles\WindowsPowerShell\Modules (%ProgramFiles%\WindowsPowerShell\Modules)

So this means that your system @ComFreek does not contain normal defaults. So, there are 3 things that can be done:

  • Move au to $Env:ProgramFiles. This means you need to be an admin to run it which kinda sux (does it really?)
  • Add $HOME to PSModulePath (via above script). Seems intrusive?
  • Do nothing.

Thoughts ?

@majkinetor
Copy link
Owner

There is also an option to add au's location to the psmodulepath which is less intrusive then adding $HOME, but $HOME should really be there in the first place.

@ComFreek
Copy link
Contributor

I think I tracked down the problem.

On my system I have moved all user-specific directories (Contacts, Pictures, Music, Videos, Documents, Desktop, Downloads etc.) to another partition, namely D. Note that "moved" means the way via the Properties dialog of each directory, so that Windows is notified about it.

So this means that your system @ComFreek does not contain normal defaults.

It does: D:\Documents\WindowsPowerShell\Modules is my user-specific module folder.

I had a look at your chocolateyInstall.ps1. In line 23 (direct link) it contains

$module_dst = "$Env:UserProfile\Documents\WindowsPowerShell\Modules\$packageName\$Env:ChocolateyPackageVersion"

Outputting $Env:UserProfile on my system showed me C:\Users\ComFreek! The install script chooses the wrong location, I even have an empty 'au' directory in C:\Users\ComFreek\Documents\WindowsPowerShell\Modules.

A quick Google searched turned up the correct way to determine the Documents directory: StackOverflow: Getting the user's Documents folder in Powershell:

[Environment]::GetFolderPath("MyDocuments")

Indeed, it does correctly return D:\Documents on my system.

@ComFreek
Copy link
Contributor

Update:

  • Completely uninstalled AU from my system (cuninst + Uninstall-Module au)
  • Tried to fix install script: majkinetor/au-packages@master...ComFreek:master
  • Installed the fixed Chocolatey package
  • Even though it now wrote into D:\Documents\WindowsPowerShell\Modules\au\2016.8.15.20160829, I could neither run Update-Package nor Import-Module au (it says it could not find such a module).

@majkinetor
Copy link
Owner

@ComFreek , however, as per MSDN page, this folder location is $Home\Documents\WindowsPowerShell\Modules which means your system is still unusual.

I know why it doesn't find the module at your location, it has invalid version (where revision comes from ?) The version that you see in folder must be the same as in au.psmd1.

I think I will just use machine location and thats it: $Env:ProgramFiles\WindowsPowerShell\Modules .

@ferventcoder
Copy link
Author

PowerShell v5 uses versions, I don't think PowerShell v3/4 allowed for versions as part of the path.

@ferventcoder
Copy link
Author

ferventcoder commented Aug 29, 2016

@ComFreek if you remove the 2016.8.15.20160829 folder from the path (moving everything in it up a directory), does it work?

@majkinetor majkinetor added this to the next milestone Aug 29, 2016
@majkinetor
Copy link
Owner

AU moved to $Env:ProgramFiles: majkinetor/au-packages@25425c3 for future versions.

@ComFreek
Copy link
Contributor

@ComFreek , however, as per MSDN page, this folder location is $Home\Documents\WindowsPowerShell\Modules which means your system is still unusual.

I suspect a documentation error on this page: https://msdn.microsoft.com/en-us/library/dd878350(v=vs.85).aspx.
Although I am not sure how fruitful it is, I filled out the feedback form inquiring about this topic.

I know why it doesn't find the module at your location, it has invalid version (where revision comes from ?) The version that you see in folder must be the same as in au.psmd1 .

That fixed it! Import-Module now finds it.
The revision part comes from your update script and setting $au_Force = $true.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants