3: ServerConfig_InstallCSC - DavidRueter/SQLVer GitHub Wiki

In the PowerShell window, type (or paste) the following and then press Enter:

cd \SQLVer\Tools
.\nuget install Microsoft.Net.Compilers

## Create a symbolic link C:\SQLVer\Tools\csc to point to the latest Microsoft.Net.Compilers folder

# Define the target base directory
$toolsPath = "C:\SQLVer\Tools"

# Define the symbolic link name
$symlinkPath = "C:\SQLVer\Tools\csc"

# Ensure the script is running as Administrator
$CurrentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$Principal = New-Object Security.Principal.WindowsPrincipal $CurrentUser
if (-Not $Principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Host "Error: Please run PowerShell as Administrator." -ForegroundColor Red
    Write-Host "Attempting to restart as Administrator..."
    Start-Process PowerShell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
    exit 1
}

# Check if the Tools directory exists
if (-Not (Test-Path $toolsPath)) {
    Write-Host "Error: SQLVer tools directory not found at $toolsPath" -ForegroundColor Red
    Pause
    exit 1
}

# Get the directory of the most recent compiler version
$latestCSCFolder = Get-ChildItem -Path $toolsPath -Filter Microsoft.Net.Compilers.* | Sort-Object Name -Descending | Select-Object -First 1

if (-Not $latestCSCFolder) {
    Write-Host "Error: No C# compiler installations found in $toolsPath" -ForegroundColor Red
    Pause
    exit 1
}

$cscPath = "$latestCSCFolder" + '\tools'

# Remove existing symlink if it exists
if ((Get-Item $symlinkPath) -is [System.IO.DirectoryInfo] -and ((Get-Item $symlinkPath).Attributes -band [System.IO.FileAttributes]::ReparsePoint)) {
    Write-Host "Removing existing symbolic link: $symlinkPath"
    cmd /c rmdir $symlinkPath
}

# Create the symbolic link
Write-Host "Creating symbolic link: $symlinkPath -> $cscPath"
cmd.exe /c mklink /D "$symlinkPath" "$cscPath"

# Verify success
if (Test-Path $symlinkPath) {
    Write-Host "Symbolic link created successfully!" -ForegroundColor Green
} else {
    Write-Host "Error: Failed to create symbolic link." -ForegroundColor Red
    Pause
    exit 1
}

This will result in a folder named Microsoft.Net.Compilers.xxx being created in C:\SQLVer\Tools, and will create a symbolic link C:\SQLVer\Tools\csc that points to this new folder.

You will use the PowerShell window again on future install steps, so leave it open.

Note: if you already have the C# command line compiler csc.exe installed elsewhere on the server, it is not absolutely required that you install another copy using these instructions. But you will need to know the full path to the csc.exe file, and then create the symbolic link yourself by pasting the following in the PowerShell window and pressing Enter:

cmd.exe /c mklink /D C:\SQLVer\Tools\cas {your path to the folder where csc.exe is located}