1

Obviously I'm still new with .Net Core with this question so bare with me. I created a .Net Core Console Application through Visual Studio 2019 and it did not create a Startup.cs class automatically. All it created was Programs.cs file. From what I understand and reading there has to be a Startup class since it is effectively the Global.asx file in .Net framework.

First I want to make sure I didn't miss a step that would have created the Startup automatically? Second, I'm assuming I can copy the code out of one of my test MVC Core applications and just use that?

Same question with Appsettings.json, I'm assuming I can just copy one from another project?

Caverman
  • 3,371
  • 9
  • 59
  • 115
  • Startup.cs is not generated for Console application projects. What is the purpose of your application? If you're looking to build a web application, you probably don't want to start from the Console application template. – Luke Sep 02 '20 at 16:12
  • I'm wanting a console application to run on a Windows Task Scheduler. Watching a video now from Tim Corey on some of this. We typically use NLog for our logging program and going through their directions it's using the Startup.cs but I'm guessing now that that's for a MVC app. – Caverman Sep 02 '20 at 16:45
  • Correct, but you can still use NLog for a console application. Here is an example I found: https://gist.github.com/gravity00/c9384f07f389f0ce25819ee0e3aaa853 – Luke Sep 02 '20 at 17:01
  • Thanks, I'll look at that link. I'm also going to look at Serilog as well and might start using that logger. – Caverman Sep 02 '20 at 18:25
  • Does this answer your question? [Startup.cs in a self-hosted .NET Core Console Application](https://stackoverflow.com/questions/41407221/startup-cs-in-a-self-hosted-net-core-console-application) – Michael Freidgeim May 08 '22 at 12:18

2 Answers2

1

When you create .net core console application then your entry point will be Program.cs file Main() function

When you create MVC application in .net core then it creates StartUp.cs file as an entry program and application.json file for configuration.

Console application does not create both files for you.

Prasad Telkikar
  • 15,207
  • 5
  • 21
  • 44
0
  1. you didn't miss anything. when you create a console application then there no need for Startup.cs file.
  2. If you want to create a web application then Startup.cs file is necessary because it's called by Program.cs file.
  3. The main method will execute in both the application. eighter it is a console or web application. the main method is the entry point from where your application will start.
  4. Now if u r confused to take Startup.cs file it's for configuring various middleware for the web application that will be available during you will HTTP request from your browser.
  5. if you are confused to take appsetting.json this is the only configuration file that you can copy from any application to any application. but you will need to take care of what configuration you have done in it.
Manoj
  • 57
  • 3