Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello i m in trouble i want to compile my a simple c# program from command promt using cmd.exe
but the problem is the latest versio of c#
I am Using Visual Studio 2013 Profssional installed 4.6 framework including c# version 6
but whenever i try to compile using cmd its failed..what should i Do Please Help Me

What I have tried:

trying c# prgram compilation using cmd
Posted
Updated 5-Jun-16 5:09am
Comments
Richard MacCutchan 5-Jun-16 7:46am    
Use Visual Studio, it's easy.

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Jun-16 11:12am    
I voted 4 this time. What you referenced is good, must-know information.
Only in practice, something very different is required: to build whole project, or, better, solution, to guarantee the same result as the build via Visual Studio. The ways to do so is most reliable and standardized.

Please see Solution 3.

—SA
First of all, it's very important to have one-click full build (batch build) of your software product, especially when it is actively develop and/or enter the phase of production.

But it has nothing to do with "CMD". Some confuse CMD with starting application with a command line. No, CMD is a regular application itself, no different from any other. It starts a command-line interpreter, which is irrelevant to your problem. Many other application can start a process via a command line, including the one you can develop. What you really need is one-click object: you click on it, and it build all the project without having to load Visual Studio, that's it. The adequate form of such file could be a batch file of one of the batch types: .bat, .WSF, .ps1 (should better be used with .lnk), .lnk… As the script you would need for this purpose is very simple (see below); all complexity is hidden in your solution and project files, I don't even consider the skills of writing such scripts as programming skills; it's closer to the level of "advanced user".

You can build (this is more precise expression than "compile", because build is what you really do, it can include compilation and many more steps) your project on different levels: by using separate source code files (see Solution 2), by project, by solution.

The most universal approach is the build of whole solution using MSBuild, which is standardized tool using standardized project file format. (You can write custom tasks, custom project types, adapt your own programming languages, and so on.) You can also use MSBuild to build a separate project, which, in your case, will create an output directory and output the build artifact which corresponds to a single output assembly.

MSBuild is what Visual Studio actually use. Please see:
MSBuild[^],
MSBuild Reference[^].

But at this moment you only need MSBuild command line: MSBuild Command-Line Reference[^].

First, you need to locate the MSBuild.EXE file and write its full path name. This is the example of simple batch:
set build=%windir%\...full-path-name... ...\MSBuild.exe
%build% mySolution.sln

This is a bit more complex example to build the same product in two configurations "Debug", and then "Release"; the output directories are prescribed in each project:
set build=%windir%\...full-path-name... ...\MSBuild.exe
set solution=mySolution.sln

%build% %solution% /p:Configuration=Debug
%build% %solution% /p:Configuration=Release

—SA
 
Share this answer
 
v3
To compile and run from a command prompt
Paste the code from the preceding procedure into any text editor, and then save the file as a text file. ...
Perform one of the following steps to open a command-prompt window: ...
In the command-prompt window, navigate to the folder that contains your Hello.cs file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900