How do I compile C# code as a library instead of an executable?

后端 未结 5 720
盖世英雄少女心
盖世英雄少女心 2021-01-12 02:56

I have a C# console application in Visual Studio 2010. It has a Main() method as well as a bunch of utility classes. I\'d like those utility classes to be available to other

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 03:58

    What I've always done (since this is what you do with C++ static libraries, which is what I normally use - though I think it has some advantages for C# too) is add the class library's project to the solution, then add a reference to it in the project (or projects) that uses it. When you go to add a reference, the list of potential references includes items from the solution, so it should be fairly obvious what to do. You should then get intellisense for your library.

    One advantage of doing things this way is that if you need to edit files in the library project, it's very straightforward because they are close to hand, and the project then gets rebuilt automatically when you compile the solution.

提交回复
热议问题