Skip to content

Commit 4da4500

Browse files
committed
Added script to allow copying the runtime to Program Files when necessary for testing within VS.
1 parent f550b25 commit 4da4500

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

eng/copy-runtime.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This script copies the downloaded runtime into the Program Files directory.
2+
# This is necessary in certain situations when running tests in Visual Studio.
3+
4+
# Check if script is running as admin
5+
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
6+
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
7+
Write-Host "This script must be run as an administrator." -ForegroundColor Red
8+
exit 1
9+
}
10+
11+
# Read the runtime version.
12+
[xml]$versionPropsXml = Get-Content "$PSScriptRoot\Versions.props"
13+
# In XPath expression syntax, `//` means, "select the node that matches regardless of the location".
14+
$runtimeVersion = $versionPropsXml.SelectSingleNode("//MicrosoftNETCorePlatformsPackageVersion").InnerText
15+
16+
# Check if the repo was built.
17+
$runtimeRepoPath = "$PSScriptRoot\..\.dotnet\shared\Microsoft.NETCore.App\$runtimeVersion"
18+
if (-not (Test-Path -Path $runtimeRepoPath)) {
19+
Write-Host "The repo has not been built. Please run 'build.cmd' from the repo root." -ForegroundColor Red
20+
exit 1
21+
}
22+
23+
# Copy the runtime to the Program Files if it doesn't exist.
24+
$runtimeProgramFilesPath = "$env:ProgramFiles\dotnet\shared\Microsoft.NETCore.App\$runtimeVersion"
25+
if (-not (Test-Path -Path $runtimeProgramFilesPath)) {
26+
Copy-Item -Path $runtimeRepoPath -Destination $runtimeProgramFilesPath -Recurse
27+
Write-Host "Runtime copied to: $runtimeProgramFilesPath"
28+
}

0 commit comments

Comments
 (0)