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

Update Install-Prerequisites.ps1 #833

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sEb05mAr86
Copy link

@sEb05mAr86 sEb05mAr86 commented Feb 6, 2025

Proposed Changes

(Describe the changes and rationale behind them)

  • improves the check if the winget in preview version is installed

    previewVersion -> v1.10.40-preview
    old
    (& $WingetCmd -v).Replace("v", "").trim()

    new
    (& $Cmd -v | Select-String -Pattern '[\d\.]+').Matches.Value
    but no longer necessary as it only checks whether it is installed or not

  • download only one package of dependencies and not separate for VCLibs / UI.Xaml

    links are hard-coded, which may pose a problem in the future

  • Microsoft Visual C++ Redistributable

    another method to check if MSVCR is installed via
    Get-CimInstance -ClassName "Win32_Product"

    downloads
    link "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe"
    more elegant method install via winget at end of this script / function
    winget install --id "Microsoft.VCRedist.2015+.$OSArch"

  • improve Invoke-WebRequest

    -UseBasicParsing / deprecated

    don't show progressbar
    $ProgressPreference = "SilentlyContinue"
    $ProgressPreference = "Continue"

  • why reinstall winget if the installed version is lower when it can update itself?

    winget upgrade --id Microsoft.AppInstaller

  • what is the point of reset the source if winget is already installed. you don't know if other important sources have been added.

    & $WingetCmd source reset --force

  • please can you add comments and write to log.
    I don't know what makes sense or if there are too many. Thank you

improves the check if the winget in preview version is installed

download only one package of dependencies and not separate for VCLibs / UI.Xaml
    links are hard-coded, which may pose a problem in the future

Microsoft Visual C++ Redistributable latest supported downloads
    another method to check if MSVCR is installed via Get-CimInstance -ClassName "Win32_Product"
    link "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe"
        more elegant method install via winget at end of this script / function

improve Invoke-WebRequest 
    don't show progressbar
        $ProgressPreference = "SilentlyContinue"
        $ProgressPreference = "Continue"
    -UseBasicParsing / deprecated

why reinstall winget if the installed version is lower when it can update itself?

what is the point of reset the source if winget is already installed. you don't know if other important sources have been added.

please add comments and write to log. I don't know what makes sense or if there are too many. Thank you
@sEb05mAr86 sEb05mAr86 closed this Feb 6, 2025
@sEb05mAr86 sEb05mAr86 deleted the r_wau branch February 6, 2025 20:56
@sEb05mAr86 sEb05mAr86 restored the r_wau branch February 6, 2025 21:00
@sEb05mAr86 sEb05mAr86 reopened this Feb 6, 2025
@AndrewDemski-ad-gmail-com
Copy link
Contributor

Hey @sEb05mAr86,

downloads
link "https://aka.ms/vs/17/release/VC_redist.$OSArch.exe"
more elegant method install via winget at end of this script / function
winget install --id "Microsoft.VCRedist.2015+.$OSArch"

I may and most likely will sound like an a-hole but..
Are you trying to use winget to install winget prerequisites needed to install winget to use winget to install those prerequisites?

@sEb05mAr86
Copy link
Author

Hey @AndrewDemski-ad-gmail-com,

you do not need a Microsoft Visual C++ 2015 Redistributable for winget

PackageDependencies

MsVC++ 2015R is installed after winget has been installed.

The dependencies are only checked and installed if winget is not present. If winget is present then the dependencies should already be installed.

If all packages are available in an older version, they can all be updated via winget.

Install-Prerequisites

@KnifMelti
Copy link
Contributor

KnifMelti commented Feb 11, 2025

This happens on Windows Sandbox:

Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet 
Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.

Adding -UseBasicParsing to Invoke-WebRequest makes it run and install the most, but I for one absolutely don't want:
& $WingetCmd upgrade --all --accept-package-agreements --accept-source-agreements --disable-interactivity --silent

After that VC doesn't install and creates a log error every time (Prerequisites checked failed)

@sEb05mAr86
Copy link
Author

Hi @KnifMelti

I've not tested it in sandbox mode.
I tested it with old OS / Win10 22H2 (Hyper-V) and new OS / Win11 24H2

The pull request is a draft, it should not be merched 1-to-1.

& $WingetCmd upgrade --all --accept-package-agreements --accept-source-agreements --disable-interactivity --silent

& $WingetCmd update Microsoft.UI.Xaml.2.8 Microsoft.VCLibs.Desktop.14 --accept-package-agreements --accept-source-agreements

I can't say if this is necessary
--disable-interactivity --silent

PS5

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\username> Get-CimInstance -ClassName "Win32_Product" | Where-Object Name -Like "Microsoft Visual C++ * x64*"

Name             Caption                   Vendor                    Version                   IdentifyingNumber
----             -------                   ------                    -------                   -----------------
Microsoft Vis... Microsoft Visual C++ 2... Microsoft Corporation     10.0.40219                {1D8E6291-B0D5-35EC-8...
Microsoft Vis... Microsoft Visual C++ 2... Microsoft Corporation     12.0.40664                {53CF6934-A98D-3D84-9...
Microsoft Vis... Microsoft Visual C++ 2... Microsoft Corporation     14.42.34433               {382F1166-A409-4C5B-9...
Microsoft Vis... Microsoft Visual C++ 2... Microsoft Corporation     14.42.34433               {E1902FC6-C423-4719-A...
Microsoft Vis... Microsoft Visual C++ 2... Microsoft Corporation     12.0.40664                {010792BA-551A-3AC0-A...


PS C:\Users\username> $urlBase = "microsoft/winget-cli/releases"
PS C:\Users\username>
PS C:\Users\username> $AvailableVersion = (((Invoke-WebRequest -Uri "https://api.github.com/repos/$urlBase/latest" |
>>             ConvertFrom-Json).tag_name) | Select-String '[\d\.]+').Matches.Value
PS C:\Users\username> $AvailableVersion
1.9.25200
PS C:\Users\username> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.26100.2200
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.26100.2200
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS7

PowerShell 7.6.0-preview.2
PS C:\Users\username> Get-CimInstance -ClassName "Win32_Product" | Where-Object Name -Like "Microsoft Visual C++ * x64*"

Name             Caption                   Vendor                    Version                   IdentifyingNumber
----             -------                   ------                    -------                   -----------------
Microsoft Visua… Microsoft Visual C++ 201… Microsoft Corporation     10.0.40219                {1D8E6291-…
Microsoft Visua… Microsoft Visual C++ 201… Microsoft Corporation     12.0.40664                {53CF6934-…
Microsoft Visua… Microsoft Visual C++ 202… Microsoft Corporation     14.42.34433               {382F1166-…
Microsoft Visua… Microsoft Visual C++ 202… Microsoft Corporation     14.42.34433               {E1902FC6-…
Microsoft Visua… Microsoft Visual C++ 201… Microsoft Corporation     12.0.40664                {010792BA-…

PS C:\Users\username> $urlBase = "microsoft/winget-cli/releases"
PS C:\Users\username>
PS C:\Users\username> $AvailableVersion = (((Invoke-WebRequest -Uri "https://api.github.com/repos/$urlBase/latest" |
>>             ConvertFrom-Json).tag_name) | Select-String '[\d\.]+').Matches.Value
PS C:\Users\username> $AvailableVersion
1.9.25200
PS C:\Users\username> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.6.0-preview.2
PSEdition                      Core
GitCommitId                    7.6.0-preview.2
OS                             Microsoft Windows 10.0.26120
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@KnifMelti
Copy link
Contributor

@sEb05mAr86
We use '-UseBasicParsing' to make it work on a newly installed Windows where the Internet Explorer components have not been initialized. This removes the dependency on IE's parser (therefore WSB)

@sEb05mAr86
Copy link
Author

it was a suggestion.

Invoke-WebRequest

You are the program developers and need to consider more dependencies.

@AndrewDemski-ad-gmail-com
Copy link
Contributor

I'd start from considering the execution times.

if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
	$OSArch = "arm64"
}
elseif ($env:PROCESSOR_ARCHITECTURE -like "*64*") {
	$OSArch = "x64"
}
else {
	$OSArch = "x86"
}
Measure-Command -Expression {
    Get-CimInstance -ClassName "Win32_Product" | 
    Where-Object Name -Like "Microsoft Visual C++ * $OSArch*"
}

On a relatively fast machine it takes over half a minute to see the results.

Measure-Command -Expression {
    Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop' -AllUsers
}

Existing method is much faster, it takes less than 1s to do that.

@sEb05mAr86
Copy link
Author

Aren't these different packages?

Microsoft.VCLibs.140.00.UWPDesktop
Microsoft.VCRedist.2015+.x64

You're right, it's not the fastest method

@AndrewDemski-ad-gmail-com
Copy link
Contributor

Aren't these different packages?

Microsoft.VCLibs.140.00.UWPDesktop
Microsoft.VCRedist.2015+.x64

You're right, it's not the fastest method

Yes,
The first is deployed as APPX, the other is the well-known legacy setup/MSI.

I wish that one day winget will be shipped as a standalone package, with zero external dependencies.

@Romanitho Romanitho changed the base branch from main to develop February 23, 2025 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants