Setting the Startup class in Visual Studio Code

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s