I have some code that is not compiling to an .exe file in PowerShell,
$csharp = '#CSharp code goes here'
$tmpFile = [IO.Path]::GetTempFileName() + ".cs" # Creates Temp file
Out-file -FilePath $tmpFile -InputObject $csharp # sets content
Start-Process -FilePath C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe -ArgumentList "/out:Launcher.exe" # Starts csc
When the script loads there is a popup with csc.exe that closes within milliseconds. Could anyone help? Thanks, CollinScripter
To prevent the new window from appearing you can use the NoNewWindow
switch:
Start-Process -FilePath C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe -NoNewWindow -ArgumentList "/out:Launcher.exe"
Note your current command is not passing the source file to compile.
Works better once you add an input. I generated a fatal error CS2008: No inputs specified
with your snippet.
$csharp = '#CSharp code goes here'
$tmpFile = [IO.Path]::GetTempFileName() + ".cs" # Creates Temp file
Out-file -FilePath $tmpFile -InputObject $csharp # sets content
Start-Process -FilePath C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe -ArgumentList "/addmodule:$tmpFile /out:Launcher.exe" # Starts csc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.