5

Could anyone help me compile via command line some c# files? I have 4 files to compile, Main, Form1 (which uses 2.cs file) and another class used in the project.

I would like to compile this project in command line so I could add the /t:library switch (like in this tutorial: http://dotnetslackers.com/articles/csharp/WritingAnActiveXControlInCSharp.aspx).

However after using "csc /t:library Program1.cs MainForm.cs MainForm.Designer.cs EigenObjectRecognizer.cs" I get missing assembly reference errros such as these:

\Project\FaceRecProOVaspVer\FaceRecProOV\MainForm.cs(14,15): error CS0234: The type or namespace name 'Structure' does not exist
    in the namespace 'Emgu.CV' (are you missing an assembly reference?)

I do have installed EMGU binaries installed. I would think I need to use some .dll's from that folder like EMGU.CV.dll?

Iuli
  • 121
  • 1
  • 4
  • 12
  • 2
    When you have a Main and a Form1 you most likely __do not want__ `/t:library` – H H May 11 '12 at 21:57

1 Answers1

12

To reference a library on the command line you need to use the /r: compiler option and pass the relative path to the library. Assuming it's in the same directory you can do the following

csc /r:EMGU.CV.dll /t:library Program1.cs MainForm.cs MainForm.Designer.cs EigenObjectRecognizer.cs

Documentation: http://msdn.microsoft.com/en-us/library/yabyz3h4. Short version of documentation available directly from command line by specifying /?: C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc /?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 1
    Thank you kindly. How would I add more than 1 .dll library reference? I tried just placing the next one in continuation, but I get an error. I used csc /r:Emgu.CV.Dll Emgu.CV.UI.dll. Would the correct syntax be adding /r: to every library? – Iuli May 11 '12 at 22:09
  • 2
    @luli yes you'd need to add a `/r:` for every library you want to reference – JaredPar May 11 '12 at 22:10
  • 2
    @luli Actually you can use **semi-colon** to separate multiple dll files. It is described in the "*Referencing External Assemblies Using /reference*" section of the following article on MSDN: [Working with the C# 2.0 Command Line Compiler](http://msdn.microsoft.com/en-us/library/ms379563%28v=vs.80%29.aspx#csharpcompiler_topic8). Although it refers to C# 2.0, but hopefully *csc.exe* in modern versions still has this feature. – informatik01 Sep 04 '13 at 02:02
  • What if I want to add a reference to an already available assembly, specifically System.Printing. How should the command line be? – Shameel Mohamed Jul 31 '17 at 15:55