2013-12-15 37 views
1

我有一些代碼,沒有編譯在PowerShell中的.exe文件,PowerShell不要編譯C#代碼爲.exe文件

$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 

當腳本加載有與CSC.EXE毫秒內關閉該彈出窗口。 任何人都可以幫忙嗎?謝謝,CollinScripter

+1

我不明白你是如何指定該tmp文件到csc命令,你只是期待沒有輸入的輸出。還要添加一個bugreport來查看錯誤。 ''/ addmodule:$ tmpFile /out:Launcher.exe bugreport:c:\ WhyItFailed.txt'試試這個並回報 –

回答

1

添加輸入後,效果會更好。我用你的代碼片段生成了一個fatal error CS2008: No inputs specified

$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 
+0

現在我得到一個損壞的文件錯誤致命錯誤CS0009:元數據文件'c:\ Users \ CollinScripter \ AppData \ Local \ Temp \ tmp1795.cs'無法打開 - 'File is corrupt。' – Collinscripter

+0

可能在$ csharp變量中,你確定它是一個功能齊全的c#應用程序.cs temp文件是否與所需輸出匹配(用notepad.exe打開) –

+0

已測試,未損壞 – Collinscripter

1

爲了防止新的窗口出現,你可以使用NoNewWindow開關:

Start-Process -FilePath C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe -NoNewWindow -ArgumentList "/out:Launcher.exe" 

注意當前的命令不流通的源文件進行編譯。