Compile Class using Command Line C# Compiler

No.of Views1094
Bookmarked0 times
Downloads 
Votes0
By  kirtan007   On  13 Jul 2010 09:07:10
Tag : CSharp , Miscellaneous
Many users know how to create code library using Visual Studio IDE in GUI environment for making code reusable code so that multiple application can use that dll.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Many users know how to create code library using Visual Studio IDE in GUI environment for making code reusable code so that multiple application can use that dll.but here I am writing something by which after reading this article you will be able to compile DLL using just command line C# compiler without opening Visual Studio IDE. 

Image Loading

Language

C# .net 2.0/3.5

Implementation

First let you tell what is out target is to compile a DLL (reusable code library) using command line c# compiler that is csc.exe.Fire up Notepad or any other your favorite text editor Program.

As example we will build simple dll that will contain methods like add() , substract() multiply().

using System;
 
namespace SimpleMaths
{public class Operations
    {public static int add(int a, int b)
        {return a + b;
        }public static int substract(int a, int b)
        {return a - b;
        }public static int multiply(int a, int b)
        {return a * b;
        }
    }
}

 Save the file with <FileName>.cs

Now open Start>>VisualStudio2005/2008 >> Visual Studio tools>>Visual Studio Command Prompt.

Now in command Prompt Locate the Directory where you have saved the .cs file just created. Using CD command.

Here I have given myfile name "test.cs".

Now for compiling our dll using csc.exe we need to pass arguments you csc.exe like what type of file we want to generate, What will be name of output dll file and source file from which we are building our dll File.

csc /target:library /out:MyMaths.dll test.cs

 

Image Loading

Press Enter and you will get your desired DLL file generated!!.You just have created DLL fFile with Command Line C# Compiler. Now use that dll file in any .net project !!

Now you will raise question how do I compile multiple source file (.cs) files? Well simple just execute commad like below one pass 2 names of source files in command while compiling it.

csc /target:library /out:MyMaths.dll test.cs test2.cs

Conclusion

This article teaches how to compile dll file in c# using command line C# Compiler of .net.

Sample Project Source

Download source files -1 kb

 
Sign Up to vote for this article
 
About Author
 
kirtan007
Occupation-
Company-
Member Type-Senior
Location-Not Provided
Joined date-02 Jul 2009
Home Page-http://kirtan.uni.cc
Blog Page-
He completed his Bachelor of Computer Application from Gujarat University 2009 .He is doing Master of Computer Application from Gujarat Technological University right now .. His area of Interests are Web Hacking , C# .net Windows form ,asp.net , WPF ,Silverlight ,SQL Server and Some PHP.
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top