Multiple exe files in one solution, all referencing a single public class
.net, c#, dll, visual-studio
Solution
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");
}
}
}
Problem
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!