I have a c# console project (vs2012) that is getting big. Currently I am calling multiple 'methods' one after the other. As I add more methods I would like to be able to break them out into multiple executable files, to be ran as scheduled apps, but still be able to reference (and change using tortoise SVN) a public class of rules of which they all will reference. Do I have to create a dll to accomplish this or is there a simpler way? Sorry, I'm new to all of this. I have found similar questions but I either did not understand them or they weren't quite what I was looking for. Thanks!
Yes you need to build a DLL and reference it from whatever project needs the code stored there.
It is just a matter to add a new Library project to your solution, create a public class and insert the methods that should be called from the other projects
Click the Menu File and choose Add Project
Then go to your Solution Explorer Window, click the Console Application and right click on references
and select from the Solution folder the Project of your class library
Now go to the predefined Class1 and add the following code
namespace ConsoleApplication1
{
// Class that contains methods and data to be used/shared by various applications
public class Class1
{
public Class1()
{ }
public void Show(string message)
{
Console.WriteLine(message);
}
}
}
and in your ConsoleApplication1 add the following code
namespace ConsoleApplication1
{
class Program
{
// A sample console application that uses the library project....
static void Main(string[] args)
{
Class1 c=new Class1();
c.Show("Hello World");
}
}
}
Do I have to create a dll to accomplish this or is there a simpler way?
If you want to achieve shared logic and modularity then the answer is no, no simpler way and you should create assembly (DLL) using the Class Library Project template in VS, write your public
classes, build it and reference it from your EXE's projects.
I would recommend you to have a solution with the Executables and the Class Library project together so you'll be able to enjoy maintainability and good synchronization with your Class Library by referencing it by Project and not by Assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With