Notes from building a first ASP.Net Core App (part 1)

Here are a few points from building your first ASP.Net Core app.

  1. Go to the site http://docs.asp.net and download all the bits you need to get your environment going with Dot Net Core. I am using Visual Studio 2015, and everything I needed was provided as updates within that environment. You can download Visual Studio Community Edition or Visual Studio Code and get it working in either of those I believe.
  2. After the update, the Dot Net 5 templates that were available when you created a new ASP.Net web project are no longer there. You now create a new project using File->New Project->Visual C#->Web and choose ASP.Net Core Web Application (.Net Core). I started with the Empty template.
  3. Build the application and run it. It opens up a new web site, but the only thing you should see at this point is “Hello World.” It still uses IIS Express.
  4. The folder system stays in sync with your development environment. There is no longer a manifest kept of all your files. The folder structure is the web site. Add a file to the folder and it will automatically be added to the project. Delete a file from the folder and it will disappear from the project. There are still some hidden files, such as “bin” and “obj” but the rest stays in sync with the web site.
  5. If you run the Hello World application NOT in Debug mode, you will be able to update the files in the project folder, and the next time you refresh a page, Visual Studio will detect the change and automatically recompile the application. To watch this happen, make sure you have visual studio open on one screen, changing the wording of Hello World in the Startup.cs file from outside the Visual Studio environment (perhaps via Notepad), save it, and then Ctrl-F5 from Chrome in another screen. Within Visual Studio, you will see the project automatically compile and the web browser will update. That’s awesome, because for experienced developers, you’ll be able to update pages on-the-fly, which is a boon for productivity.
  6. Within a project, there are initially only a few files we are interested in. The first is project.json. project.json is used for storing project-wide configuration. It contains “version”, “dependencies”, “frameworks”
  7. “version” is the current version number of your application
  8. “dependencies” is a list of all the dependencies that the project relies on. You don’t have a readily available list of dependencies like this in old ASP.Net. This is where all the necessary libraries and frameworks are specified. Usually you won’t need to type these yourself – you can use the nuget package manager to load anything you need. To use the nuget package manager, right-click on References in the project list and click “Manage Nuget Packages.” If you do that right now, you will be able to see the list of Nuget Packages that are currently installed by default.
  9. “frameworks” is where the current dot net framework is specified.
  10. If you expand the References node in Solution Explorer, you will see that it is showing .NetCodeApp, Version=v1.0. Expand that node and you will see all the Nuget packages that it is now referencing. And you can, in turn, expand them and see all the packages that they are dependent on.
  11. To make files available to the site, they must appear under the wwwroot folder in your project.
  12. There is a new Startup.cs file. It contains a Startup class. ASP.Net looks for this file by convention. To get your ASP.Net application working nicely, you will need to modify the Configure method, which is where the http processing pipeline gets built. It defines how the application responds to requests.
  13. At the moment, the site does not serve html files. Wow, right? To do this, you will need to modify the Configure method to support the serving of html files. This is a deliberate design choice. Want to server an MVC application? Again, changes to the Configuration method will be needed. (I’ll get to that later.)
  14. There is also a ConfigureServices method, which is where you configure components needed within the application. It is here where we set up the Inversion Of Control container so we can perform functions like testing.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: