DanGough / Nevergreen

This module is an alternative to Evergreen, and allows you to find the latest version and download URL for various Windows apps. Evergreen uses API queries to obtain its data whereas this module is more focussed on web scraping. This is more prone to breaking when websites are changed, hence the name.
The Unlicense
77 stars 18 forks source link

[New App Request] Microsoft VC++ redistributables #110

Closed AScott-WWF closed 3 months ago

AScott-WWF commented 3 months ago

As Microsoft have not until recently published the latest version number on the VC++ release url (https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170), it was previously necessary to download the version available and then check the version of the downloaded file. This appears to be no longer necessary as they are finally publishing the release version on the page, This can be found directly below the heading on this link: https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#latest-microsoft-visual-c-redistributable-version

The latest version is 14.40.33810.0

So it is now possible (with the Nevergreen script below) to return the release number and resolve the urls for x86, x64 and ARM64 version downloads.

N.B. Evergreen currently serves a very good 3rd Party alternative product "VisualCppRedistAIO" from https://github.com/abbodi1406/vcredist for VC++ redistributables, but as this software is not directly from the source vendor (Microsoft), some users / orgs may prefer not to use this repackaged version.

The script:

# Get-MicrosoftVCPPRedist.ps1

# Define AppName
$AppName = "Microsoft Visual C++ Redistributable"

$ReleaseUrl = "https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170"

Write-Verbose "Obtaining $($AppName) Release Versions from $($ReleaseUrl)...`n"

# Main script to fetch and process links
$AppVersions = @(
    @{AppName = $($AppName); Architecture = 'x64'; Type = 'exe'; Pattern = 'x64\.exe'; VersionPattern = 'The latest version is <code>(\d+\.\d+\.\d+\.\d+)</code>'}
    @{AppName = $($AppName); Architecture = 'x86'; Type = 'exe'; Pattern = 'x86\.exe'; VersionPattern = 'The latest version is <code>(\d+\.\d+\.\d+\.\d+)</code>'}
    @{AppName = $($AppName); Architecture = 'ARM64'; Type = 'exe'; Pattern = 'arm64\.exe'; VersionPattern = 'The latest version is <code>(\d+\.\d+\.\d+\.\d+)</code>'}
)

foreach ($AppVersion in $AppVersions) {
    $SearchCount = 1 # This may need increasing as future versions are released

    #Build each link with File Type specific versions
    $URL = (Get-Link -Uri $ReleaseUrl -MatchProperty href -Pattern $AppVersion.Pattern)
    $URL = (Resolve-Uri -Uri (Get-Link -Uri $ReleaseUrl -MatchProperty href -Pattern $AppVersion.Pattern)).Uri
    $Version = Get-Version -Uri $ReleaseURL -Pattern $AppVersion.VersionPattern

    do {
        if ($URL) {
            New-NevergreenApp -Name $($AppVersion.AppName) -Architecture $($AppVersion.Architecture) -Version $($Version) -Uri $($URL) -Type $($AppVersion.Type)
            break
        }

        $SearchCount--
    } until ($SearchCount -eq 0)

    if ($SearchCount -eq 0) {
        Write-Warning "Could not find release for $($AppName) $($AppVersion.Type)"
    }
}

$ReleaseNotesUrl = "https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170"
Write-Verbose "$($AppName) (Version: $($Version)) release notes are available here: $($ReleaseNotesUrl)"
DanGough commented 3 months ago

There is already a separate module VcRedist that caters for these (by the same author as Evergreen, Aaron Parker). I don't want to support any apps in Nevergreen that are already in Evergreen or VcRedist, unless there's a good reason.

AScott-WWF commented 3 months ago

Thanks @DanGough I'd overlooked that module - Now added to my PowerShell module arsenal ;-)

AScott-WWF commented 3 months ago

Not required as VcRedist PowerShell Module solves this issue