I have recently started using Visual Studio Code for creating simple C# projects to play around with the new language enhancements in C# 9.0. I ran into an issue when I have multiple classes with the Main
method. The Build
task flags this as an error and I could not find any way to set the startup project or the startup class from the editor UI.
If you have multiple Main
methods in C# and are looking to set the startup object in Visual Studio Code, open the .csproj
file, in it, find the PropertyGroup
element, and to it add:
<StartupObject>Namespace.ClassName</StartupObject>
In Visual Studio, you can get this done by – right click on the project, and choose “Set as Startup project"
.
If the project has multiple classes with Main
, in project Properties, Application
tab, select the class from the Startup object
dropdown.