Last active
January 16, 2018 21:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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