Skip to content

Instantly share code, notes, and snippets.

@pcrama
Last active January 16, 2018 21:36
Show Gist options
  • Save pcrama/f236c1e8a3ecb03add98c11d4a534531 to your computer and use it in GitHub Desktop.
Save pcrama/f236c1e8a3ecb03add98c11d4a534531 to your computer and use it in GitHub Desktop.
Simplistic PowerShell script to call latest C# compiler on a simple .cs file
Param(
[string]$dir,
[string]$f,
[string]$x64, # "64" for x64 compiler, "" for 32bit
[string]$extraRef
)
Write-Host 'looking for C# compiler' -nonewline
# Get latest directory into $v
$v = ""
Get-ChildItem -Attributes Directory C:\Windows\Microsoft.NET\Framework$x64\v* `
| Sort-Object -Descending `
| ForEach-Object{ If ("$v" -EQ "") { $v = "$_" } }
Write-Host ", use $v" -nonewline
# $oldLocation = Get-Location
# Set-Location "$dir"
if ($extraRef -eq "") {
$argList = @("$f")
} else {
$argList = @("$f", "/reference:$v\$extraRef")
}
Start-Process "$v\csc.exe" -ArgumentList $argList -Wait -NoNewWindow -WorkingDirectory "$dir"
# Set-Location "$oldLocation"
Write-Host ', done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment