Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$profile is empty string when installing packages - does not automatically install the ChocolateyProfile. #667

Closed
flcdrg opened this issue Mar 23, 2016 · 16 comments

Comments

@flcdrg
Copy link
Member

flcdrg commented Mar 23, 2016

What You Are Seeing?

WARNING: Unable to add Chocolatey to the profile. You will need to do it manually. Error was 'Cannot bind argument to parameter 'Path' because it is an empty string.'

What is Expected?

Output advice to user about what to add to their profile.. eg

$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
  Import-Module "$ChocolateyProfile"
}

How Did You Get This To Happen? (Steps to Reproduce)

Upgraded to latest Chocolatey

Output Log

2016-03-24 09:08:16,294 [INFO ] - VERBOSE: Importing alias 'Remove-BinFile'.
2016-03-24 09:08:16,309 [INFO ] - WARNING: Unable to add Chocolatey to the profile. You will need to do it manually. Error was 'Cannot bind argument to parameter 'Path' because it is an empty string.'
2016-03-24 09:08:16,309 [DEBUG] - Install-DotNet4IfMissing
2016-03-24 09:08:16,325 [INFO ] - Chocolatey (choco.exe) is now ready.

@ferventcoder
Copy link
Member

Thanks!

@ferventcoder
Copy link
Member

I'm wondering if the profile is missing due to the way Chocolatey calls PowerShell.exe (e.g. -noprofile).

@ferventcoder ferventcoder modified the milestones: 0.9.10, 0.9.10.x Mar 24, 2016
@ferventcoder ferventcoder self-assigned this Mar 24, 2016
@ferventcoder
Copy link
Member

I saw it once during testing and didn't really think about it as it was working in other places. Those other places were running the installer like it would from the web.

@flcdrg
Copy link
Member Author

flcdrg commented Mar 24, 2016

Maybe.. because I definitely have an existing profile.

From: Rob Reynolds [mailto:notifications@github.com]
Sent: Thursday, 24 March 2016 11:30 AM
To: chocolatey/choco choco@noreply.github.com
Cc: David Gardiner david@gardiner.net.au
Subject: Re: [choco] Provide manual steps to updating PowerShell profile if installer can't do it automatically (#667)

I'm wondering if the profile is missing due to the way Chocolatey calls PowerShell.exe (e.g. -noprofile).


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHubhttps://github.com//issues/667#issuecomment-200602215

@ferventcoder
Copy link
Member

So on a first install, it would work if you were using the install script from dot org, but as an upgrade it would not because Chocolatey runs PowerShell without a profile. In that case it would need a backup way of getting to the profile. This may also be why Posh-Git installer never works the first time. cc @dahlbyk

@ferventcoder
Copy link
Member

easy to reproduce. Write a package with Write-Output "profile = '$profile'"

@ferventcoder
Copy link
Member

Confirmed

choco install .\testprofile.1.0.nupkg
Chocolatey v0.9.10-beta1-201-g652a747 Professional
Installing the following packages:
.\testprofile.1.0.nupkg
By installing you accept licenses for the packages.

testprofile v1.0
The package testprofile wants to run 'chocolateyinstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider setting
 'allowGlobalConfirmation'. Run 'choco feature -h' for more details.
Do you want to run the script?
 1) yes
 2) no
 3) print
yes
profile = ''
 The install of testprofile was successful.

Chocolatey installed 1/1 package(s). 0 package(s) failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

@ferventcoder ferventcoder changed the title Provide manual steps to updating PowerShell profile if installer can't do it automatically $profile is empty string when installing packages Mar 24, 2016
@ferventcoder ferventcoder changed the title $profile is empty string when installing packages $profile is empty string when installing packages - does not automatically install the ChocolateyProfile. Mar 24, 2016
@dahlbyk
Copy link

dahlbyk commented Mar 24, 2016

Interesting... When I spawn a new powershell -noprofile from a new cmd I still see the normal $PROFILE path. 😕

@ferventcoder
Copy link
Member

In the new betas it runs a custom PowerShell host. I'm thinking that if noprofile isn't causing the issue, this is. It also would explain why I saw it work in some cases and fail in just one case.

@ferventcoder
Copy link
Member

So I created a package that logs all of the automatic variables to detect anomalies:

https://gist.github.com/ferventcoder/132560fc67fe92d1fb2a

$profile is really the only thing missing.

@ferventcoder
Copy link
Member

I resolved this by setting $profile for now.

ferventcoder added a commit that referenced this issue Mar 26, 2016
When running a custom host, it appears all automatic variables are set
but `$profile`. It is empty for all the different profiles.  When the
profile value is empty and the documents folder exists for the
user, set `$profile` to a string value that represents what it would
have been set to in a normal PowerShell scenario. We can get away with
a single value for `$profile` as most scripts do not look at each of the
profiles, only what is returned by the `$profile` string, which is
`CurrentUserCurrentHost`.

We check for the existence of the documents folder because it tells us
that this is not the LocalSystem user, and we don't want to set
`$profile` when the SYSTEM user is running choco.
@ferventcoder
Copy link
Member

I asked this Stack Overflow question for help on this one: http://stackoverflow.com/q/36239010/18475

@ferventcoder
Copy link
Member

Then I promptly answered it a few hours later. We'll wait for someone to tell me that it is wrong to do it the way I'm doing it.

@ferventcoder
Copy link
Member

This will be fixed in the next beta, but it will only work when upgrading from that next version. If you upgrade from a non-beta this will work fine.

@ferventcoder ferventcoder reopened this Mar 26, 2016
@ferventcoder
Copy link
Member

I still need to provide instructions when it doesn't work

ferventcoder added a commit that referenced this issue Mar 26, 2016
When adding the profile fails, provide advice on how to add it manually.
@flcdrg
Copy link
Member Author

flcdrg commented Mar 27, 2016

Added some comments to the SO question

ferventcoder added a commit that referenced this issue Mar 29, 2016
* stable:
  (GH-460) Amended Template
  (GH-623) Extract Nuspec on Install
  (GH-674)(GH-672) Color Overrides / Fix Write-Host
  (GH-181) log selection to log file only
  (GH-181)(GH-184) Short prompt/Prompt character
  (GH-675) Template include LICENSE/VERIFICATION
  (GH-258) Rename zip to detector.zip
  (GH-572) Fix: The handle is invalid - Output Redirection
  (maint) comments
  (GH-667) Provide How To Add Profile Manually
  (GH-667) PowerShell Custom Host - Set $Profile
  (GH-666) pass Write-ChocolateyError message param
  (GH-673) Ensure Get-BinRoot Warning is Shown
  (GH-666) setup logs colored write-host w/fallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants