As the OP came from a Java background, I think it worth answering this question in a slightly different way.
I understand the the OP has a few different C# classes with their corresponding static Main()
methods (each one of these classes probably being a different way to bootstrap the app code) and wants to easily switch between them when launching the app in Visual Studio.
So, the short answer is: there is no easy way :(
Firstly, you can not launch a project through a static Main()
method if its output type is a "Class Library". You need to change it to either "Console Application" or "Windows Application" to be able to launch it. This is completely different from the Java world where you can simply right-click on any class with a static main()
method, then click "Run as...", "Java Application". In Java, there is no such concept of a library project/module, so it doesn't matter if the project that contains this class with static main()
is a "library" or not.
Secondly, the easiest way I found is (very similar to Ray's answer):
- Right-click on the project, then "Properties"
- In "Application", make sure your output type is not "Class Library"
- Change "Startup Object" to the class whose
static Main()
is the one you want to run
- Right-click on your project, "Debug", "Start New Instance"
Unfortunately, I see no way to save in VS different launch configurations for the same project using different classes, so that you can easily switch between them. AFAICS the only way to achieve that is to create new projects inside the solution and configure them to launch the different main classes.
main
function?