Part 1 – Create a new Visual Studio solution

Partly as an excuse to post some pages on my blog but also as a starter for others getting into ASP.NET MVC Core (or even migrating from ASP.NET MVC 5). I’m hoping to cover some of the pitfalls that can be encountered. In this example I’m using Visual Studio 2015 and some of the tools included in there. All of this should work fine with the excellent and free community edition of Visual Studio 2015 (see this link to the Microsoft download page and choose the community edition, unless of course you are rich and want the full on Enterprise version!).

Once you’ve installed Visual Studio open it up and the welcome screen should have a link to create a new project, click this and you should then see this dialog…

visual-studio-create-project

 

For this tutorial I’m going to be using C# but the main concepts and tools should work fine with Visual Basic. So as you can see in the image above, expand the Visual C# tree and then click on the Web entry and you should see the above three different options you have by default for creating a new MVC project in Visual Studio. We’re going to be using one of the two ASP.NET Core projects.

If you were aiming for eventual deployment to Windows, Linux and Mac then you would need to select the (.NET Core) project. This will limit your project to use on the .NET Core library and not the full .NET framework, however the .NET Core framework is available over all three platforms unlike the .NET framework.

If on the other hand you are just developing for Windows, you can select the (.NET Framework) option for your project. We’re going to choose this version, if only for the fact that we’ll be using the full .NET version of the Entity Framework  later on in this project. If all the library functions you need are contained in the .NET Core framework it would make no sense to choose the Windows only .NET framework option.

Ok then, name you project/solution whatever you like and click ok to create it. In this example I’ve named the project Example.Web and the solution is just called Example. The reason for this naming convention is that I’d like to maybe add some more projects to my solution later on. So say for example I wanted to add a unit test project then to keep everything nice and neat we’d call it Example.Tests. This way you’ll end up with nice, neat and clearly named projects (and namespaces!) in your solution. This is especially true if you end up having a lot of projects in your solution eventually. You can of course create folders to separate things out in the solution but for now we’ll just stick with the default solution structure. You by now be presented with this screen…

visual-studio-choose-authentication

For our example I’m imaging a scenario where we are creating a small intranet application for work so I’ve chosen ‘Windows Authentication’ by clicking the ‘Change Authentication’ button. If you were creating a web site for some other purpose then you would probably not choose this option. We’re also not going to host in the cloud for now so untick that checkbox as well and click Ok and you’re project should begin creating. Eventually once its all settled down you should see the Solution Explorer window on the right and it should look like this…

.solution-explorer-start

 

Assuming all has gone ok all we need to do is test the application works by clicking the debug button at the top of Visual Studio. It looks like a green play button and should probably have ‘IIS Express’ on it…

start-debugging

 

Give it a moment and then it should open your browser and display the default welcome page setup in the application which should look something a little like this below…

welcome-page

 

And that brings us nicely to the end of part 1, stay tuned for part 2 coming as soon as I get some more time to do it – hope this has helped!

Advertisements