Discussion › Forums › discussion › Compiling a class using csc
This topic contains 0 voices and has 6 replies.
| Author | Posts |
|---|---|
| Author | Posts |
| April 27, 2010 at 3:05 pm #2792 | |
|
gj1118 Member
|
I would like to compile a C# class using the C# command line compiler. I am doing something like this C:WINDOWSsystem32cmd.exe /k “”C:Program FilesMicrosoft Visual Studio 9.0VCvcvarsall.bat”" x86″ csc /target:exe /reference:mscorlib.dll /out:test.exe test.cs and its failing with a message Failed to create Process: the system cannot find the file specified. Any help would be highly appreciated Thanks and regards GJ |
| April 27, 2010 at 3:16 pm #17093 | |
|
gj1118 Member
|
oops , forgot to mention that this was I added C:WINDOWSsystem32cmd.exe /k “”C:Program FilesMicrosoft Visual Studio 9.0VCvcvarsall.bat”" x86″ csc /target:exe /reference:mscorlib.dll /out:test.exe test.cs in the tools section of the C# tools option in PN |
| April 27, 2010 at 4:50 pm #17094 | |
|
simon Key Master
|
Hi, At a guess you need to move the /k bit from your command line to the Parameters box, e.g. Command: cmd.exe Parameters: /k “”C:Program … Also, note that you can only run one program in here, so if you want to combine running vcvarsall with calling csc then probably the best option is to create a simple batch file called build.bat or similar:
Then configure your tool like this: Command: build.bat Parameters: %n This will pass the filename part of the current file to the tool, to build filename.cs into filename.exe. |
| April 27, 2010 at 5:03 pm #17095 | |
|
gj1118 Member
|
Thanks Simon , for your help. really appreciate that.. I tried to follow this step of yours(right now I am using only 1 tool(csc))
Command: cmd.exe Parameters: /k “”C:Program … but now I am getting this error > “cmd.exe” /k “”C:Program FilesMicrosoft Visual Studio 9.0VCvcvarsall.bat”" x86″ csc /target:exe /reference:mscorlib.dll /out:test.exe test.cs The filename, directory name, or volume label syntax is incorrect. C:Program FilesProgrammer’s Notepad> Guess, this is happening because visual studio command prompt cannot be located?? that was just a wild guess.. but if you could please help me with this, that would be awesome Thanks and regards GJ |
| April 27, 2010 at 5:13 pm #17096 | |
|
gj1118 Member
|
Alternatively I also tried using your second approach , i.e creating a bat file here is how i created my bat file
@echo off call %comspec% /k “C:Program FilesMicrosoft Visual Studio 9.0Common7Toolsvsvars32.bat” csc /target:exe /reference:mscorlib.dll /out:%1.exe %1.cs after creating the bat file, i did exactly what you mentioned in your second part
Then configure your tool like this: Command: build.bat Parameters: %n This will pass the filename part of the current file to the tool, to build filename.cs into filename.exe. but then i get this message(note that – there are no errors, this time, thank you once again
> “ Setting environment for using Microsoft Visual Studio 2008 x86 tools.
but the file did not get executed and nor was the exe file created ? pray tell me , wat wrong did i do? Thanks again GJ |
| April 27, 2010 at 6:06 pm #17097 | |
|
gj1118 Member
|
Got it .. thanks@simon for somebody like me , here is how you can do it put this in a bat file
@echo off call C:WINDOWSMicrosoft.NETFrameworkv3.5csc.exe /target:exe /reference:mscorlib.dll /out:%1.exe %1.cs and Then configure your tool like this:
Command: build.bat Parameters: %n This will pass the filename part of the current file to the tool, to build filename.cs into filename.exe. |
| April 28, 2010 at 1:17 pm #17098 | |
|
simon Key Master
|
Great, glad you got it working. For reference, the problem with your previous file was this:
If you had used this I think it would have worked:
Using comspec starts a new command-prompt instance to run that command, which then exits afterwards. We want the changes from vsvars in our current session so we don’t use comspec. |
You must be logged in to reply to this topic.
)
PnCSharpBuild.bat” test