-1
csc /target:library /out:MyMaths.dll ClassLibraryFunction.csproj

I am using this code to generate a DLL in VS.Cmd compiler for a whole solution. However, I am getting a compile error, and the DLL is not being generated.

ErikE
  • 48,881
  • 23
  • 151
  • 196
pratik godha
  • 73
  • 1
  • 8

1 Answers1

6

csc does not work with .csproj files. You have a few options:

  1. use msbuild; for example

    msbuild ClassLibraryFunction.csproj
    

    noting that you may need to change the output-type of the project (in the IDE this is Project Properties, Application, Output type; in the csproj file this is <OutputType>Library</OutputType>)

  2. use csc with the /recurse switch; for example:

    csc /target:library /out:MyMaths.dll /recurse:*.cs
    

    (which will compile all the .cs files in the current folder or in sub-folders)

  3. do nothing whatsoever, and just use the exe that you already have; a .NET exe can be referenced just like any other assembly, and any public types can be consumed

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • @pratikgodha a project **can be** a dll; you just set the project's output as library. The word is "whole", btw; not "hole" - that means something completely different. – Marc Gravell Jan 03 '13 at 10:37
  • yes i can add lib. to the new Application but on that time i am not able to access the classes. what i want when i will create a dll for a application1 which contains the classes and when i will create a new application2 and attach a lib. or dll into application2 i will be able to access all the classes . – pratik godha Jan 03 '13 at 11:07
  • @pratikgodha everything you have said is normal behaviour for a library. The only question I have is simply: are the types `public`? BTW: did you know you can also add a reference to an exe? So even if your application is currently an exe, you can **still** reference it from another project, and consume the types. As long as they are `public`. – Marc Gravell Jan 03 '13 at 11:13
  • yes i know that i can add reference .exe but when i am accessing that not able to call classes which it exe contains do you understand what i want and what i want to do ? – pratik godha Jan 03 '13 at 11:20
  • @pratikgodha allow me to say again: that should work fine. If you can't see the types, then you need to go and make them `public`. – Marc Gravell Jan 03 '13 at 11:33
  • you mean to say Class will be a **Public** then my all classes is publicly define but i am not able to call. – pratik godha Jan 03 '13 at 12:06
  • @pratik then my next guess would be: different namespaces (add a `using` directive). But it has nothing to do with whether it is built as an exe or a dll. – Marc Gravell Jan 03 '13 at 12:31
  • all the namespace and classes is ok when i will make a DLL for a single class and add it into reference this is then ok to call class but prob is to create a DLL for Whole Application. – pratik godha Jan 03 '13 at 12:41
  • @pratikgodha there is no fundamental difference between a dll for a single class and a dll/exe containing an entire application. Whatever you are doing wrong, it has nothing whatsoever to do with whether you build it as an exe or a dll – Marc Gravell Jan 03 '13 at 12:44
  • create application having a classes and create another application and add exe/dll of the first application then call classes if you will be able to access that class then please rep. – pratik godha Jan 03 '13 at 13:03
  • @pratikgodha yes, you can access the classes. If you can't, you've done something wrong, but I can't tell you what based on the very limited information available. – Marc Gravell Jan 03 '13 at 13:10
  • i told you that i am not able to access any class after attaching the dll/exe. – pratik godha Jan 03 '13 at 13:18
  • @pratikgodha then ... is there still a problem? – Marc Gravell Jan 03 '13 at 13:19
  • yes there is a prob i want to access classes in another application which is in first application dll/exe but still i am not able to call the classes – pratik godha Jan 03 '13 at 13:22
  • @pratikgodha I cannot answer that with the information you have presented, which has nothing whatsoever to do with the question you asked – Marc Gravell Jan 03 '13 at 13:26