From 5c91f611b66f92e22cbb32cd9e36ebb3b9c7d997 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 12:49:35 +0100 Subject: [PATCH 01/13] Create draft PR for #953 From 687c9054cd56e7ce7f57c54dfdb7370940b26016 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 18:27:33 +0100 Subject: [PATCH 02/13] dotnet exact version detect or install --- scripts/check_requisites.ps1 | 134 ++++++++++++++++++++++++++++------- 1 file changed, 107 insertions(+), 27 deletions(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index f6173b649..cd79c89a8 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -1,12 +1,11 @@ ## Check pre-requisites # Definition of the requisities and locations +$dotNetInstallationScriptLocation = "https://dot.net/v1/dotnet-install.ps1" $dotNetRequiredVersion = "10.0.100" -$dotNetWingetInstall = "Microsoft.DotNet.SDK.10 --version 10.0.100" - $visualStudioRequiredVersionRange = "[17.8.0,18.0)"; -$apaxRequiredVersion = "4.2.0" +$apaxRequiredVersion = "4.1.1" $apaxUrl = "https://console.simatic-ax.siemens.io/" $axCodeRequiredVersion = "1.94.2" @@ -21,29 +20,114 @@ $expectedVCToolsInstallDir = "C:\Program Files (x86)\Microsoft Visual Studio\201 $vsBuildToolInstallerDownloadLocation = "https://aka.ms/vs/16/release/vs_buildtools.exe" $vsBuildToolRequiredComponents = "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.Windows10SDK.18362" -# List all installed .NET SDKs -$dotnetSDKs = (dotnet --list-sdks 2>$null) -$dotnetInstalled = $false +# Function to check if required version of dotnet is installed +function VerifyDotNet { + param( + [Parameter(Mandatory)][string]$DotNetRequiredVersion, + [string]$DotNetExePath + ) + + $dotnetInstalled = $false -foreach ($sdk in $dotnetSDKs) -{ - if ($sdk -match [regex]::Escape($dotNetRequiredVersion)) - { - $dotnetInstalled = $true - break + if (-not $DotNetExePath) { + # default per-user install path + $DotNetExePath = Join-Path $env:USERPROFILE ".dotnet\dotnet.exe" } + + if (-not (Test-Path -LiteralPath $DotNetExePath)) { + Write-Host "dotnet.exe not found at '$DotNetExePath' (PATH may not be updated yet)." -ForegroundColor Red + $dotnetInstalled = $false + } + + $dotnetSDKs = & $DotNetExePath --list-sdks 2>$null + foreach ($sdk in $dotnetSDKs) { + if ($sdk -match "^$([regex]::Escape($DotNetRequiredVersion))\s") { + $dotnetInstalled = $true + break + } + } + if ($dotnetInstalled) + { + Write-Host ".NET $dotNetRequiredVersion SDK detected." -ForegroundColor Green + } + else + { + Write-Host ".NET $dotNetRequiredVersion SDK is not installed." -ForegroundColor Red + } + return $dotnetInstalled } +# Function to download and install dotnet +function InstallDotNet { + param([Parameter(Mandatory)][string]$DotNetRequiredVersion) -if ($dotnetInstalled) -{ - Write-Host ".NET $dotNetRequiredVersion SDK detected." -ForegroundColor Green -} -else + $dotnetInstall = "dotnet-install.ps1" + $installDir = Join-Path $env:USERPROFILE ".dotnet" + $dotnetExe = Join-Path $installDir "dotnet.exe" + + try { + Write-Host "Downloading $dotnetInstall..." + Invoke-WebRequest -Uri $dotNetInstallationScriptLocation -OutFile $dotnetInstall + + if (-not (Test-Path -LiteralPath $dotnetInstall)) { + Write-Host "Failed to download $dotnetInstall." -ForegroundColor Red + exit 1 + } + + $scriptPath = Join-Path $PSScriptRoot $dotnetInstall + Write-Host "Installing .NET SDK $DotNetRequiredVersion to $installDir" + + $arguments = @( + "-NoProfile" + "-ExecutionPolicy Bypass" + "-File `"$scriptPath`"" + "-Version `"$DotNetRequiredVersion`"" + "-InstallDir `"$installDir`"" + "-NoPath" # we'll set PATH ourselves in this session (reliable) + ) + + $proc = Start-Process powershell.exe -ArgumentList ($arguments -join ' ') -Wait -PassThru + if ($proc.ExitCode -ne 0) { + Write-Host "dotnet-install.ps1 failed with exit code $($proc.ExitCode)" -ForegroundColor Red + exit 1 + } + + # Make dotnet available in *this* PowerShell session: + $env:DOTNET_ROOT = $installDir + if ($env:PATH -notlike "*$installDir*") { + $env:PATH = "$installDir;$env:PATH" + } + + $dotnetInstalled = VerifyDotNet -DotNetRequiredVersion $DotNetRequiredVersion -DotNetExePath $dotnetExe + if (-not $dotnetInstalled) { + Write-Host "Error installing dotnet (or dotnet not visible in this session)." -ForegroundColor Red + exit 1 + } + + Write-Host ".NET SDK $DotNetRequiredVersion installed successfully." -ForegroundColor Green + } + catch { + Write-Host "Error installing dotnet: $($_.Exception.Message)" -ForegroundColor Red + exit 1 + } + finally { + # cleanup silently + Remove-Item -Path (Join-Path $PSScriptRoot $dotnetInstall) -Force -ErrorAction SilentlyContinue + } +} + +$dotnetInstalled = VerifyDotNet -DotNetRequiredVersion $dotNetRequiredVersion + +# Check .NET SDKs +if (-not $dotnetInstalled) { - Write-Host ".NET $dotNetRequiredVersion SDK is not installed." -ForegroundColor Red + $response = Read-Host ".NET $dotNetRequiredVersion SDK is not installed. Would you like to install it now? (Y/N)" + if ($response -eq 'Y' -or $response -eq 'y') { + InstallDotNet $dotNetRequiredVersion + } } +exit 0 # Check for Visual Studio if (Test-Path $vsWhereLocation) @@ -79,7 +163,7 @@ try else { Write-Host "Apax version mismatch. Expected $apaxRequiredVersion but found $apaxVersion." -ForegroundColor Red - Write-Host "Run apax self-update $apaxRequiredVersion." -ForegroundColor Red + Write-Host "Run apax self-update $apaxVersion." -ForegroundColor Red } } catch @@ -275,6 +359,7 @@ if($hasFeedAccess) } } + # Define a function to prompt and download function PromptAndDownload { param( @@ -289,14 +374,7 @@ function PromptAndDownload { } } -# Check .NET SDKs -if (-not $dotnetInstalled) -{ - $response = Read-Host ".NET $dotNetRequiredVersion SDK is not installed. Would you like to install it now? (Y/N)" - if ($response -eq 'Y' -or $response -eq 'y') { - winget install $dotNetWingetInstall - } -} + # Check for Visual Studio if (-not $vsVersion) { @@ -332,6 +410,8 @@ Note: Treat your personal access token like a password. Keep it secure and do no Write-Host "You need to add the GitHub NuGet feed to your sources manually." $nugetGuide } + + # Function to download VS Build Tools function Download-VSBuildTools { From ab2a9c38726ff1018b2bfffbd6d1ec12726d9996 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 19:17:12 +0100 Subject: [PATCH 03/13] DotNet SDK exact version installation using checkrequisities script with env:PATH modification --- scripts/check_requisites.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index cd79c89a8..527c3c07b 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -113,6 +113,15 @@ function InstallDotNet { finally { # cleanup silently Remove-Item -Path (Join-Path $PSScriptRoot $dotnetInstall) -Force -ErrorAction SilentlyContinue + # Persist PATH for the current user (future shells) + $dotnetDir = Join-Path $env:USERPROFILE ".dotnet" + + $existingUserPath = [Environment]::GetEnvironmentVariable("PATH", "User") + + if ($existingUserPath -notlike "*$dotnetDir*") { + $newUserPath = "$dotnetDir;$existingUserPath" + [Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User") + } } } From fd2f5d425a13830aa6dc3f1913bcf0b571a925c4 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 20:50:12 +0100 Subject: [PATCH 04/13] Axcode version check --- scripts/check_requisites.ps1 | 133 ++++++++++++++++++++++++++++------- 1 file changed, 107 insertions(+), 26 deletions(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index 527c3c07b..8f219b605 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -5,9 +5,10 @@ $dotNetRequiredVersion = "10.0.100" $visualStudioRequiredVersionRange = "[17.8.0,18.0)"; +$axCodeRequiredVersion = "1.94.2" + $apaxRequiredVersion = "4.1.1" $apaxUrl = "https://console.simatic-ax.siemens.io/" -$axCodeRequiredVersion = "1.94.2" $inxtonRegistryUrl = "https://npm.pkg.github.com/" @@ -19,7 +20,9 @@ $expectedVCToolsInstallDir = "C:\Program Files (x86)\Microsoft Visual Studio\201 $vsBuildToolInstallerDownloadLocation = "https://aka.ms/vs/16/release/vs_buildtools.exe" $vsBuildToolRequiredComponents = "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.Windows10SDK.18362" - +#################################################################################### +# DOT NET # +#################################################################################### # Function to check if required version of dotnet is installed function VerifyDotNet { param( @@ -135,10 +138,10 @@ if (-not $dotnetInstalled) InstallDotNet $dotNetRequiredVersion } } - -exit 0 +#################################################################################### +# VISUAL STUDIO # +#################################################################################### # Check for Visual Studio - if (Test-Path $vsWhereLocation) { $vsVersion = & $vsWhereLocation -version $visualStudioRequiredVersionRange -products * -property catalog_productDisplayVersion @@ -158,6 +161,105 @@ else Write-Host "vswhere tool not found. Unable to determine if Visual Studio is installed." -ForegroundColor Yellow Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow } +#################################################################################### +# AX CODE # +#################################################################################### +# Function to check if the actual version is equal to required version +function MajorMinorBuildRevisionEqual { + param( + [Parameter(Mandatory)][string]$Package, + [Parameter(Mandatory)][string]$ActualVersion, + [Parameter(Mandatory)][string]$RequiredVersion + ) + + $retval = $false + + $Actual = [version]$ActualVersion + $Required = [version]$RequiredVersion + + if ($Actual -eq $Required) + { + Write-Host "The actual version of the $Package ($ActualVersion) is equal to required ($RequiredVersion)." -ForegroundColor Green + $retval = $true + } + else + { + Write-Host "The actual version of the $Package ($ActualVersion) is different to required ($RequiredVersion)." -ForegroundColor Red + } + return $retval +} +# Function to check if the actual version is equal or higher then required version +function MajorMinorBuildRevisionEqualOrHigher { + param( + [Parameter(Mandatory)][string]$Package, + [Parameter(Mandatory)][string]$ActualVersion, + [Parameter(Mandatory)][string]$RequiredVersion + ) + + $retval = $false + + $Actual = [version]$ActualVersion + $Required = [version]$RequiredVersion + + if ($Actual -ge $Required) + { + Write-Host "The actual version of the $Package ($ActualVersion) is equal or higher then required ($RequiredVersion)." -ForegroundColor Green + $retval = $true + } + else + { + Write-Host "The actual version of the $Package ($ActualVersion) is lower then required ($RequiredVersion)." -ForegroundColor Red + } + return $retval +} +# Function to check if the major and minor version equal or and build and revision version is equal or higher +function MajorMinorEqualBuildRevisionEqualOrHigher { + param( + [Parameter(Mandatory)][string]$Package, + [Parameter(Mandatory)][string]$ActualVersion, + [Parameter(Mandatory)][string]$RequiredVersion + ) + + $retval = $false + + $Actual = [version]$ActualVersion + $Required = [version]$RequiredVersion + + if ($Actual.Major -eq $Required.Major -and $Actual.Minor -eq $Required.Minor -and $Actual.Build -ge $Required.Build -and $Actual.Revision -ge $Required.Revision ) + { + Write-Host "The actual version of the $Package ($ActualVersion) does fit the required ($RequiredVersion)." -ForegroundColor Green + $retval = $true + } + else + { + Write-Host "The actual version of the $Package ($ActualVersion) does not fit the required ($RequiredVersion)." -ForegroundColor Red + } + return $retval +} + + + +# Define the command to get the version +$command = "axcode --version" +# Execute the command and capture the output +try +{ + $version = Invoke-Expression $command + $ActualVersion = $version.Item(0) + # Compare the retrieved version with the expected version + if (-not (MajorMinorBuildRevisionEqualOrHigher -Package "AX Code" -ActualVersion $ActualVersion -RequiredVersion $axCodeRequiredVersion)) + { + Write-Host "The AXCode version does not match the expected version: $axCodeRequiredVersion. It's highly recommended to update it." -ForegroundColor Red + } +} +catch +{ + Write-Host "Error: Unable to determine the AXCode version. Ensure AXCode is correctly installed and accessible from the command line." -ForegroundColor Red + exit 1 +} + + +exit 0 # Check for apax $isApaxInstalled = $false @@ -272,27 +374,6 @@ Note: Treat your personal access token like a password. Keep it secure and do no } -# Define the command to get the version -$command = "axcode --version" -# Execute the command and capture the output -try -{ - $version = Invoke-Expression $command - - # Compare the retrieved version with the expected version - if ($version -eq $axCodeRequiredVersion) - { - Write-Host "The AXCode version matches the expected version: $axCodeRequiredVersion" -ForegroundColor Green - } - else - { - Write-Host "The AXCode version does not match the expected version: $axCodeRequiredVersion" -ForegroundColor Red - } -} -catch -{ - Write-Host "Error: Unable to determine the AXCode version. Ensure AXCode is correctly installed and accessible from the command line." -ForegroundColor Red -} $headers = @{ From 7f6ecd91baed9a20453968f56a2c6d73d80bc2d1 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 21:57:41 +0100 Subject: [PATCH 05/13] Node.js installation --- scripts/check_requisites.ps1 | 40 ++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index 8f219b605..1992ed9b4 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -237,8 +237,6 @@ function MajorMinorEqualBuildRevisionEqualOrHigher { return $retval } - - # Define the command to get the version $command = "axcode --version" # Execute the command and capture the output @@ -258,10 +256,9 @@ catch exit 1 } - -exit 0 - -# Check for apax +#################################################################################### +# APAX # +#################################################################################### $isApaxInstalled = $false try { @@ -280,8 +277,39 @@ try catch { Write-Host "Apax is not installed or not found in PATH. You need to have valid SIMATIC-AX license." -ForegroundColor Red + try + { + $nodeVersion = (node -v).Trim() + } + catch + { + Write-Host "Node.js is not installed or not found in PATH." -ForegroundColor Red + Write-Host "Installing Node.js LTS via winget..." + + $packageId = "OpenJS.NodeJS.LTS" + + $winget = Get-Command winget -ErrorAction SilentlyContinue + if (-not $winget) { + throw "winget is not available on this system." + } + + winget install ` + --id $packageId ` + --exact ` + --silent ` + --accept-package-agreements ` + --accept-source-agreements + + $env:Path = "$env:ProgramFiles\nodejs;$env:Path" + + # Verify + node -v + npm -v + + } } +exit 0 $accessToApax = $false; if($isApaxInstalled) From 2a7bf5be22b2f0c8987f471ed3138f6806f919b5 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 22:43:26 +0100 Subject: [PATCH 06/13] apax login --- scripts/check_requisites.ps1 | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index 1992ed9b4..c23da1c85 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -257,21 +257,17 @@ catch } #################################################################################### -# APAX # +# APAX INSTALATION # #################################################################################### $isApaxInstalled = $false try { $apaxVersion = (apax --version).Trim() - if ($apaxVersion -eq $apaxRequiredVersion) - { - Write-Host "Apax $apaxRequiredVersion detected." -ForegroundColor Green - $isApaxInstalled = $true; - } - else + # Compare the retrieved version with the expected version + if (-not (MajorMinorBuildRevisionEqualOrHigher -Package "APAX" -ActualVersion $apaxVersion -RequiredVersion $apaxRequiredVersion)) { - Write-Host "Apax version mismatch. Expected $apaxRequiredVersion but found $apaxVersion." -ForegroundColor Red - Write-Host "Run apax self-update $apaxVersion." -ForegroundColor Red + Write-Host "The APAX version does not match the expected version: $apaxRequiredVersion. It's highly recommended to update it." -ForegroundColor Red + Write-Host "The APAX version does not match the expected version: $apaxRequiredVersion. It's highly recommended to update it." -ForegroundColor Red } } catch @@ -309,8 +305,9 @@ catch } } -exit 0 - +#################################################################################### +# APAX LOGIN AX # +#################################################################################### $accessToApax = $false; if($isApaxInstalled) { @@ -351,6 +348,10 @@ catch Write-Host "Error: Unable to access apax packages. Check your connections, firewall, credentials etc. : $($_.Exception.Message)" -ForegroundColor Red } +#################################################################################### +# APAX LOGIN AX # +#################################################################################### + # Check the access to the external @inxton registry $jsonData = Get-Content -Raw -Path "$env:USERPROFILE\.apax\auth.json" | ConvertFrom-Json @@ -402,7 +403,7 @@ Note: Treat your personal access token like a password. Keep it secure and do no } - +exit 0 $headers = @{ "Authorization" = "Bearer $userToken" From c7d55515806a022d8f6082f7b1f99817f129480e Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 22:54:49 +0100 Subject: [PATCH 07/13] reordered --- scripts/check_requisites.ps1 | 112 ++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index c23da1c85..a8a4640cb 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -138,29 +138,7 @@ if (-not $dotnetInstalled) InstallDotNet $dotNetRequiredVersion } } -#################################################################################### -# VISUAL STUDIO # -#################################################################################### -# Check for Visual Studio -if (Test-Path $vsWhereLocation) -{ - $vsVersion = & $vsWhereLocation -version $visualStudioRequiredVersionRange -products * -property catalog_productDisplayVersion - if (-not $vsVersion) - { - Write-Host "Visual Studio is not detected in required version or update. Required version range is $visualStudioRequiredVersionRange" -ForegroundColor Yellow - Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow - } - else - { - Write-Host "Visual Studio detected: $vsVersion" -ForegroundColor Green - Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor DarkBlue - } -} -else -{ - Write-Host "vswhere tool not found. Unable to determine if Visual Studio is installed." -ForegroundColor Yellow - Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow -} + #################################################################################### # AX CODE # #################################################################################### @@ -305,6 +283,19 @@ catch } } +# Check for Apax - Assuming there's a direct link for Apax +# (Note: You might want to guide users more specifically since Apax's installation might not be as straightforward as opening a URL.) +if (-not $isApaxInstalled) { + $apaxGuide = @" +To download Apax: +1. Visit https://console.simatic-ax.siemens.io/downloads in your browser. +2. Log in with your credentials. +3. Follow the on-site instructions to download and install Apax. +"@ + Write-Host "Apax is not installed or not found in PATH. You need to have a valid SIMATIC-AX license." $apaxGuide -ForegroundColor Yellow +} + + #################################################################################### # APAX LOGIN AX # #################################################################################### @@ -349,7 +340,7 @@ catch } #################################################################################### -# APAX LOGIN AX # +# APAX LOGIN INXTON # #################################################################################### # Check the access to the external @inxton registry @@ -403,8 +394,6 @@ Note: Treat your personal access token like a password. Keep it secure and do no } -exit 0 - $headers = @{ "Authorization" = "Bearer $userToken" "User-Agent" = "PowerShell" @@ -479,6 +468,47 @@ if($hasFeedAccess) } +if(-not ($isFeedAlreadyAdded -and $hasFeedAccess -and $hasFeedAutorization)) +{ +$nugetGuide = @" +To manually add the GitHub NuGet feed to your sources: + +1. Generate a Personal Access Token on GitHub with 'read:packages', 'write:packages', and 'delete:packages' (if needed) permissions. +2. Open a command prompt or terminal. +3. Use the following command to add the feed to your NuGet sources: + dotnet nuget add source --username [YOUR_GITHUB_USERNAME] --password [YOUR_PERSONAL_ACCESS_TOKEN] --store-password-in-clear-text --name gh-packages-inxton $nugetFeedUrl + + Replace [YOUR_GITHUB_USERNAME] with your actual GitHub username and [YOUR_PERSONAL_ACCESS_TOKEN] with the token you generated. + +Note: Treat your personal access token like a password. Keep it secure and do not share it. +"@ + Write-Host "You need to add the GitHub NuGet feed to your sources manually." $nugetGuide +} + +#################################################################################### +# VISUAL STUDIO # +#################################################################################### +# Check for Visual Studio +if (Test-Path $vsWhereLocation) +{ + $vsVersion = & $vsWhereLocation -version $visualStudioRequiredVersionRange -products * -property catalog_productDisplayVersion + if (-not $vsVersion) + { + Write-Host "Visual Studio is not detected in required version or update. Required version range is $visualStudioRequiredVersionRange" -ForegroundColor Yellow + Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow + } + else + { + Write-Host "Visual Studio detected: $vsVersion" -ForegroundColor Green + Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor DarkBlue + } +} +else +{ + Write-Host "vswhere tool not found. Unable to determine if Visual Studio is installed." -ForegroundColor Yellow + Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow +} + # Define a function to prompt and download function PromptAndDownload { param( @@ -493,41 +523,13 @@ function PromptAndDownload { } } - - # Check for Visual Studio if (-not $vsVersion) { PromptAndDownload "Visual Studio is not detected." "https://visualstudio.microsoft.com/vs/" } -# Check for Apax - Assuming there's a direct link for Apax -# (Note: You might want to guide users more specifically since Apax's installation might not be as straightforward as opening a URL.) -if (-not $isApaxInstalled) { - $apaxGuide = @" -To download Apax: -1. Visit https://console.simatic-ax.siemens.io/downloads in your browser. -2. Log in with your credentials. -3. Follow the on-site instructions to download and install Apax. -"@ - Write-Host "Apax is not installed or not found in PATH. You need to have a valid SIMATIC-AX license." $apaxGuide -ForegroundColor Yellow -} - -if(-not ($isFeedAlreadyAdded -and $hasFeedAccess -and $hasFeedAutorization)) -{ -$nugetGuide = @" -To manually add the GitHub NuGet feed to your sources: - -1. Generate a Personal Access Token on GitHub with 'read:packages', 'write:packages', and 'delete:packages' (if needed) permissions. -2. Open a command prompt or terminal. -3. Use the following command to add the feed to your NuGet sources: - dotnet nuget add source --username [YOUR_GITHUB_USERNAME] --password [YOUR_PERSONAL_ACCESS_TOKEN] --store-password-in-clear-text --name gh-packages-inxton $nugetFeedUrl - - Replace [YOUR_GITHUB_USERNAME] with your actual GitHub username and [YOUR_PERSONAL_ACCESS_TOKEN] with the token you generated. +exit 0 -Note: Treat your personal access token like a password. Keep it secure and do not share it. -"@ - Write-Host "You need to add the GitHub NuGet feed to your sources manually." $nugetGuide -} From fb0c028a020669babceadebc9e39098024b8b729 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 23:01:37 +0100 Subject: [PATCH 08/13] wip --- scripts/check_requisites.ps1 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index a8a4640cb..cfbb463f7 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -528,11 +528,6 @@ if (-not $vsVersion) { PromptAndDownload "Visual Studio is not detected." "https://visualstudio.microsoft.com/vs/" } -exit 0 - - - - # Function to download VS Build Tools function Download-VSBuildTools { @@ -552,6 +547,10 @@ function Download-VSBuildTools } } + +#################################################################################### +# VISUAL STUDIO BUILD TOOLS # +#################################################################################### # Function to install VS Build Tools function Install-VSBuildTools { From 72390847baf92908de7e21db7983b142d1a222ff Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 23:19:57 +0100 Subject: [PATCH 09/13] wip --- scripts/check_requisites.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index cfbb463f7..c45c82ee0 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -242,7 +242,11 @@ try { $apaxVersion = (apax --version).Trim() # Compare the retrieved version with the expected version - if (-not (MajorMinorBuildRevisionEqualOrHigher -Package "APAX" -ActualVersion $apaxVersion -RequiredVersion $apaxRequiredVersion)) + if ((MajorMinorBuildRevisionEqualOrHigher -Package "APAX" -ActualVersion $apaxVersion -RequiredVersion $apaxRequiredVersion)) + { + $isApaxInstalled = $true + } + else { Write-Host "The APAX version does not match the expected version: $apaxRequiredVersion. It's highly recommended to update it." -ForegroundColor Red Write-Host "The APAX version does not match the expected version: $apaxRequiredVersion. It's highly recommended to update it." -ForegroundColor Red From 318199bc638a0b8460c286281c1b4d5d9781c861 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Mon, 12 Jan 2026 23:53:50 +0100 Subject: [PATCH 10/13] Visual Studio 2026 --- scripts/check_requisites.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index c45c82ee0..ba9186912 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -3,7 +3,7 @@ $dotNetInstallationScriptLocation = "https://dot.net/v1/dotnet-install.ps1" $dotNetRequiredVersion = "10.0.100" -$visualStudioRequiredVersionRange = "[17.8.0,18.0)"; +$visualStudioRequiredVersionRange = "[17.8.0,19.0)"; $axCodeRequiredVersion = "1.94.2" From 73208333bf705242b65ed9ec1540f5afddccde78 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Wed, 14 Jan 2026 10:28:04 +0100 Subject: [PATCH 11/13] bcp --- scripts/check_requisites.ps1 | 729 +++++++++++++++++++++++++++++------ 1 file changed, 614 insertions(+), 115 deletions(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index ba9186912..be631d0ee 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -1,32 +1,425 @@ ## Check pre-requisites # Definition of the requisities and locations +#################################################################################### +# DOT NET # +#################################################################################### $dotNetInstallationScriptLocation = "https://dot.net/v1/dotnet-install.ps1" -$dotNetRequiredVersion = "10.0.100" - -$visualStudioRequiredVersionRange = "[17.8.0,19.0)"; - +$dotNetSDKRequiredVersion = "10.0.100" +$dotNetDesktopRuntimeRequiredVersion = "8.0.22" +#################################################################################### +# AX CODE # +#################################################################################### $axCodeRequiredVersion = "1.94.2" - +$axCodeDownloadUrl = "https://console.simatic-ax.siemens.io/downloads" +#################################################################################### +# APAX AX # +#################################################################################### $apaxRequiredVersion = "4.1.1" $apaxUrl = "https://console.simatic-ax.siemens.io/" - +#################################################################################### +# APAX LOGIN INXTON # +#################################################################################### $inxtonRegistryUrl = "https://npm.pkg.github.com/" - $nugetFeedUrl = "https://nuget.pkg.github.com/inxton/index.json" - - +#################################################################################### +# VISUAL STUDIO # +#################################################################################### +$visualStudioRequiredVersionRange = "[17.8.0,19.0)"; $vsWhereLocation = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -$expectedVCToolsInstallDir = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133" +#################################################################################### +# VISUAL STUDIO BUILD TOOLS # +#################################################################################### +$vsBuildToolInstallationURL = "https://aka.ms/vs/16/release/vs_buildtools.exe" +$vsBuildToolInstallCommand = ".\vs_buildtools.exe --wait --norestart --nocache --passive --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.Windows10SDK.19041" +$vsBuildToolRequiredVersion = "16.11.36631.11" +$expectedVCToolsInstallDir = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133" $vsBuildToolInstallerDownloadLocation = "https://aka.ms/vs/16/release/vs_buildtools.exe" $vsBuildToolRequiredComponents = "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.Windows10SDK.18362" + +######################################################################################################################################################################## +# VERSION CHECKERS # #################################################################################### -# DOT NET # +# Function to check if the actual version is equal to required version +function MajorMinorBuildRevisionEqual { + param + ( + [Parameter(Mandatory)][string]$Item, + [Parameter(Mandatory)][string]$ActualVersion, + [Parameter(Mandatory)][string]$RequiredVersion, + [switch]$Silent + ) + + $retval = $false + + $Actual = [version]$ActualVersion + $Required = [version]$RequiredVersion + + if ($Actual -eq $Required) + { + $retval = $true + if(-not $Silent) + { + Write-Host "The actual version of the $Item ($ActualVersion) is equal to required ($RequiredVersion)." -ForegroundColor Green + } + + } + elseif(-not $Silent) + { + Write-Host "The actual version of the $Item ($ActualVersion) is different to required ($RequiredVersion)." -ForegroundColor Red + } + return $retval +} +# Function to check if the actual version is equal or higher then required version +function MajorMinorBuildRevisionEqualOrHigher { + param + ( + [Parameter(Mandatory)][string]$Item, + [Parameter(Mandatory)][string]$ActualVersion, + [Parameter(Mandatory)][string]$RequiredVersion, + [switch]$Silent + ) + + $retval = $false + + $Actual = [version]$ActualVersion + $Required = [version]$RequiredVersion + + if ($Actual -ge $Required) + { + $retval = $true + if(-not $Silent) + { + Write-Host "The actual version of the $Item ($ActualVersion) is equal or higher then required ($RequiredVersion)." -ForegroundColor Green + } + } + elseif(-not $Silent) + { + Write-Host "The actual version of the $Item ($ActualVersion) is lower then required ($RequiredVersion)." -ForegroundColor Red + } + return $retval +} +# Function to check if the major and minor version is equal and build and revision version is equal or higher +function MajorMinorEqualBuildRevisionEqualOrHigher { + param + ( + [Parameter(Mandatory)][string]$Item, + [Parameter(Mandatory)][string]$ActualVersion, + [Parameter(Mandatory)][string]$RequiredVersion, + [switch]$Silent + ) + + $retval = $false + + $Actual = [version]$ActualVersion + $Required = [version]$RequiredVersion + + if ($Actual.Major -eq $Required.Major -and $Actual.Minor -eq $Required.Minor -and $Actual.Build -ge $Required.Build -and $Actual.Revision -ge $Required.Revision ) + { + $retval = $true + if(-not $Silent) + { + Write-Host "The actual version of the $Item ($ActualVersion) fits the required one ($RequiredVersion)." -ForegroundColor Green + } + } + elseif(-not $Silent) + { + Write-Host "The actual version of the $Item ($ActualVersion) does not fit the required ($RequiredVersion)." -ForegroundColor Red + } + return $retval +} +# Function to check if the major minor and build version is equal and revision version is equal or higher +function MajorMinorBuildEqualRevisionEqualOrHigher { + param + ( + [Parameter(Mandatory)][string]$Item, + [Parameter(Mandatory)][string]$ActualVersion, + [Parameter(Mandatory)][string]$RequiredVersion, + [switch]$Silent + ) + + $retval = $false + + $Actual = [version]$ActualVersion + $Required = [version]$RequiredVersion + + if ($Actual.Major -eq $Required.Major -and $Actual.Minor -eq $Required.Minor -and $Actual.Build -eq $Required.Build -and $Actual.Revision -ge $Required.Revision ) + { + $retval = $true + if(-not $Silent) + { + Write-Host "The actual version of the $Item ($ActualVersion) fits the required one ($RequiredVersion)." -ForegroundColor Green + } + } + elseif(-not $Silent) + { + Write-Host "The actual version of the $Item ($ActualVersion) does not fit the required ($RequiredVersion)." -ForegroundColor Red + } + return $retval +} + +##################################################################################### +## DOT NET # +##################################################################################### +## Function to check if required version of dotnet is installed +#function VerifyDotNet { +# param +# ( +# [Parameter(Mandatory)][string]$RequiredVersion, +# [Parameter(Mandatory)][ValidateSet("SDK","Runtime")][string]$Type, +# [Parameter(Mandatory)][ValidateSet("x86","x64")][string]$Architecture +# ) +# +# $retval = $false +# +# # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) +# if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { +# Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red +# return $retval +# exit 1 +# } +# +# $dotnetExe = if ($Type -eq "SDK") +# { +# Join-Path $env:USERPROFILE ".dotnet\dotnet.exe" +# } +# elseif ($Architecture -eq "x86") +# { +# Join-Path ${env:ProgramFiles(x86)} "dotnet\dotnet.exe" +# } +# else +# { +# Join-Path $env:ProgramFiles "dotnet\dotnet.exe" +# } +# if (-not $dotnetExe) +# { +# # default per-user install path +# $dotnetExe = Join-Path $env:USERPROFILE ".dotnet\dotnet.exe" +# } +# +# if (-not (Test-Path -LiteralPath $dotnetExe)) +# { +# Write-Host "dotnet.exe not found at '$dotnetExe' (PATH may not be updated yet)." -ForegroundColor Red +# $retval = $false +# } +# if($Type -eq "Runtime") +# { +# $list = "--list-runtimes" +# $filter = '^Microsoft\.WindowsDesktop\.App\s+([\d\.]+)\s' +# } +# else +# { +# $list = "--list-sdks" +# $filter = '^([\d\.]+)\s' +# } +# $items = & $dotnetExe $list 2>$null +# # Extract versions like 8.0.1, 8.0.12, etc. +# $versions = foreach ($item in $items) +# { +# if ($item -match $filter) +# { +# [version]$matches[1] +# } +# } +# foreach ($version in $versions) { +# if (MajorMinorBuildEqualRevisionEqualOrHigher -Item ".NET" -ActualVersion $version -RequiredVersion $RequiredVersion -Silent) +# { +# $retval = $true +# break +# } +# } +# if ($retval) +# { +# Write-Host ".NET $Type $RequiredVersion $Architecture detected." -ForegroundColor Green +# } +# else +# { +# Write-Host ".NET $Type $RequiredVersion $Architecture is not installed." -ForegroundColor Red +# } +# return $retval +#} +# +## Function to download and install dotnet SDK +#function InstallDotNet { +# param +# ( +# [Parameter(Mandatory)][string]$RequiredVersion, +# [Parameter(Mandatory)][ValidateSet("SDK","Runtime")][string]$Type, +# [Parameter(Mandatory)][ValidateSet("x86","x64")][string]$Architecture +# ) +# +# $dotnetInstall = "dotnet-install.ps1" +# $installDir = if ($Type -eq "SDK") +# { +# Join-Path $env:USERPROFILE ".dotnet" +# } +# elseif ($Architecture -eq "x86") +# { +# Join-Path ${env:ProgramFiles(x86)} "dotnet" +# } +# else +# { +# Join-Path $env:ProgramFiles "dotnet" +# } +# if (-not $installDir) +# { +# # default per-user install path +# $installDir = Join-Path $env:USERPROFILE ".dotnet" +# } +# +# try { +# Write-Host "Downloading $dotnetInstall..." +# Write-Host "The installer will request to run as administrator. Expect a prompt." +# Invoke-WebRequest -Uri $dotNetInstallationScriptLocation -OutFile $dotnetInstall +# +# if (-not (Test-Path -LiteralPath $dotnetInstall)) { +# Write-Host "Failed to download $dotnetInstall." -ForegroundColor Red +# exit 1 +# } +# +# $scriptPath = Join-Path $PSScriptRoot $dotnetInstall +# Write-Host "Installing .NET SDK $RequiredVersion to $installDir" +# +# if($Type -eq "Runtime") +# { +# $arguments = @( +# "-NoProfile" +# "-ExecutionPolicy Bypass" +# "-File `"$scriptPath`"" +# "-Version `"$RequiredVersion`"" +# "-Runtime windowsdesktop" +# "-InstallDir `"$installDir`"" +# "-Architecture `"$Architecture`"" +# "-NoPath" # we'll set PATH ourselves in this session (reliable) +# ) +# } +# else +# { +# $arguments = @( +# "-NoProfile" +# "-ExecutionPolicy Bypass" +# "-File `"$scriptPath`"" +# "-Version `"$RequiredVersion`"" +# "-InstallDir `"$installDir`"" +# "-NoPath" # we'll set PATH ourselves in this session (reliable) +# ) +# } +# +# $proc = Start-Process powershell.exe -ArgumentList ($arguments -join ' ') -Wait -PassThru +# if ($proc.ExitCode -ne 0) { +# Write-Host "dotnet-install.ps1 failed with exit code $($proc.ExitCode)" -ForegroundColor Red +# exit 1 +# } +# +# # Make dotnet available in *this* PowerShell session: +# $env:DOTNET_ROOT = $installDir +# if ($env:PATH -notlike "*$installDir*") { +# $env:PATH = "$installDir;$env:PATH" +# } +# +# if (-not (VerifyDotNet -RequiredVersion $RequiredVersion -Type $Type -Architecture $Architecture)) +# { +# Write-Host "Error installing .NET $Type $RequiredVersion $Architecture (or .NET not visible in this session)." -ForegroundColor Red +# exit 1 +# } +# +# Write-Host ".NET $Type $RequiredVersion $Architecture installed successfully." -ForegroundColor Green +# } +# catch { +# Write-Host "Error installing .NET: $($_.Exception.Message)" -ForegroundColor Red +# exit 1 +# } +# finally { +# # cleanup silently +# Remove-Item -Path (Join-Path $PSScriptRoot $dotnetInstall) -Force -ErrorAction SilentlyContinue +# # Persist PATH for the current user (future shells) +# $dotnetDir = Join-Path $env:USERPROFILE ".dotnet" +# +# $existingUserPath = [Environment]::GetEnvironmentVariable("PATH", "User") +# +# if ($existingUserPath -notlike "*$dotnetDir*") { +# $newUserPath = "$dotnetDir;$existingUserPath" +# [Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User") +# } +# } +#} +# +## Check .NET SDK +#if (-not (VerifyDotNet -RequiredVersion $dotNetSDKRequiredVersion -Type SDK -Architecture x64)) +#{ +# $response = Read-Host ".NET $dotNetSDKRequiredVersion SDK is not installed. Would you like to install it now? (Y/N)" +# if ($response -eq 'Y' -or $response -eq 'y') { +# InstallDotNet -RequiredVersion $dotNetSDKRequiredVersion -Type SDK -Architecture x64 +# } +#} +## Check .NET desktop runtime x86 +#if (-not (VerifyDotNet -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Type Runtime -Architecture x86)) +#{ +# $response = Read-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime x86 is not installed. Would you like to install it now? (Y/N)" +# if ($response -eq 'Y' -or $response -eq 'y') { +# InstallDotNet -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Type Runtime -Architecture x86 +# } +#} +## Check .NET desktop runtime x64 +#if (-not (VerifyDotNet -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Type Runtime -Architecture x64)) +#{ +# $response = Read-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime x86 is not installed. Would you like to install it now? (Y/N)" +# if ($response -eq 'Y' -or $response -eq 'y') { +# InstallDotNet -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Type Runtime -Architecture x64 +# } +#} +#exit 0 +#################################################################################### +# WINGET # #################################################################################### -# Function to check if required version of dotnet is installed -function VerifyDotNet { +$winget = Get-Command winget -ErrorAction SilentlyContinue +if (-not $winget) { + Write-Host "winget is not available on this system." -ForegroundColor Red + exit 1 +} +#################################################################################### +# NODE.JS # +#################################################################################### +try +{ + $nodeVersion = (node -v).Trim() +} +catch +{ + Write-Host "Node.js is not installed or not found in PATH." -ForegroundColor Red + Write-Host "Installing Node.js LTS via winget..." + + $packageId = "OpenJS.NodeJS.LTS" + + winget install ` + --id $packageId ` + --exact ` + --silent ` + --accept-package-agreements ` + --accept-source-agreements + + $env:Path = "$env:ProgramFiles\nodejs;$env:Path" + + # Verify + $nodeVersion = (node -v).Trim() + if(-not $nodeVersion) + { + Write-Host "Error installing Node.js." -ForegroundColor Red + } + else + { + Write-Host "Node.js succefully installed." -ForegroundColor Green + } + npm -v + +} +#################################################################################### +# DOT NET SDK # +#################################################################################### +# Function to check if required version of dotnet SDK is installed +function VerifyDotNetSDK { param( - [Parameter(Mandatory)][string]$DotNetRequiredVersion, + [Parameter(Mandatory)][string]$RequiredVersion, [string]$DotNetExePath ) @@ -44,25 +437,25 @@ function VerifyDotNet { $dotnetSDKs = & $DotNetExePath --list-sdks 2>$null foreach ($sdk in $dotnetSDKs) { - if ($sdk -match "^$([regex]::Escape($DotNetRequiredVersion))\s") { + if ($sdk -match "^$([regex]::Escape($RequiredVersion))\s") { $dotnetInstalled = $true break } } if ($dotnetInstalled) { - Write-Host ".NET $dotNetRequiredVersion SDK detected." -ForegroundColor Green + Write-Host ".NET $RequiredVersion SDK detected." -ForegroundColor Green } else { - Write-Host ".NET $dotNetRequiredVersion SDK is not installed." -ForegroundColor Red + Write-Host ".NET $RequiredVersion SDK is not installed." -ForegroundColor Red } return $dotnetInstalled } -# Function to download and install dotnet -function InstallDotNet { - param([Parameter(Mandatory)][string]$DotNetRequiredVersion) +# Function to download and install dotnet SDK +function InstallDotNetSDK { + param([Parameter(Mandatory)][string]$RequiredVersion) $dotnetInstall = "dotnet-install.ps1" $installDir = Join-Path $env:USERPROFILE ".dotnet" @@ -70,6 +463,7 @@ function InstallDotNet { try { Write-Host "Downloading $dotnetInstall..." + Write-Host "The installer will request to run as administrator. Expect a prompt." Invoke-WebRequest -Uri $dotNetInstallationScriptLocation -OutFile $dotnetInstall if (-not (Test-Path -LiteralPath $dotnetInstall)) { @@ -78,13 +472,13 @@ function InstallDotNet { } $scriptPath = Join-Path $PSScriptRoot $dotnetInstall - Write-Host "Installing .NET SDK $DotNetRequiredVersion to $installDir" + Write-Host "Installing .NET SDK $RequiredVersion to $installDir" $arguments = @( "-NoProfile" "-ExecutionPolicy Bypass" "-File `"$scriptPath`"" - "-Version `"$DotNetRequiredVersion`"" + "-Version `"$RequiredVersion`"" "-InstallDir `"$installDir`"" "-NoPath" # we'll set PATH ourselves in this session (reliable) ) @@ -101,13 +495,13 @@ function InstallDotNet { $env:PATH = "$installDir;$env:PATH" } - $dotnetInstalled = VerifyDotNet -DotNetRequiredVersion $DotNetRequiredVersion -DotNetExePath $dotnetExe + $dotnetInstalled = VerifyDotNetSDK -RequiredVersion $RequiredVersion -DotNetExePath $dotnetExe if (-not $dotnetInstalled) { Write-Host "Error installing dotnet (or dotnet not visible in this session)." -ForegroundColor Red exit 1 } - Write-Host ".NET SDK $DotNetRequiredVersion installed successfully." -ForegroundColor Green + Write-Host ".NET SDK $RequiredVersion installed successfully." -ForegroundColor Green } catch { Write-Host "Error installing dotnet: $($_.Exception.Message)" -ForegroundColor Red @@ -128,92 +522,146 @@ function InstallDotNet { } } -$dotnetInstalled = VerifyDotNet -DotNetRequiredVersion $dotNetRequiredVersion - -# Check .NET SDKs -if (-not $dotnetInstalled) +# Check .NET SDK +if (-not (VerifyDotNetSDK -RequiredVersion $dotNetSDKRequiredVersion)) { - $response = Read-Host ".NET $dotNetRequiredVersion SDK is not installed. Would you like to install it now? (Y/N)" + $response = Read-Host ".NET $dotNetSDKRequiredVersion SDK is not installed. Would you like to install it now? (Y/N)" if ($response -eq 'Y' -or $response -eq 'y') { - InstallDotNet $dotNetRequiredVersion + InstallDotNetSDK -RequiredVersion $dotNetSDKRequiredVersion } } - #################################################################################### -# AX CODE # +# DOT NET DESKTOP RUNTIME # #################################################################################### -# Function to check if the actual version is equal to required version -function MajorMinorBuildRevisionEqual { +# Function to check if required version of dotnet desktop runtime is installed +function VerifyDotNetDesktopRuntime { param( - [Parameter(Mandatory)][string]$Package, - [Parameter(Mandatory)][string]$ActualVersion, - [Parameter(Mandatory)][string]$RequiredVersion + [Parameter(Mandatory)][string]$RequiredVersion, + [Parameter(Mandatory)][ValidateSet("x86","x64")][string]$Architecture ) - $retval = $false - - $Actual = [version]$ActualVersion - $Required = [version]$RequiredVersion - - if ($Actual -eq $Required) + # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) + if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { + Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red + return $retval + exit 1 + } + + $dotnetExe = if ($Architecture -eq "x86") { - Write-Host "The actual version of the $Package ($ActualVersion) is equal to required ($RequiredVersion)." -ForegroundColor Green - $retval = $true + Join-Path ${env:ProgramFiles(x86)} "dotnet\dotnet.exe" } else - { - Write-Host "The actual version of the $Package ($ActualVersion) is different to required ($RequiredVersion)." -ForegroundColor Red - } - return $retval -} -# Function to check if the actual version is equal or higher then required version -function MajorMinorBuildRevisionEqualOrHigher { - param( - [Parameter(Mandatory)][string]$Package, - [Parameter(Mandatory)][string]$ActualVersion, - [Parameter(Mandatory)][string]$RequiredVersion - ) + { - $retval = $false + Join-Path $env:ProgramFiles "dotnet\dotnet.exe" + } + if (-not $dotnetExe) { + # default per-user install path + $dotnetExe = Join-Path $env:USERPROFILE ".dotnet\dotnet.exe" + } - $Actual = [version]$ActualVersion - $Required = [version]$RequiredVersion + if (-not (Test-Path -LiteralPath $dotnetExe)) + { + Write-Host "dotnet.exe not found at '$dotnetExe' (PATH may not be updated yet)." -ForegroundColor Red + $retval = $false + } + $runtimes = & $dotnetExe --list-runtimes 2>$null - if ($Actual -ge $Required) + # Extract versions like 8.0.1, 8.0.12, etc. + $versions = foreach ($line in $runtimes) { - Write-Host "The actual version of the $Package ($ActualVersion) is equal or higher then required ($RequiredVersion)." -ForegroundColor Green - $retval = $true + if ($line -match '^Microsoft\.WindowsDesktop\.App\s+([\d\.]+)\s') + { + [version]$matches[1] + } + } + foreach ($version in $versions) { + if ($version -eq $RequiredVersion) + { + $retval = $true + break + } + } + + + if ($retval) + { + Write-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime $Architecture detected." -ForegroundColor Green } else { - Write-Host "The actual version of the $Package ($ActualVersion) is lower then required ($RequiredVersion)." -ForegroundColor Red + Write-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime $Architecture is not installed." -ForegroundColor Red } return $retval } -# Function to check if the major and minor version equal or and build and revision version is equal or higher -function MajorMinorEqualBuildRevisionEqualOrHigher { + +# Function to download and install dotnet desktop runtime +function InstallDotNetDesktopRuntime { param( - [Parameter(Mandatory)][string]$Package, - [Parameter(Mandatory)][string]$ActualVersion, - [Parameter(Mandatory)][string]$RequiredVersion + [Parameter(Mandatory)][string]$RequiredVersion, + [Parameter(Mandatory)][ValidateSet("x86","x64")][string]$Architecture ) - $retval = $false + # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) + if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { + Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red + return $retval + exit 1 + } - $Actual = [version]$ActualVersion - $Required = [version]$RequiredVersion + $channel = ($RequiredVersion -split '\.')[0..1] -join '.' + + $url = "https://aka.ms/dotnet/$channel/windowsdesktop-runtime-win-$Architecture.exe" + $installer = Join-Path $env:TEMP "dotnet-desktop-runtime-$channel-$Architecture.exe" - if ($Actual.Major -eq $Required.Major -and $Actual.Minor -eq $Required.Minor -and $Actual.Build -ge $Required.Build -and $Actual.Revision -ge $Required.Revision ) + Write-Host "Downloading .NET Desktop Runtime $channel ($Architecture)..." + Write-Host "The installer will request to run as administrator. Expect a prompt." + Invoke-WebRequest -Uri $url -OutFile $installer -UseBasicParsing + + Write-Host "Installing .NET Desktop Runtime $channel ($Architecture)..." + $proc = Start-Process -FilePath $installer -ArgumentList "/install /quiet /norestart" -Verb RunAs -Wait -PassThru + + if ($proc.ExitCode -ne 0) { - Write-Host "The actual version of the $Package ($ActualVersion) does fit the required ($RequiredVersion)." -ForegroundColor Green - $retval = $true - } - else + Write-Host ".NET Desktop Runtime $channel ($Architecture) installation failed with exit code $($proc.ExitCode)." -ForegroundColor Red + return $retval + exit 1 + } + + # Verify post-install + if (-not (VerifyDotNetDesktopRuntime -RequiredVersion $RequiredVersion -Architecture $Architecture)) + { + Write-Host "Installation completed but verification failed for .NET Desktop Runtime $RequiredVersion ($Architecture)." -ForegroundColor Red + return $retval + exit 1 + } + + Write-Host ".NET Desktop Runtime $RequiredVersion ($Architecture) installed successfully." -ForegroundColor Green +} + +# Check .NET desktop runtime x86 +if (-not (VerifyDotNetDesktopRuntime -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Architecture x86)) +{ + $response = Read-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime x86 is not installed. Would you like to install it now? (Y/N)" + if ($response -eq 'Y' -or $response -eq 'y') { - Write-Host "The actual version of the $Package ($ActualVersion) does not fit the required ($RequiredVersion)." -ForegroundColor Red - } - return $retval + InstallDotNetDesktopRuntime -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Architecture x86 + } } +# Check .NET desktop runtime x64 +if (-not (VerifyDotNetDesktopRuntime -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Architecture x64)) +{ + $response = Read-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime x64 is not installed. Would you like to install it now? (Y/N)" + if ($response -eq 'Y' -or $response -eq 'y') + { + InstallDotNetDesktopRuntime -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Architecture x64 + } +} + +#################################################################################### +# AX CODE # +#################################################################################### # Define the command to get the version $command = "axcode --version" @@ -223,7 +671,7 @@ try $version = Invoke-Expression $command $ActualVersion = $version.Item(0) # Compare the retrieved version with the expected version - if (-not (MajorMinorBuildRevisionEqualOrHigher -Package "AX Code" -ActualVersion $ActualVersion -RequiredVersion $axCodeRequiredVersion)) + if (-not (MajorMinorBuildRevisionEqualOrHigher -Item "AX Code" -ActualVersion $ActualVersion -RequiredVersion $axCodeRequiredVersion)) { Write-Host "The AXCode version does not match the expected version: $axCodeRequiredVersion. It's highly recommended to update it." -ForegroundColor Red } @@ -231,6 +679,17 @@ try catch { Write-Host "Error: Unable to determine the AXCode version. Ensure AXCode is correctly installed and accessible from the command line." -ForegroundColor Red + $axCodeGuide = @" + 1. Ensure that you have a valid SIMATIC AX license. + 2. Verify that you have access to $axCodeDownloadUrl. + 3. Download AX Code for Windows from $axCodeDownloadUrl. + 4. Install AX Code for Windows. + 5. Restart your computer. + 6. Run this script again. +"@ + Write-Host "To install the AXCode:" -ForegroundColor Yellow + Write-Host $axCodeGuide -ForegroundColor Yellow + exit 1 } @@ -242,14 +701,13 @@ try { $apaxVersion = (apax --version).Trim() # Compare the retrieved version with the expected version - if ((MajorMinorBuildRevisionEqualOrHigher -Package "APAX" -ActualVersion $apaxVersion -RequiredVersion $apaxRequiredVersion)) + if ((MajorMinorBuildRevisionEqualOrHigher -Item "APAX" -ActualVersion $apaxVersion -RequiredVersion $apaxRequiredVersion)) { $isApaxInstalled = $true } else { Write-Host "The APAX version does not match the expected version: $apaxRequiredVersion. It's highly recommended to update it." -ForegroundColor Red - Write-Host "The APAX version does not match the expected version: $apaxRequiredVersion. It's highly recommended to update it." -ForegroundColor Red } } catch @@ -268,7 +726,8 @@ catch $winget = Get-Command winget -ErrorAction SilentlyContinue if (-not $winget) { - throw "winget is not available on this system." + Write-Host "winget is not available on this system." -ForegroundColor Red + exit 1 } winget install ` @@ -292,11 +751,12 @@ catch if (-not $isApaxInstalled) { $apaxGuide = @" To download Apax: -1. Visit https://console.simatic-ax.siemens.io/downloads in your browser. -2. Log in with your credentials. -3. Follow the on-site instructions to download and install Apax. + 1. Visit https://console.simatic-ax.siemens.io/downloads in your browser. + 2. Log in with your credentials. + 3. Follow the on-site instructions to download and install Apax. "@ - Write-Host "Apax is not installed or not found in PATH. You need to have a valid SIMATIC-AX license." $apaxGuide -ForegroundColor Yellow + Write-Host "Apax is not installed or not found in PATH. You need to have a valid SIMATIC-AX license." -ForegroundColor Yellow + Write-Host $apaxGuide -ForegroundColor Yellow } @@ -404,8 +864,6 @@ $headers = @{ "Accept" = "application/vnd.github.package-preview+json" } - - # Check if the feed is added $isFeedAlreadyAdded = $false; try @@ -532,46 +990,87 @@ if (-not $vsVersion) { PromptAndDownload "Visual Studio is not detected." "https://visualstudio.microsoft.com/vs/" } -# Function to download VS Build Tools -function Download-VSBuildTools +#################################################################################### +# VISUAL STUDIO BUILD TOOLS # +#################################################################################### +# Check if VS Build Tools is installed +function Verify-VSBuildTools { - $output = "vs_buildtools.exe" - - Write-Host "Downloading Visual Studio Build Tools..." - Invoke-WebRequest -Uri $vsBuildToolInstallerDownloadLocation -OutFile $output - - if (Test-Path $output) - { - Write-Host "Visual Studio Build Tools downloaded successfully." - } - else - { - Write-Host "Failed to download Visual Studio Build Tools." + param( + [Parameter(Mandatory)][string]$RequiredVersion + ) + $retval = $false + # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) + if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { + Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red + return $retval + exit 1 + } + $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + + if (-not (Test-Path $vswhere)) { + Write-Host "vswhere.exe not found. Visual Studio Installer is missing." -ForegroundColor Red + return $retval exit 1 } -} + Write-Host "Checking for Visual Studio Build Tools..." + + $vsBuildToolsPath = & $vswhere -products Microsoft.VisualStudio.Product.BuildTools -property installationPath + + if ($vsBuildToolsPath) + { + Write-Host "Visual Studio Build Tools already installed at: $vsBuildToolsPath" + $vsBuildToolsVersion = & $vswhere -products Microsoft.VisualStudio.Product.BuildTools -property installationVersion + $retval = MajorMinorEqualBuildRevisionEqualOrHigher -Package "Visual Studio Build Tools" -ActualVersion $vsBuildToolsVersion -RequiredVersion $RequiredVersion + } + return $retval +} -#################################################################################### -# VISUAL STUDIO BUILD TOOLS # -#################################################################################### # Function to install VS Build Tools function Install-VSBuildTools { - Write-Host "Installing Visual Studio Build Tools..." - - .\vs_buildtools.exe --wait --norestart --nocache --passive $vsBuildToolRequiredComponents - Write-Host "Visual Studio Build Tools installation completed." + Write-Host "VS Build Tools not found. Installing..." + + $outFile = [System.IO.Path]::GetFileName($vsBuildToolInstallationURL) + + try + { + Invoke-WebRequest -Uri $vsBuildToolInstallationURL -OutFile $outFile -UseBasicParsing + Invoke-Expression $vsBuildToolInstallCommand + Write-Host "VS Build Tools installation completed successfully." -ForegroundColor Green + } + catch + { + Write-Host "VS Build Tools installationfinished with an error." -ForegroundColor Red + } +} + +# Check if VSBuildTools is installed +if (-not (Verify-VSBuildTools -RequiredVersion $vsBuildToolRequiredVersion)) +{ + $response = Read-Host "VSBuildTools $vsBuildToolRequiredVersion is not installed. Would you like to install it now? (Y/N)" + if ($response -eq 'Y' -or $response -eq 'y') + { + Install-VSBuildTools -RequiredVersion $dotNetDesktopRuntimeRequiredVersion + } } +exit 0 + # Check if the environment variable exists -$vctoolsDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::Machine) +$vctoolsDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::User) if ($vctoolsDir -and (Test-Path $vctoolsDir)) { # If the environment variable exists and the path is valid Write-Host "VCToolsInstallDir is set and the path exists: $vctoolsDir" -foregroundcolor green } +elseif ($vctoolsDir -and -not (Test-Path $vctoolsDir)) +{ + # If the environment variable exists but the path is invalid + Write-Host "VCToolsInstallDir is set but the path does not exist: $vctoolsDir" -foregroundcolor red +} else { # If the environment variable doesn't exist or the path is invalid @@ -589,7 +1088,7 @@ else try { # Set the environment variable after installation - [System.Environment]::SetEnvironmentVariable("VCToolsInstallDir", $expectedVCToolsInstallDir, [System.EnvironmentVariableTarget]::Machine) + [System.Environment]::SetEnvironmentVariable("VCToolsInstallDir", $expectedVCToolsInstallDir, [System.EnvironmentVariableTarget]::User) } catch { @@ -597,7 +1096,7 @@ else Write-Host "VCToolsInstallDir = $expectedVCToolsInstallDir" -foregroundcolor red } # Verify that the environment variable and path are now correct - $finalVCToolsInstallDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::Machine) + $finalVCToolsInstallDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::User) if ($finalVCToolsInstallDir -eq $expectedVCToolsInstallDir -and (Test-Path $finalVCToolsInstallDir)) { From 0f656bde63da61700a89fa58d8ae8b8044ba7db0 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Thu, 15 Jan 2026 12:32:05 +0100 Subject: [PATCH 12/13] requisities --- scripts/check_requisites.ps1 | 832 ++++++++++++++++++----------------- 1 file changed, 430 insertions(+), 402 deletions(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index be631d0ee..5d97ac426 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -1,13 +1,27 @@ ## Check pre-requisites # Definition of the requisities and locations #################################################################################### +# NODE # +#################################################################################### +$nodeRequiredVersion = "23.7.0" +#################################################################################### +# MICROSOFT VISUAL C++ REDISTRIBUTABLE # +#################################################################################### +$VCpRequiredVersion = "14.38.33135.0" +$VcpRegPath = 'HKLM:\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64' +$VcpUrl = 'https://aka.ms/vs/17/release/vc_redist.x64.exe' +#################################################################################### +# GIT # +#################################################################################### +$gitRequiredVersion = "2.44.0" +#################################################################################### # DOT NET # #################################################################################### $dotNetInstallationScriptLocation = "https://dot.net/v1/dotnet-install.ps1" $dotNetSDKRequiredVersion = "10.0.100" $dotNetDesktopRuntimeRequiredVersion = "8.0.22" #################################################################################### -# AX CODE # +# AX CODE # #################################################################################### $axCodeRequiredVersion = "1.94.2" $axCodeDownloadUrl = "https://console.simatic-ax.siemens.io/downloads" @@ -22,23 +36,19 @@ $apaxUrl = "https://console.simatic-ax.siemens.io/" $inxtonRegistryUrl = "https://npm.pkg.github.com/" $nugetFeedUrl = "https://nuget.pkg.github.com/inxton/index.json" #################################################################################### -# VISUAL STUDIO # -#################################################################################### -$visualStudioRequiredVersionRange = "[17.8.0,19.0)"; -$vsWhereLocation = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -#################################################################################### # VISUAL STUDIO BUILD TOOLS # #################################################################################### $vsBuildToolInstallationURL = "https://aka.ms/vs/16/release/vs_buildtools.exe" $vsBuildToolInstallCommand = ".\vs_buildtools.exe --wait --norestart --nocache --passive --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.Windows10SDK.19041" $vsBuildToolRequiredVersion = "16.11.36631.11" - $expectedVCToolsInstallDir = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133" -$vsBuildToolInstallerDownloadLocation = "https://aka.ms/vs/16/release/vs_buildtools.exe" -$vsBuildToolRequiredComponents = "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK --add Microsoft.VisualStudio.Component.Windows10SDK.18362" - +#################################################################################### +# VISUAL STUDIO # +#################################################################################### +$visualStudioRequiredVersionRange = "[17.8.0,19.0)"; +$vsWhereLocation = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" ######################################################################################################################################################################## -# VERSION CHECKERS # +# VERSION CHECKERS/HELPERS # #################################################################################### # Function to check if the actual version is equal to required version function MajorMinorBuildRevisionEqual { @@ -157,236 +167,64 @@ function MajorMinorBuildEqualRevisionEqualOrHigher { } return $retval } - -##################################################################################### -## DOT NET # -##################################################################################### -## Function to check if required version of dotnet is installed -#function VerifyDotNet { -# param -# ( -# [Parameter(Mandatory)][string]$RequiredVersion, -# [Parameter(Mandatory)][ValidateSet("SDK","Runtime")][string]$Type, -# [Parameter(Mandatory)][ValidateSet("x86","x64")][string]$Architecture -# ) -# -# $retval = $false -# -# # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) -# if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { -# Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red -# return $retval -# exit 1 -# } -# -# $dotnetExe = if ($Type -eq "SDK") -# { -# Join-Path $env:USERPROFILE ".dotnet\dotnet.exe" -# } -# elseif ($Architecture -eq "x86") -# { -# Join-Path ${env:ProgramFiles(x86)} "dotnet\dotnet.exe" -# } -# else -# { -# Join-Path $env:ProgramFiles "dotnet\dotnet.exe" -# } -# if (-not $dotnetExe) -# { -# # default per-user install path -# $dotnetExe = Join-Path $env:USERPROFILE ".dotnet\dotnet.exe" -# } -# -# if (-not (Test-Path -LiteralPath $dotnetExe)) -# { -# Write-Host "dotnet.exe not found at '$dotnetExe' (PATH may not be updated yet)." -ForegroundColor Red -# $retval = $false -# } -# if($Type -eq "Runtime") -# { -# $list = "--list-runtimes" -# $filter = '^Microsoft\.WindowsDesktop\.App\s+([\d\.]+)\s' -# } -# else -# { -# $list = "--list-sdks" -# $filter = '^([\d\.]+)\s' -# } -# $items = & $dotnetExe $list 2>$null -# # Extract versions like 8.0.1, 8.0.12, etc. -# $versions = foreach ($item in $items) -# { -# if ($item -match $filter) -# { -# [version]$matches[1] -# } -# } -# foreach ($version in $versions) { -# if (MajorMinorBuildEqualRevisionEqualOrHigher -Item ".NET" -ActualVersion $version -RequiredVersion $RequiredVersion -Silent) -# { -# $retval = $true -# break -# } -# } -# if ($retval) -# { -# Write-Host ".NET $Type $RequiredVersion $Architecture detected." -ForegroundColor Green -# } -# else -# { -# Write-Host ".NET $Type $RequiredVersion $Architecture is not installed." -ForegroundColor Red -# } -# return $retval -#} -# -## Function to download and install dotnet SDK -#function InstallDotNet { -# param -# ( -# [Parameter(Mandatory)][string]$RequiredVersion, -# [Parameter(Mandatory)][ValidateSet("SDK","Runtime")][string]$Type, -# [Parameter(Mandatory)][ValidateSet("x86","x64")][string]$Architecture -# ) -# -# $dotnetInstall = "dotnet-install.ps1" -# $installDir = if ($Type -eq "SDK") -# { -# Join-Path $env:USERPROFILE ".dotnet" -# } -# elseif ($Architecture -eq "x86") -# { -# Join-Path ${env:ProgramFiles(x86)} "dotnet" -# } -# else -# { -# Join-Path $env:ProgramFiles "dotnet" -# } -# if (-not $installDir) -# { -# # default per-user install path -# $installDir = Join-Path $env:USERPROFILE ".dotnet" -# } -# -# try { -# Write-Host "Downloading $dotnetInstall..." -# Write-Host "The installer will request to run as administrator. Expect a prompt." -# Invoke-WebRequest -Uri $dotNetInstallationScriptLocation -OutFile $dotnetInstall -# -# if (-not (Test-Path -LiteralPath $dotnetInstall)) { -# Write-Host "Failed to download $dotnetInstall." -ForegroundColor Red -# exit 1 -# } -# -# $scriptPath = Join-Path $PSScriptRoot $dotnetInstall -# Write-Host "Installing .NET SDK $RequiredVersion to $installDir" -# -# if($Type -eq "Runtime") -# { -# $arguments = @( -# "-NoProfile" -# "-ExecutionPolicy Bypass" -# "-File `"$scriptPath`"" -# "-Version `"$RequiredVersion`"" -# "-Runtime windowsdesktop" -# "-InstallDir `"$installDir`"" -# "-Architecture `"$Architecture`"" -# "-NoPath" # we'll set PATH ourselves in this session (reliable) -# ) -# } -# else -# { -# $arguments = @( -# "-NoProfile" -# "-ExecutionPolicy Bypass" -# "-File `"$scriptPath`"" -# "-Version `"$RequiredVersion`"" -# "-InstallDir `"$installDir`"" -# "-NoPath" # we'll set PATH ourselves in this session (reliable) -# ) -# } -# -# $proc = Start-Process powershell.exe -ArgumentList ($arguments -join ' ') -Wait -PassThru -# if ($proc.ExitCode -ne 0) { -# Write-Host "dotnet-install.ps1 failed with exit code $($proc.ExitCode)" -ForegroundColor Red -# exit 1 -# } -# -# # Make dotnet available in *this* PowerShell session: -# $env:DOTNET_ROOT = $installDir -# if ($env:PATH -notlike "*$installDir*") { -# $env:PATH = "$installDir;$env:PATH" -# } -# -# if (-not (VerifyDotNet -RequiredVersion $RequiredVersion -Type $Type -Architecture $Architecture)) -# { -# Write-Host "Error installing .NET $Type $RequiredVersion $Architecture (or .NET not visible in this session)." -ForegroundColor Red -# exit 1 -# } -# -# Write-Host ".NET $Type $RequiredVersion $Architecture installed successfully." -ForegroundColor Green -# } -# catch { -# Write-Host "Error installing .NET: $($_.Exception.Message)" -ForegroundColor Red -# exit 1 -# } -# finally { -# # cleanup silently -# Remove-Item -Path (Join-Path $PSScriptRoot $dotnetInstall) -Force -ErrorAction SilentlyContinue -# # Persist PATH for the current user (future shells) -# $dotnetDir = Join-Path $env:USERPROFILE ".dotnet" -# -# $existingUserPath = [Environment]::GetEnvironmentVariable("PATH", "User") -# -# if ($existingUserPath -notlike "*$dotnetDir*") { -# $newUserPath = "$dotnetDir;$existingUserPath" -# [Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User") -# } -# } -#} -# -## Check .NET SDK -#if (-not (VerifyDotNet -RequiredVersion $dotNetSDKRequiredVersion -Type SDK -Architecture x64)) -#{ -# $response = Read-Host ".NET $dotNetSDKRequiredVersion SDK is not installed. Would you like to install it now? (Y/N)" -# if ($response -eq 'Y' -or $response -eq 'y') { -# InstallDotNet -RequiredVersion $dotNetSDKRequiredVersion -Type SDK -Architecture x64 -# } -#} -## Check .NET desktop runtime x86 -#if (-not (VerifyDotNet -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Type Runtime -Architecture x86)) -#{ -# $response = Read-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime x86 is not installed. Would you like to install it now? (Y/N)" -# if ($response -eq 'Y' -or $response -eq 'y') { -# InstallDotNet -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Type Runtime -Architecture x86 -# } -#} -## Check .NET desktop runtime x64 -#if (-not (VerifyDotNet -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Type Runtime -Architecture x64)) -#{ -# $response = Read-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime x86 is not installed. Would you like to install it now? (Y/N)" -# if ($response -eq 'Y' -or $response -eq 'y') { -# InstallDotNet -RequiredVersion $dotNetDesktopRuntimeRequiredVersion -Type Runtime -Architecture x64 -# } -#} -#exit 0 +function Refresh-Path { + $machine = [Environment]::GetEnvironmentVariable("Path", "Machine") + $user = [Environment]::GetEnvironmentVariable("Path", "User") + $env:Path = "$machine;$user" +} +Refresh-Path #################################################################################### # WINGET # #################################################################################### $winget = Get-Command winget -ErrorAction SilentlyContinue if (-not $winget) { Write-Host "winget is not available on this system." -ForegroundColor Red + $wingetGuide = @" + To install winget: + 1. Proceed to: https://learn.microsoft.com/en-us/windows/package-manager/winget/. + 2. Follow the on-site instructions to download and install winget. +"@ + Write-Host $wingetGuide -ForegroundColor Yellow exit 1 } #################################################################################### # NODE.JS # #################################################################################### -try -{ - $nodeVersion = (node -v).Trim() +# Function to check if required version of Node.js is installed +function VerifyNode { + param + ( + [Parameter(Mandatory)][string]$RequiredVersion + ) + + $retval = $false + # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) + if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { + Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red + return $retval + exit 1 + } + + try + { + $nodeVersion = (node -v).TrimStart('v') + if(MajorMinorBuildRevisionEqualOrHigher -Item "Node.js" -ActualVersion $nodeVersion -RequiredVersion $RequiredVersion) + { + $retval = $true + } + } + catch + { + Write-Host "Node.js is not installed or not found in PATH." -ForegroundColor Red + $retval = $false + return $retval + } + return $retval } -catch -{ - Write-Host "Node.js is not installed or not found in PATH." -ForegroundColor Red + +# Function to download and install Node.js +function InstallNode{ + param([Parameter(Mandatory)][string]$RequiredVersion) Write-Host "Installing Node.js LTS via winget..." $packageId = "OpenJS.NodeJS.LTS" @@ -405,44 +243,213 @@ catch if(-not $nodeVersion) { Write-Host "Error installing Node.js." -ForegroundColor Red + exit 1 } else { Write-Host "Node.js succefully installed." -ForegroundColor Green } - npm -v + node -v +} +# Check Node +if (-not (VerifyNode -RequiredVersion $nodeRequiredVersion)) +{ + $response = Read-Host "Node.js $nodeRequiredVersion is not installed. Would you like to install it now? (Y/N)" + if ($response -eq 'Y' -or $response -eq 'y') { + InstallNode -RequiredVersion $nodeRequiredVersion + } +} +#################################################################################### +# MICROSOFT VISUAL C++ REDISTRIBUTABLE # +#################################################################################### +# Function to check if required version of Microsoft Visual C++ Redistributable is installed +function VerifyVcp { + param + ( + [Parameter(Mandatory)][string]$RequiredVersion + ) + + $retval = $false + # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) + if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { + Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red + return $retval + exit 1 + } + + $vc = Get-ItemProperty $VcpRegPath -ErrorAction SilentlyContinue + $actualVersion = $vc.Version.TrimStart('v') + + if ($vc -and $vc.Installed -eq 1 -and (MajorMinorBuildRevisionEqualOrHigher -Item "VC++ Redistributable" -ActualVersion $actualVersion -RequiredVersion $RequiredVersion)) + { + $retval = $true + } + + if ($retval) + { + Write-Host "VC++ Redistributable $RequiredVersion detected." -ForegroundColor Green + } + else + { + Write-Host "VC++ Redistributable $RequiredVersion is not installed." -ForegroundColor Red + } + return $retval +} + +# Function to download and install Microsoft Visual C++ Redistributable +function InstallVcp{ + param([Parameter(Mandatory)][string]$RequiredVersion) + + $installer = "$env:TEMP\vc_redist.x64.exe" + + Write-Host "Downloading VC++ Redistributable..." + Invoke-WebRequest $VcpUrl -OutFile $installer + + Write-Host "Installing VC++ Redistributable..." + Start-Process $installer -ArgumentList '/install /quiet /norestart' -Wait + + Start-Sleep -Seconds 5 + + if (-not (VerifyVcp -RequiredVersion $RequiredVersion)) { + Write-Host "Error installing VC++ Redistributable ." -ForegroundColor Red + exit 1 + } + Write-Host "VC++ Redistributable $RequiredVersion installed successfully." -ForegroundColor Green +} + +# Check VerifyVcp Visual C++ Redistributable +if (-not (VerifyVcp -RequiredVersion $VCpRequiredVersion)) +{ + $response = Read-Host "Microsoft Visual C++ Redistributable $VCpRequiredVersion is not installed. Would you like to install it now? (Y/N)" + if ($response -eq 'Y' -or $response -eq 'y') { + InstallVcp -RequiredVersion $VCpRequiredVersion + } +} +#################################################################################### +# GIT # +#################################################################################### +# Function to check if required version of Git is installed +function VerifyGit { + param + ( + [Parameter(Mandatory)][string]$RequiredVersion + ) + + $retval = $false + # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) + if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { + Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red + return $retval + exit 1 + } + + try + { + $actualVersion = git --version | Select-String -Pattern '([0-9]+\.[0-9]+\.[0-9]+)' | ForEach-Object { $_.Matches[0].Value } + if(MajorMinorBuildRevisionEqualOrHigher -Item "Git" -ActualVersion $actualVersion -RequiredVersion $RequiredVersion) + { + $retval = $true + } + } + catch + { + Write-Host "Git is not installed." -ForegroundColor Red + $retval = $false + return $retval + } + return $retval +} + +# Function to download and install Git +function InstallGit{ + param([Parameter(Mandatory)][string]$RequiredVersion) + Write-Host "Installing Git via winget..." + + $packageId = "Git.Git" + + winget install ` + --id $packageId ` + --exact ` + --silent ` + --accept-package-agreements ` + --accept-source-agreements + + + Start-Sleep -Seconds 10 + + Refresh-Path + + if (-not (VerifyGit -RequiredVersion $RequiredVersion)) { + Write-Host "Error installing Git." -ForegroundColor Red + exit 1 + } + Write-Host "Git $RequiredVersion installed successfully." -ForegroundColor Green + + +} + +# Check Git +if (-not (VerifyGit -RequiredVersion $gitRequiredVersion)) +{ + $response = Read-Host "Git $gitRequiredVersion is not installed. Would you like to install it now? (Y/N)" + if ($response -eq 'Y' -or $response -eq 'y') { + InstallGit -RequiredVersion $gitRequiredVersion + } } #################################################################################### # DOT NET SDK # #################################################################################### # Function to check if required version of dotnet SDK is installed function VerifyDotNetSDK { - param( - [Parameter(Mandatory)][string]$RequiredVersion, - [string]$DotNetExePath + param + ( + [Parameter(Mandatory)][string]$RequiredVersion ) - $dotnetInstalled = $false + $retval = $false + # Allow Major.Minor, Major.Minor.Patch, or extended build versions (e.g. 16.11.36631.11) + if ($RequiredVersion -notmatch '^\d+\.\d+(\.\d+){0,2}$') { + Write-Host "RequiredVersion must be 'Major.Minor' (e.g. 8.0), 'Major.Minor.Patch' (e.g. 8.0.2), or extended (e.g. 16.11.36631.11)." -ForegroundColor Red + return $retval + exit 1 + } - if (-not $DotNetExePath) { - # default per-user install path - $DotNetExePath = Join-Path $env:USERPROFILE ".dotnet\dotnet.exe" + $dotnetDir = Join-Path $env:ProgramFiles "dotnet" + $dotnetExe = Join-Path $dotnetDir "dotnet.exe" + + if (-not (Test-Path -LiteralPath $dotnetDir)) + { + Write-Host "Directory $dotnetDir not found." -ForegroundColor Red + $retval = $false + return $retval + exit 0 } - if (-not (Test-Path -LiteralPath $DotNetExePath)) { - Write-Host "dotnet.exe not found at '$DotNetExePath' (PATH may not be updated yet)." -ForegroundColor Red - $dotnetInstalled = $false + if (-not (Test-Path -LiteralPath $dotnetExe)) + { + Write-Host "dotnet.exe not found at '$dotnetExe' (PATH may not be updated yet)." -ForegroundColor Red + $retval = $false + return $retval + exit 0 } - $dotnetSDKs = & $DotNetExePath --list-sdks 2>$null - foreach ($sdk in $dotnetSDKs) { + $existingUserPath = [Environment]::GetEnvironmentVariable("PATH", "User") + if ($existingUserPath -notlike "*$dotnetDir*") + { + $newUserPath = "$dotnetDir;$existingUserPath" + [Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User") + Refresh-Path + } + $dotnetSDKs = & dotnet --list-sdks 2>$null + foreach ($sdk in $dotnetSDKs) + { if ($sdk -match "^$([regex]::Escape($RequiredVersion))\s") { - $dotnetInstalled = $true + $retval = $true break } } - if ($dotnetInstalled) + if ($retval) { Write-Host ".NET $RequiredVersion SDK detected." -ForegroundColor Green } @@ -450,7 +457,7 @@ function VerifyDotNetSDK { { Write-Host ".NET $RequiredVersion SDK is not installed." -ForegroundColor Red } - return $dotnetInstalled + return $retval } # Function to download and install dotnet SDK @@ -458,12 +465,11 @@ function InstallDotNetSDK { param([Parameter(Mandatory)][string]$RequiredVersion) $dotnetInstall = "dotnet-install.ps1" - $installDir = Join-Path $env:USERPROFILE ".dotnet" - $dotnetExe = Join-Path $installDir "dotnet.exe" + $installDir = Join-Path $env:ProgramFiles "dotnet" try { Write-Host "Downloading $dotnetInstall..." - Write-Host "The installer will request to run as administrator. Expect a prompt." + Write-Host " The installer will request to run as administrator. Expect a prompt." -ForegroundColor Yellow Invoke-WebRequest -Uri $dotNetInstallationScriptLocation -OutFile $dotnetInstall if (-not (Test-Path -LiteralPath $dotnetInstall)) { @@ -483,24 +489,29 @@ function InstallDotNetSDK { "-NoPath" # we'll set PATH ourselves in this session (reliable) ) - $proc = Start-Process powershell.exe -ArgumentList ($arguments -join ' ') -Wait -PassThru + $proc = Start-Process powershell.exe -ArgumentList ($arguments -join ' ') -Verb RunAs -Wait -PassThru if ($proc.ExitCode -ne 0) { Write-Host "dotnet-install.ps1 failed with exit code $($proc.ExitCode)" -ForegroundColor Red exit 1 } - # Make dotnet available in *this* PowerShell session: $env:DOTNET_ROOT = $installDir - if ($env:PATH -notlike "*$installDir*") { + if ($env:PATH -notlike "*$installDir*") + { $env:PATH = "$installDir;$env:PATH" } - - $dotnetInstalled = VerifyDotNetSDK -RequiredVersion $RequiredVersion -DotNetExePath $dotnetExe + # Persist PATH for the current user (future shells) + $existingUserPath = [Environment]::GetEnvironmentVariable("PATH", "User") + if ($existingUserPath -notlike "*$installDir*") + { + $newUserPath = "$installDir;$existingUserPath" + [Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User") + } + $dotnetInstalled = VerifyDotNetSDK -RequiredVersion $RequiredVersion if (-not $dotnetInstalled) { Write-Host "Error installing dotnet (or dotnet not visible in this session)." -ForegroundColor Red exit 1 } - Write-Host ".NET SDK $RequiredVersion installed successfully." -ForegroundColor Green } catch { @@ -510,15 +521,6 @@ function InstallDotNetSDK { finally { # cleanup silently Remove-Item -Path (Join-Path $PSScriptRoot $dotnetInstall) -Force -ErrorAction SilentlyContinue - # Persist PATH for the current user (future shells) - $dotnetDir = Join-Path $env:USERPROFILE ".dotnet" - - $existingUserPath = [Environment]::GetEnvironmentVariable("PATH", "User") - - if ($existingUserPath -notlike "*$dotnetDir*") { - $newUserPath = "$dotnetDir;$existingUserPath" - [Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User") - } } } @@ -535,7 +537,8 @@ if (-not (VerifyDotNetSDK -RequiredVersion $dotNetSDKRequiredVersion)) #################################################################################### # Function to check if required version of dotnet desktop runtime is installed function VerifyDotNetDesktopRuntime { - param( + param + ( [Parameter(Mandatory)][string]$RequiredVersion, [Parameter(Mandatory)][ValidateSet("x86","x64")][string]$Architecture ) @@ -546,27 +549,50 @@ function VerifyDotNetDesktopRuntime { return $retval exit 1 } - - $dotnetExe = if ($Architecture -eq "x86") + $dotnetDir = if ($Architecture -eq "x86") { - Join-Path ${env:ProgramFiles(x86)} "dotnet\dotnet.exe" + Join-Path ${env:ProgramFiles(x86)} "dotnet" } else { - - Join-Path $env:ProgramFiles "dotnet\dotnet.exe" + Join-Path $env:ProgramFiles "dotnet" } - if (-not $dotnetExe) { - # default per-user install path - $dotnetExe = Join-Path $env:USERPROFILE ".dotnet\dotnet.exe" + $dotnetExe = Join-Path $dotnetDir "dotnet.exe" + + if (-not (Test-Path -LiteralPath $dotnetDir)) + { + Write-Host "Directory $dotnetDir not found." -ForegroundColor Red + $retval = $false + return $retval + exit 0 } - if (-not (Test-Path -LiteralPath $dotnetExe)) + if (-not (Test-Path -LiteralPath $dotnetExe)) { Write-Host "dotnet.exe not found at '$dotnetExe' (PATH may not be updated yet)." -ForegroundColor Red $retval = $false + return $retval + exit 0 } - $runtimes = & $dotnetExe --list-runtimes 2>$null + if ($Architecture -eq "x64") + { + $existingUserPath = [Environment]::GetEnvironmentVariable("PATH", "User") + if ($existingUserPath -notlike "*$dotnetDir*") + { + $newUserPath = "$dotnetDir;$existingUserPath" + [Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User") + Refresh-Path + } + } + if ($Architecture -eq "x86") + { + $runtimes = & $dotnetExe --list-runtimes 2>$null + } + else + { + $runtimes = & dotnet --list-runtimes 2>$null + } + # Extract versions like 8.0.1, 8.0.12, etc. $versions = foreach ($line in $runtimes) @@ -577,14 +603,13 @@ function VerifyDotNetDesktopRuntime { } } foreach ($version in $versions) { - if ($version -eq $RequiredVersion) + if (MajorMinorEqualBuildRevisionEqualOrHigher -Item "DOT NET DESKTOP RUNTIME" -ActualVersion $version -RequiredVersion $RequiredVersion -Silent) { $retval = $true break } } - if ($retval) { Write-Host ".NET $dotNetDesktopRuntimeRequiredVersion runtime $Architecture detected." -ForegroundColor Green @@ -598,7 +623,8 @@ function VerifyDotNetDesktopRuntime { # Function to download and install dotnet desktop runtime function InstallDotNetDesktopRuntime { - param( + param + ( [Parameter(Mandatory)][string]$RequiredVersion, [Parameter(Mandatory)][ValidateSet("x86","x64")][string]$Architecture ) @@ -616,7 +642,7 @@ function InstallDotNetDesktopRuntime { $installer = Join-Path $env:TEMP "dotnet-desktop-runtime-$channel-$Architecture.exe" Write-Host "Downloading .NET Desktop Runtime $channel ($Architecture)..." - Write-Host "The installer will request to run as administrator. Expect a prompt." + Write-Host " The installer will request to run as administrator. Expect a prompt." -ForegroundColor Yellow Invoke-WebRequest -Uri $url -OutFile $installer -UseBasicParsing Write-Host "Installing .NET Desktop Runtime $channel ($Architecture)..." @@ -689,7 +715,6 @@ catch "@ Write-Host "To install the AXCode:" -ForegroundColor Yellow Write-Host $axCodeGuide -ForegroundColor Yellow - exit 1 } @@ -751,7 +776,7 @@ catch if (-not $isApaxInstalled) { $apaxGuide = @" To download Apax: - 1. Visit https://console.simatic-ax.siemens.io/downloads in your browser. + 1. Proceed to: $axCodeDownloadUrl in your browser. 2. Log in with your credentials. 3. Follow the on-site instructions to download and install Apax. "@ @@ -780,7 +805,6 @@ if($isApaxInstalled) } } - # Check for apax $isApaxAccessible = $false try { @@ -789,8 +813,19 @@ try { Write-Host "resp $resp" -ForegroundColor Yellow if($resp[2].ToString().Contains("No access to the Simatic-AX registry")) { - Write-Host "Unable to access apax packages. Check your connections, firewall, credentials etc." -ForegroundColor Red - Write-Host "$errorOutput" -ForegroundColor Red + Write-Host "Unable to access apax packages." -ForegroundColor Red + Write-Host "$errorOutput" -ForegroundColor Red + $apaxGuide = @" + 1. Check your connections, firewall, credentials etc. + 2. Proceed to: $apaxUrl in your browser aand verify that it is accessible. + 3. Log in with your credentials. + 4. In the AX code environment run 'apax login' command. + 5. Choose the 'AX (for Apax packages and IDE extensions)' + 6. Log in with your credentials. + 7. Run this script again. +"@ + Write-Host $apaxGuide -ForegroundColor Yellow + exit 1 } else { @@ -801,6 +836,7 @@ try { catch { Write-Host "Error: Unable to access apax packages. Check your connections, firewall, credentials etc. : $($_.Exception.Message)" -ForegroundColor Red + exit 1 } #################################################################################### @@ -842,19 +878,19 @@ if ($jsonData.PSObject.Properties.Name -contains $inxtonRegistryUrl) }else { Write-Host "Registry '$inxtonRegistryUrl' not found in $maskedPath." -ForegroundColor Red - -$registryGuide = @" - -1. Generate a Personal Access Token on GitHub with 'read:packages' permissions (at least). -2. In AX code environment run 'apax login' command. -3. Choose the 'Custom NPM registry' -4. Enter the registry URL: $inxtonRegistryUrl -5. Enter your username -6. Enter your personal access token + $registryGuide = @" + 1. Generate a Personal Access Token on GitHub with 'read:packages' permissions (at least). + 2. In AX code environment run 'apax login' command. + 3. Choose the 'Custom NPM registry' + 4. Enter the registry URL: $inxtonRegistryUrl + 5. Enter your username + 6. Enter your personal access token + 7. Run this script again. Note: Treat your personal access token like a password. Keep it secure and do not share it. "@ - Write-Host "You need to provide apax login to external registry." $registryGuide - + Write-Host "You need to provide apax login to external registry." -ForegroundColor Yellow + Write-Host $registryGuide -ForegroundColor Yellow + exit 1 } @@ -874,7 +910,7 @@ try if ($isFeedAlreadyAdded) { - Write-Host "The NuGet feed with URL $nugetFeedUrl is already added." + Write-Host "The NuGet feed with URL $nugetFeedUrl is already added." -ForegroundColor Green } else { @@ -933,61 +969,20 @@ if($hasFeedAccess) if(-not ($isFeedAlreadyAdded -and $hasFeedAccess -and $hasFeedAutorization)) { $nugetGuide = @" -To manually add the GitHub NuGet feed to your sources: + To manually add the GitHub NuGet feed to your sources: -1. Generate a Personal Access Token on GitHub with 'read:packages', 'write:packages', and 'delete:packages' (if needed) permissions. -2. Open a command prompt or terminal. -3. Use the following command to add the feed to your NuGet sources: - dotnet nuget add source --username [YOUR_GITHUB_USERNAME] --password [YOUR_PERSONAL_ACCESS_TOKEN] --store-password-in-clear-text --name gh-packages-inxton $nugetFeedUrl + 1. Generate a Personal Access Token on GitHub with 'read:packages', 'write:packages', and 'delete:packages' (if needed) permissions. + 2. Open a command prompt or terminal. + 3. Use the following command to add the feed to your NuGet sources: + dotnet nuget add source --username [YOUR_GITHUB_USERNAME] --password [YOUR_PERSONAL_ACCESS_TOKEN] --store-password-in-clear-text --name gh-packages-inxton $nugetFeedUrl - Replace [YOUR_GITHUB_USERNAME] with your actual GitHub username and [YOUR_PERSONAL_ACCESS_TOKEN] with the token you generated. + Replace [YOUR_GITHUB_USERNAME] with your actual GitHub username and [YOUR_PERSONAL_ACCESS_TOKEN] with the token you generated. -Note: Treat your personal access token like a password. Keep it secure and do not share it. + Note: Treat your personal access token like a password. Keep it secure and do not share it. "@ - Write-Host "You need to add the GitHub NuGet feed to your sources manually." $nugetGuide -} - -#################################################################################### -# VISUAL STUDIO # -#################################################################################### -# Check for Visual Studio -if (Test-Path $vsWhereLocation) -{ - $vsVersion = & $vsWhereLocation -version $visualStudioRequiredVersionRange -products * -property catalog_productDisplayVersion - if (-not $vsVersion) - { - Write-Host "Visual Studio is not detected in required version or update. Required version range is $visualStudioRequiredVersionRange" -ForegroundColor Yellow - Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow - } - else - { - Write-Host "Visual Studio detected: $vsVersion" -ForegroundColor Green - Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor DarkBlue - } -} -else -{ - Write-Host "vswhere tool not found. Unable to determine if Visual Studio is installed." -ForegroundColor Yellow - Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow -} - -# Define a function to prompt and download -function PromptAndDownload { - param( - [string]$message, - [string]$downloadLink - ) - - $response = Read-Host "$message Would you like to download it now? (Y/N)" - if ($response -eq 'Y' -or $response -eq 'y') - { - Start-Process $downloadLink - } -} - -# Check for Visual Studio -if (-not $vsVersion) { - PromptAndDownload "Visual Studio is not detected." "https://visualstudio.microsoft.com/vs/" + Write-Host "You need to add the GitHub NuGet feed to your sources manually." -ForegroundColor Yellow + Write-Host $nugetGuide -ForegroundColor Yellow + exit 0 } #################################################################################### @@ -996,7 +991,8 @@ if (-not $vsVersion) { # Check if VS Build Tools is installed function Verify-VSBuildTools { - param( + param + ( [Parameter(Mandatory)][string]$RequiredVersion ) $retval = $false @@ -1014,16 +1010,40 @@ function Verify-VSBuildTools exit 1 } - Write-Host "Checking for Visual Studio Build Tools..." - $vsBuildToolsPath = & $vswhere -products Microsoft.VisualStudio.Product.BuildTools -property installationPath if ($vsBuildToolsPath) { - Write-Host "Visual Studio Build Tools already installed at: $vsBuildToolsPath" + Write-Host "Visual Studio Build Tools already installed at: $vsBuildToolsPath" -ForegroundColor Green $vsBuildToolsVersion = & $vswhere -products Microsoft.VisualStudio.Product.BuildTools -property installationVersion - $retval = MajorMinorEqualBuildRevisionEqualOrHigher -Package "Visual Studio Build Tools" -ActualVersion $vsBuildToolsVersion -RequiredVersion $RequiredVersion + $retval = MajorMinorEqualBuildRevisionEqualOrHigher -Item "Visual Studio Build Tools" -ActualVersion $vsBuildToolsVersion -RequiredVersion $RequiredVersion } + # Check if the VSBuildTools default installation path exists + if (Test-Path $expectedVCToolsInstallDir) + { + Write-Host "VSBuildTools default installation path exists: $expectedVCToolsInstallDir" -ForegroundColor Green + } + else + { + Write-Host "VSBuildTools default installation path could not be found: $expectedVCToolsInstallDir" -ForegroundColor Red + $retval = $false + return $retval + exit 1 + } + # Check if the environment variable exists + $vctoolsDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::Machine) + + if ($vctoolsDir -and $vctoolsDir -eq $expectedVCToolsInstallDir) + { + Write-Host "VCToolsInstallDir is set to: $vctoolsDir" -ForegroundColor Green + } + else + { + Write-Host "VCToolsInstallDir is not set correctly." -ForegroundColor Red + $retval = $false + return $retval + exit 1 + } return $retval } @@ -1038,12 +1058,34 @@ function Install-VSBuildTools { Invoke-WebRequest -Uri $vsBuildToolInstallationURL -OutFile $outFile -UseBasicParsing Invoke-Expression $vsBuildToolInstallCommand - Write-Host "VS Build Tools installation completed successfully." -ForegroundColor Green + # Check if the VSBuildTools default installation path exists + if (Test-Path $expectedVCToolsInstallDir) + { + Write-Host "VSBuildTools default installation path exists: $expectedVCToolsInstallDir" -ForegroundColor Green + } + else + { + Write-Host "VSBuildTools default installation path could not be found: $expectedVCToolsInstallDir" -ForegroundColor Red + exit 1 + } + try + { + # Set the environment variable after installation + [System.Environment]::SetEnvironmentVariable("VCToolsInstallDir", $expectedVCToolsInstallDir, [System.EnvironmentVariableTarget]::User) + } + catch + { + Write-Host "Failed to set VCToolsInstallDir environment variable or path. You will need to set it manually." -ForegroundColor Red + Write-Host "VCToolsInstallDir = $expectedVCToolsInstallDir" -ForegroundColor Red + exit 1 + } } catch { - Write-Host "VS Build Tools installationfinished with an error." -ForegroundColor Red + Write-Host "VS Build Tools installation finished with an error." -ForegroundColor Red + exit 1 } + exit 0 } # Check if VSBuildTools is installed @@ -1056,60 +1098,46 @@ if (-not (Verify-VSBuildTools -RequiredVersion $vsBuildToolRequiredVersion)) } } -exit 0 - -# Check if the environment variable exists -$vctoolsDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::User) - -if ($vctoolsDir -and (Test-Path $vctoolsDir)) -{ - # If the environment variable exists and the path is valid - Write-Host "VCToolsInstallDir is set and the path exists: $vctoolsDir" -foregroundcolor green -} -elseif ($vctoolsDir -and -not (Test-Path $vctoolsDir)) +#################################################################################### +# VISUAL STUDIO # +#################################################################################### +# Check for Visual Studio +if (Test-Path $vsWhereLocation) { - # If the environment variable exists but the path is invalid - Write-Host "VCToolsInstallDir is set but the path does not exist: $vctoolsDir" -foregroundcolor red + $vsVersion = & $vsWhereLocation -version $visualStudioRequiredVersionRange -products * -property catalog_productDisplayVersion + if (-not $vsVersion) + { + Write-Host "Visual Studio is not detected in required version or update. Required version range is $visualStudioRequiredVersionRange" -ForegroundColor Yellow + Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow + } + else + { + Write-Host "Visual Studio detected: $vsVersion" -ForegroundColor Green + Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor DarkBlue + } } else { - # If the environment variable doesn't exist or the path is invalid - Write-Host "VCToolsInstallDir is not set correctly or the path does not exist." -foregroundcolor red + Write-Host "vswhere tool not found. Unable to determine if Visual Studio is installed." -ForegroundColor Yellow + Write-Host "Visual Studio is optional you can use any editor of your choice like VSCode, Rider, or you can even use AXCode to edit .NET files." -ForegroundColor Yellow +} - # Prompt the user to confirm installation - $userResponse = Read-Host "Would you like to download and install Visual Studio Build Tools? (Y/N)" - - if ($userResponse -eq 'Y' -or $userResponse -eq 'y') - { - # If the user confirms, download and install Visual Studio Build Tools - Download-VSBuildTools - Install-VSBuildTools +# Define a function to prompt and download +function PromptAndDownload { + param( + [string]$message, + [string]$downloadLink + ) - try - { - # Set the environment variable after installation - [System.Environment]::SetEnvironmentVariable("VCToolsInstallDir", $expectedVCToolsInstallDir, [System.EnvironmentVariableTarget]::User) - } - catch - { - Write-Host "Failed to set VCToolsInstallDir environment variable or path. You will need to set it manually." -foregroundcolor red - Write-Host "VCToolsInstallDir = $expectedVCToolsInstallDir" -foregroundcolor red - } - # Verify that the environment variable and path are now correct - $finalVCToolsInstallDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::User) - - if ($finalVCToolsInstallDir -eq $expectedVCToolsInstallDir -and (Test-Path $finalVCToolsInstallDir)) - { - Write-Host "VCToolsInstallDir is now set correctly: $finalVCToolsInstallDir" - } - else - { - Write-Host "Failed to set VCToolsInstallDir environment variable or path." - } - } - else - { - # If the user declines installation - Write-Host "Installation aborted by the user." + $response = Read-Host "$message Would you like to download it now? (Y/N)" + if ($response -eq 'Y' -or $response -eq 'y') + { + Start-Process $downloadLink } } + +# Check for Visual Studio +if (-not $vsVersion) { + PromptAndDownload "Visual Studio is not detected." "https://visualstudio.microsoft.com/vs/" +} + From e6b587e2c1df54f0c70b13a65edb94e833158229 Mon Sep 17 00:00:00 2001 From: TK <61820360+TomKovac@users.noreply.github.com> Date: Thu, 15 Jan 2026 18:20:48 +0100 Subject: [PATCH 13/13] Update VCToolsInstallDir environment variable handling to user scope and add error handling --- scripts/check_requisites.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/check_requisites.ps1 b/scripts/check_requisites.ps1 index 5d97ac426..dd20af952 100644 --- a/scripts/check_requisites.ps1 +++ b/scripts/check_requisites.ps1 @@ -1031,7 +1031,7 @@ function Verify-VSBuildTools exit 1 } # Check if the environment variable exists - $vctoolsDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::Machine) + $vctoolsDir = [System.Environment]::GetEnvironmentVariable("VCToolsInstallDir", [System.EnvironmentVariableTarget]::User) if ($vctoolsDir -and $vctoolsDir -eq $expectedVCToolsInstallDir) { @@ -1042,6 +1042,17 @@ function Verify-VSBuildTools Write-Host "VCToolsInstallDir is not set correctly." -ForegroundColor Red $retval = $false return $retval + try + { + # Set the environment variable after installation + [System.Environment]::SetEnvironmentVariable("VCToolsInstallDir", $expectedVCToolsInstallDir, [System.EnvironmentVariableTarget]::User) + } + catch + { + Write-Host "Failed to set VCToolsInstallDir environment variable or path. You will need to set it manually." -ForegroundColor Red + Write-Host "VCToolsInstallDir = $expectedVCToolsInstallDir" -ForegroundColor Red + exit 1 + } exit 1 } return $retval