diff --git a/scripts/prepare-machine.ps1 b/scripts/prepare-machine.ps1 index 335cd78d07..6512254cd6 100644 --- a/scripts/prepare-machine.ps1 +++ b/scripts/prepare-machine.ps1 @@ -466,10 +466,20 @@ function Install-Dotnet { } Write-Host "Installing dotnet" - # known issue https://learn.microsoft.com/en-us/dotnet/core/install/linux-package-mixup?pivots=os-linux-ubuntu - sudo bash -c "echo 'Package: dotnet* aspnet* netstandard*' >> /etc/apt/preferences" - sudo bash -c "echo 'Pin: origin packages.microsoft.com' >> /etc/apt/preferences" - sudo bash -c "echo 'Pin-Priority: -10' >> /etc/apt/preferences" + + # Check /etc/apt/preperences whether it has the known issue workaround + if (Test-Path /etc/apt/preferences) { + $hasKnownIssueWorkaround = (Get-Content /etc/apt/preferences | Select-String -Pattern "Package: dotnet* aspnet* netstandard*") -ne $null + if (!$hasKnownIssueWorkaround) { + # known issue https://learn.microsoft.com/en-us/dotnet/core/install/linux-package-mixup?pivots=os-linux-ubuntu + sudo bash -c "echo 'Package: dotnet* aspnet* netstandard*' >> /etc/apt/preferences" + sudo bash -c "echo 'Pin: origin packages.microsoft.com' >> /etc/apt/preferences" + sudo bash -c "echo 'Pin-Priority: -10' >> /etc/apt/preferences" + } else { + Write-Host "Known issue workaround already applied" + } + } + sudo apt-get update -y sudo apt-get install dotnet-sdk-6.0 aspnetcore-runtime-6.0 dotnet-runtime-6.0 }