1

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

1
  • 1
    I don't see how you are specifying that tmp file into the csc command, you are just expecting an output with no input. Also add a bugreport to see the error. "/addmodule:$tmpFile /out:Launcher.exe bugreport:c:\WhyItFailed.txt Try that and report back Commented Dec 15, 2013 at 15:53

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

5 Comments

Now I get an corrupt file error. fatal error CS0009: Metadata file 'c:\Users\CollinScripter\AppData\Local\Temp\tmp1795.cs' could not be opened -- 'File is corrupt.'
Might be in the $csharp variable, are you sure it is a fully functioning c# app. Does the .cs temp file match the output desired (open with notepad.exe)
Start-Process -FilePath C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe -ArgumentList "/out:Launcher.exe $tmpFile" # Starts csc If that fixes it, I will edit answer.
c:\Users\CollinScripter\AppData\Local\Temp\tmpD546.cs(2,13): error C S0116: A namespace cannot directly contain members such as fields or methods c:\Users\CollinScripter\AppData\Local\Temp\tmpD546.cs(3,24): error CS1518: Expected class, delegate, enum, interface, or struct
Don't know really how to do that.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.