Does not contain a static 'main' method suitable for an entry point

前端 未结 26 1701
时光说笑
时光说笑 2020-12-05 12:55

I began organizing my code to day into seperarate .cs files, and in order to allow the methods that work with the UI to continue to do so I would create the .cs code under t

相关标签:
26条回答
  • 2020-12-05 13:17

    If you are like me, then you might have started with a Class Library, and then switched this to a Console Application. If so, change this...

    namespace ClassLibrary1
    {
        public class Class1
        {
        }
    }
    

    To this...

    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-05 13:18

    If you don't have a file named Program.cs, just add a new Class and name it Program.cs.

    Then paste this code:

     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;
     using System.Windows.Forms;
    
     namespace Sales {
         static class Program {
    
             /// <summary>
             /// The main entry point for the application.
             /// </summary>
             [STAThread]
             static void Main() {
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
                 Application.Run(new Form1());
             }
         }
    
     }
    
    0 讨论(0)
  • 2020-12-05 13:18

    For me, the error was actually produced by "Feature 'async main' is not available in C# 7.0. Please use language version 7.1 or greater". This issue was resulting in the "Does not contain a static 'main' method suitable for an entry point" message in the Error List, but the Output window showed the "not available" error. To correct this, I changed the language version from 'C# latest minor version (default)' to 'C# latest minor version (latest)' under Advanced Build Settings.

    0 讨论(0)
  • 2020-12-05 13:18

    Edit .csproj file

    <OutputType>Library</OutputType>

    cheers !

    0 讨论(0)
  • 2020-12-05 13:20

    Change the Output Type under the Project > Properties to that of a “Class Library”. By default, this setting may have been set to a “Console Application”.

    0 讨论(0)
  • 2020-12-05 13:20

    Check to see if the project is set as the "Startup Project"

    Right click on the project and choose "Set as Startup Project" from the menu.

    0 讨论(0)
提交回复
热议问题