microsoft / vssetup.powershell

PowerShell module to interact with Visual Studio Setup
MIT License
233 stars 41 forks source link

Cannot Remove-Module since VSSetupVersionTable is constant #47

Closed heaths closed 6 years ago

heaths commented 6 years ago

Apparently never tested just removing the VSSetup module. One cannot since $VSSetupVersionTable is constant, nor can it be forcibly removed. Should make it read-only. Seems there'd be little incentive to change the values and $PSVersionTable doesn't prevent it either. Should also probably set the AllScope option as is set on $PSVersionTable.

mide1234 commented 6 years ago

I guess it is related but I am not an expert in this area. When importing the VSSetup module one can see the following exception:

Import-Module VSSetup [<<==>>] Exception: Cannot overwrite variable VSSetupVersionTable because it is read-only or constant.

The VSSetup is installed on a an environment where it might be already installed via the following code:

# User has to exit the current session after installing the latest version of PowerShellGet. - https://github.com/PowerShell/PowerShellGet/issues/227
PowerShell -Command {
    # VSSetup requires PSGet to be installed https://docs.microsoft.com/en-us/powershell/gallery/installing-psget
    Write-Host "Installing NugetProvider for powershell"    
    Install-PackageProvider Nuget –Force;
    Write-Host "NugetProvider for powershell installed"

    Write-Host "Installing PowerShellGet"   
    Install-Module –Name PowerShellGet –Force;
    Write-Host "PowerShellGet installed"

    # VSSetup installation: https://github.com/Microsoft/vssetup.powershell
    Write-Host "Installing VSSetup" 
    Install-Module VSSetup -Scope CurrentUser -Force;
    Write-Host "VSSetup installed"
}
SimonTaubertTCNE commented 6 years ago

For us this has resulted in a total breakdown of the entire build and deploy process, since psake includes the line Import-Module VSSetup which throws Exception: Cannot overwrite variable VSSetupVersionTable because it is read-only or constant. Psake failed...

mide1234 commented 6 years ago

Yeah, we are in pretty much the same position as we are using Psake as well. Is there currently any known workaround? Would downgrade of VSSetup help? And if so, to what version should we downgrade?

jwittner commented 6 years ago

I've effectively abandoned use of version 2.2.0 because of this issue.

pianomanjh commented 6 years ago

Also struggling with our builds due to this issue + psake.

SimonTaubertTCNE commented 6 years ago

I'm glad to see I'm not alone, but unfortunately I have no workaround as of yet. I got the build to pass once by manually commenting out the specified line i the psake code (ConfigureBuildEnvironment.ps1) on the build server. But that of course gets run over when the build scripts fetches the psake nuget package next time...

@jwittner: How do you mean "abandoned"? I can't see a way of choosing which version to use, or is there?

mide1234 commented 6 years ago

@SimonTaubertTCNE My current workaround is a bit dummy, but basically removes all versions of VSSetup and installs the working one (prior to version 2.2.0) and it works for me :)

Uninstall-Module VSSetup -AllVersions -Force
Install-Module VSSetup -Scope CurrentUser -Force -MaximumVersion 2.0.1;
SimonTaubertTCNE commented 6 years ago

@mide1234 Ok, nice. But I guess there is a problem still since the Install command without the MaximumVersion flag is in the Psake source code. Or did you get that flow working?

mide1234 commented 6 years ago

@SimonTaubertTCNE Well, I do not think that Psake installs VSSetup. It relies on it to be installed. At least it seems to be the case for Psake 4.7.0. See step 5: https://github.com/psake/psake

SimonTaubertTCNE commented 6 years ago

@mide1234 That's how I understood it prior to this issue, but the exception thrown is from the psake source code: https://github.com/psake/psake/blob/09713113ec9cef6f240e83147e549c62cf0a7f87/src/private/ConfigureBuildEnvironment.ps1#L100 (here on disk: \Packages\psake.4.7.0\tools\psake\private\ConfigureBuildEnvironment.ps1 line 99)

SimonTaubertTCNE commented 6 years ago

@mide1234 Your workaround did indeed save the day, thanks!

One fix was needed though, the script, when run in a console window, prompted for a verification that the Powershell gallery was a trusted source. This made the process halt in an infinite loop when run from an automation server like Jenkins since it never got an answer. But this was solved by setting the installation policy once and for all manually first: Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

mide1234 commented 6 years ago

@SimonTaubertTCNE You are welcome, I am glad you were able to fix your build :)