जब हम C# Compiler को Command Line द्वारा Use करते हैं तो विभिन्न प्रकार की जरूरतों को पूरा करने के लिए हम विभिन्न प्रकार के C# Parameters को Specify कर सकते हैं, जो कि पूरी तरह से हमारी जरूरत पर निर्भर करते हैं। C# Compiler के साथ जिन Command Line Arguments को Use किया जा सकता है, उनकी Details को हम Command Prompt पर “csc /?” Command Specify करके प्राप्त कर सकते हैं।
हालांकि अलग-अलग प्रकार की जरूरतों को पूरा करने के लिए हम अलग-अलग Parameters को C# Compiler के साथ Specify कर सकते हैं। लेकिन फिलहाल हम केवल Output Files से सम्बंधित Parameters के बारे में ही बात करेंगे।
/out Parameter
इस Parameter के बारे में हम पिछले Post में पहले ही Discuss कर चुके हैं। इस Parameter को C# Compiler के साथ Specify करके हम C# Compiler को इस बात की Information देते हैं कि हम किस नाम व Extension की Compiled Assembly File Generate करना चाहते हैं। जब हम इस Parameter को Specify नहीं करते, तो Default रूप से Create होने वाली Output File का वही नाम होता है, जो हमारी C# Source File का नाम होता है।
उदाहरण के लिए यदि हमारी C# File का नाम HelloWorld.cs हो तो /out Parameter को Specify नहीं करने पर Generate होने वाली Output Assembly File का Default नाम HelloWorld.exe ही होता है।
इसका मतलब ये है कि यदि हम Notepad++ के NppExec Plugin के Execute Window में /out Parameter को Specify न करें, तो हम हमारे C# Command Line Compiler Command को पिछले चित्रानुसार भी Specify कर सकते हैं।
/target:exe Parameter
इस Parameter को Specify करके हम Command Line C# Compiler का प्रयोग करके एक Executable Console Application Build करते हैं। जबकि यदि हम इस Parameter को Specify नहीं करते, तब भी Default रूप से Create होने वाली Output File एक Executable .EXE Assembly File ही होती है।
यदि हम Notepad++ के NppExec Plugin के Execute Window में /target:exe Parameter को Specify करें, तो हम हमारे C# Command Line Compiler Command को निम्न चित्रानुसार भी Specify कर सकते हैं:
/target:library Parameter
इस Parameter को Specify करके हम Command Line C# Compiler का प्रयोग करके एक Single File *.dll Assembly Build कर सकते हैं और ऐसा करने के लिए हमें Notepad++ के NppExec Plugin के Execute Window में /target:library Parameter को निम्नानुसार Specify करना होता है। जैसे:
/target:winexe Parameter
हालांकि हम /target:exe Option द्वारा भी GUI Application Compile कर सकते हैं लेकिन जब हम इस Option को Use करते हुए GUI Application Compile करते हैं, तो GUI Application के Background में एक Console Window दिखाई देता रहता है। इसलिए सामान्यत: GUI Applications को Compile करने के लिए हम /target:winexe Parameter Specify करते हैं और ये Parameter Use करने पर GUI Application के Run होने पर Background में Console Window दिखाई नहीं देता।
हम Command Line Compiler के साथ Use किए जाने वाले विभिन्न Parameters को Dash Prefix के साथ भी Use कर सकते हैं। जैसे:
Referencing External Assemblies
जब हम हमारे .NET Application में किसी External Assembly में Defined Type (Class) को Use करते हैं, तो ऐसे .NET Application को Compile करने के लिए हमें Command Line C# Compiler को Use करते समय हर External Assembly का Reference Specify करना जरूरी होता है, ताकि Command Line Compiler को पता रहे कि Current Application में जिन Classes को Use किया गया है, उनमें से कुछ Classes mscorlib.dll Assembly में Exist नहीं है बल्कि किसी External Assembly में Defined है।
mscorlib.dll File में Specified Classes वास्तव में Base Class Library की Classes होती हैं। जबकि हमने पिछले Chapter में Discuss किया था कि Microsoft ने Base Class Library के अलावा भी कई अन्य Libraries को Define किया है, जिन्हें FCL द्वारा Refer किया जाता है।
FCL की Classes व अन्य Classes को जिन Assemblies में Defined किया गया होता है, उन्हें External Assemblies के नाम से जाना जाता है और उन Assemblies में Defined Classes को यदि Current .NET Application में Use किया जाता है, तो Command Line Compiler को उन External Assemblies को Refer करते हुए ही Compile करना जरूरी होता है, अन्यथा Compile Time Error Generate होने की सम्भावना रहती है।
यहां एक ध्यान देने वाली बात ये है कि किसी Assembly में कई प्रकार के Namespaces हो सकते हैं, जबकि अलग-अलग तरह के बहुत सारे Types के Collection को Namespace के नाम से जाना जाता है। यानी एक Namespace में एक या एक से अधिक प्रकार के बहुत सारे Types हो सकते हैं जबकि एक Assembly में बहुत सारे Namespaces हो सकते हैं क्योंकि सभी Namespaces किसी न किसी EXE या DLL File के रूप में ही Assembled होते हैं, जिन्हें Assembly के नाम से जाना जाता है।
किसी .NET Application को Compile करते समय किसी External Assembly को Reference करने के लिए हमें निम्नानुसार तरीके से Command Line Compiler के साथ External Assembly Related Parameters को Specify करना होता है:
PROMPT:> csc -r:System.Windows.Forms.dll HelloWorld.cs
इसी तरह से यदि एक ही .NET Application में एक से ज्यादा External Assemblies के Types का प्रयोग किया गया हो, तो Command Line Compiler के साथ “/r:” Parameter के साथ Semicolon से Separate करते हुए Multiple External Assemblies को Specify कर सकते हैं। जैसे:
PROMPT:> csc -r:System.Windows.Forms.dll;System.Drawing.dll HelloWorld.cs
Compiling Multiple Source Files
किसी भी .NET Application में सारी Coding को कभी भी एक Single File में नहीं लिखा जाताए बल्कि किसी भी Project में अलग-अलग जरूरतों को पूरा करने से सम्बंधित अलग-अलग Source Files Create की जाती हैं और सभी Source Files मिलकर कोई एक EXE Executable या DLL Library File Generate करते हैं। इसलिए जब हम किसी Multiple Source Files के Project को Command Line द्वारा Compile करना चाहते हैं, तब हमें निम्न तरीके को Use करना होता है:
csc -r:System.Windows.Forms.dll;System.Drawing.dll HelloWorld.cs TestApplication.cs
इस Command Line Statement द्वारा हम C# Compiler को ये बता रहे हैं कि हमारे Currently Compile किए जाने वाले Project में HelloWorld.cs व TestApplication.cs नाम की दो C# Source Files हैं, जिनमें Use किए गए Types को System.Windows.Forms.dll व System.Drawing.dll नाम की Assemblies में Define किया गया है।
जब हम इस तरह से Command Line Compiler का प्रयोग करके किसी Project की Multiple Source Files की Compiling करते हैं, तब भी Output के रूप में एक ही Executable Generate होता है, जिसे .NET Platform के CLR द्वारा Run किया जाता है।
C# Response Files
जब हम Command Line Compiler Parameters Use करते हैं, तब Parameters के रूप में हमें बार-बार Input, Output व Parameters की Information के रूप में बहुत सारी Typing करनी पडती है। इस परेशानी से बचने के लिए Command Line C# Compiler हमें Response Files नाम की एक सुविधा Provide करता है।
C# Response File में हम हमारे Current Project के Compilation से सम्बंधित सारे Instructions को एक ही File के Instructions रूप में Define करते हैं। इस Response File का Extension *.rsp (Response) रखा जाता है।
उदाहरण के लिए यदि हम TestingApp.rsp नाम की एक Response File Create करें, तो उसमें हम निम्नानुसार तरीके से Compilation से सम्बंधित विभिन्न Input, Output व Parameters को Specify कर सकते हैं:
File Name: TestingApp.rsp #External Assembly Reference /r:System.Windows.Forms.dll;System.Drawing.dll #Output and Source Files to Compile /target:exe /out:TestingApp.exe *.cs
इस तरह से एक Response File में विभिन्न Parameters Specify करने के बाद हम इस Response File को ही Directly Command Line C# Compiler पर निम्नानुसार तरीके से @ Symbol के साथ Pass कर सकते हैं:
csc @TestingApp.rsp
जबकि यदि हम चाहें तो एक साथ एक से ज्यादा Response Files को निम्नानुसार तरीके से C# Compiler के साथ Specify कर सकते हैं:
csc @TestingApp.rsp @TestingApp1.rsp @TestingApp2.rsp
जब हम इस तरीके को Use करते हैं, तब इस बात का ध्यान रखना जरूरी होता है कि बाद का Parameter या बाद में Specified Response File के अन्दर Specified Parameters, पहले Specified Parameter या Response File के अन्दर Specified Parameters को Override करते हैं। जैसे:
csc /out:MyTestingApp.exe @TestingApp.rsp
यदि हम इस Command Line को Use करें, तो Generate होने वाली Executable File का नाम MyTestingApp.exe नहीं होगा, क्योंकि TestingApp.rsp नाम की Response File में हमने निम्न Statement द्वारा Target File के रूप में TestingApp.exe नाम ही Specify किया है:
/target:exe /out:TestingApp.exe *.cs
जो कि बाद में Specified होने की वजह से MyTestingApp.exe नाम को Override कर देता है।
Default Response File
C# के साथ csc.rsp नाम की एक Default Response File भी Install होती है, जिसके साथ C# Compiler Default रूप से Associated रहता है। ये File भी “C:/Windows/Microsoft.NET/Frameworks/” में Installed विभिन्न Versions के .NET Frameworks के Folder में Saved होती है, जहां C# Compiler Installed होता है।
इसलिए यदि हम इस File को Notepad के माध्यम से Open करें, तो हम देख सकते हैं कि इस File में Web Development, LINQ Programming, Data Access व mscorlib.dll Assembly में उपलब्ध विभिन्न Core Libraries के अलावा कई और अन्य Assemblies को पहले से ही “/r:” Flag के साथ Specify किया गया होता है। जैसे:
File Name: csc.rsp # This file contains command-line options that the C# # command line compiler (CSC) will process as part # of every compilation, unless the "/noconfig" option # is specified. # Reference the common Framework libraries /r:Accessibility.dll /r:Microsoft.CSharp.dll /r:System.Configuration.dll /r:System.Configuration.Install.dll /r:System.Core.dll /r:System.Data.dll /r:System.Data.DataSetExtensions.dll /r:System.Data.Linq.dll /r:System.Data.OracleClient.dll /r:System.Deployment.dll /r:System.Design.dll /r:System.DirectoryServices.dll /r:System.dll /r:System.Drawing.Design.dll /r:System.Drawing.dll /r:System.EnterpriseServices.dll /r:System.Management.dll /r:System.Messaging.dll /r:System.Runtime.Remoting.dll /r:System.Runtime.Serialization.dll /r:System.Runtime.Serialization.Formatters.Soap.dll /r:System.Security.dll /r:System.ServiceModel.dll /r:System.ServiceModel.Web.dll /r:System.ServiceProcess.dll /r:System.Transactions.dll /r:System.Web.dll /r:System.Web.Extensions.Design.dll /r:System.Web.Extensions.dll /r:System.Web.Mobile.dll /r:System.Web.RegularExpressions.dll /r:System.Web.Services.dll /r:System.Windows.Forms.Dll /r:System.Workflow.Activities.dll /r:System.Workflow.ComponentModel.dll /r:System.Workflow.Runtime.dll /r:System.Xml.dll /r:System.Xml.Linq.dll
अलग-अलग .NET Framework Versions में इस Response File में Specified Assemblies की संख्या अलग-अलग हो सकती है। उदाहरण के लिए .NET Framework 2.0 में इस File में केवल निम्नानुसार Assemblies को ही Specify किया गया था:
File Name: csc.rsp # This file contains command-line options that the C# # command line compiler (CSC) will process as part # of every compilation, unless the "/noconfig" option # is specified. # Reference the common Framework libraries /r:Accessibility.dll /r:Microsoft.Vsa.dll /r:System.Configuration.dll /r:System.Configuration.Install.dll /r:System.Data.dll /r:System.Data.OracleClient.dll /r:System.Data.SqlXml.dll /r:System.Deployment.dll /r:System.Design.dll /r:System.DirectoryServices.dll /r:System.dll /r:System.Drawing.Design.dll /r:System.Drawing.dll /r:System.EnterpriseServices.dll /r:System.Management.dll /r:System.Messaging.dll /r:System.Runtime.Remoting.dll /r:System.Runtime.Serialization.Formatters.Soap.dll /r:System.Security.dll /r:System.ServiceProcess.dll /r:System.Transactions.dll /r:System.Web.dll /r:System.Web.Mobile.dll /r:System.Web.RegularExpressions.dll /r:System.Web.Services.dll /r:System.Windows.Forms.Dll /r:System.Xml.dll
सामान्यत: जब हम हमारे किसी C# Source File को Command Line C# Compiler द्वारा Compile करते हैं, तो विभिन्न Command Line Input, Output व Parameters को Specify करने अथवा Custom Response File Specify करने के बावजूद C# Compiler इस Default csc.rsp File को Automatically Internally Reference करता है। इसलिए जिन Assemblies को Currently Use किए जा रहे .NET Framework की इस Default csc.rsp File में Specify किया गया है, उन Assemblies को Command Line पर “/r:” Parameter के साथ Specify करने की जरूरत नहीं होती।
लेकिन यदि हम चाहें, तो Command Line पर “/noconfig” Parameter Specify करके C# Compiler द्वारा Default रूप से Use होने वाली csc.rsp File को Automatically Use होने से रोक सकते हैं। जैसे:
csc #TestingApp.rsp /noconfig
Command Lines C# Compiler से सम्बंधित इन बातों के अलावा और भी कई बातें हैं, जिनके बारे में हम तब चर्चा करेंगे, जब उन्हें Use किया जाएगा।
इस तरह से इस Post में हमने उस समय कुछ बहुत ही ज्यादा उपयोग में आने वाले Command Line Arguments के बारे में जाना जब हम हमारे C# Program को Command Prompt के माध्यम से Compile कर रहे होते हैं अथवा Notepad++ को IDE की तरह Use कर रहे होते हैं।
ये Article इस वेबसाईट पर Selling हेतु उपलब्ध EBook C#.NET in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी।
C#.NET in Hindi | Page:908 | Format: PDF