In this section I add all of the Entity Framework and Automapper packages to the projects.
- [Instructor] In addition to updating the packages to the current versions, we need to add in packages for frameworks and tooling that we need for this project. So all the projects are going to get AutoMapper, Microsoft.EntityFramworkCore, and EntityFrameworkCore.SqlServer. Our data access layer project, that's the SpyStore DAL project, needs a lot more entity framework core tooling, so you see it's a much longer list than the other projects.
So we'll start with the SpyStoreAPI. Again we're going to right-click on the solution, Manage NuGet Packages for Solution, go to Browse, this time, and the entity framework you see here at the top, that's actually version six, it's not the one we want. But AutoMapper is right here. And we can select which projects to install it. Select all of them, and click Install.
Depending on your settings, you might get prompted for some license information or other confirmations. You can always check that box to not show it again. And we'll wait while that does the install. Running a little PowerShell in the background to update the references, copy appropriate files, and all of the related dependencies for AutoMapper. And then, finally, as you can see, it does a restore to bring everything back into the fold.
All right, it's finished. Now we're going to select, Microsoft .EntityFrameworkCore. Unfortunately there's no multi-select, so we have to pick them one at a time. This one as well as EntityFrameworkCore.SqlServer will go into all the projects, so we leave them all selected and we click Install.
Once again, we might get prompted, unless you've checked that box, I accept the license agreement. I know I clicked on those kind of fast, but, they're the same thing, they come up every time. Are you sure you want to install it? Do you accept the license agreement? Next, we add in Microsoft.EntityFrameworkCore.SqlServer. Again, we're going to put this into all of the projects, so we select Install, and wait for that to finish.
Actually, wait to get prompted for some dialogs, say yes, I accept. Now we wait for it to finish. Now that it's finished, we need to update the test project in our other solution. But the NuGet package manager isn't the only way that you can add or update packages. You can also do it directly into the CSPROJ file. So let's go into our test project here, right-click, and in 2017 we now have this option to edit the project file.
So we'll select that. I'm going to copy these three lines, and then I'm going to switch over to the other solution, and I'm going to right-click on the test project, edit the CSPROJ file, and in this first item group, I'm going to add those packages in. So this has the same effect as if I had gone out to the package manager, did a search, clicked on Install, and waited for all those dialogs to come through.
Now, when I save this file, Visual Studio, will restore those packages for you. Interestingly enough, you don't get prompted for the dialogs if you do it this way. All right, we will switch back to the API project, and we have to add a lot more packages to the data access layer project file, and instead of you watching me type all this, we're going to use the magic of clipboard inheritance, as I'm going to copy from the finished project, all of the references, and I'm going to paste them in here.
Once I save the project file, all of those packages that I've added will be downloaded. Any packages that I removed from the project file, will be removed from the project, and as you can see it's a very convenient way to add and remove packages, as long as you know the version. There is IntelliSense support built into the project file, however, I have found it to be flaky at best, so I try not to rely on it.
So in addition to AutoMapper, EntityFramworkCore, and EntityFrameworkCore.SqlServer, we've brought in those additional packages, very very quickly. Unfortunately, at this time, installing command line interface or .NET Core CLI packages must be done by hand. So we need to go back into the CSPROJ file for the SpyStore DAL project, and add the following lines.
So once again, using the magic of clipboard inheritance, I will come over here to the finished project, copy, go back to here, and paste that in, and then we can talk about it. So it's another item group. Instead of a package reference, it is a .NET CLI tool reference, as you can see on line 19. The tooling is EntityFrameworkCore.Tools.DotNet, and the current version is 1.0.
One way we can check the version, is we can go into NuGet, do a search. Ah, and we see we have an update, so the latest stable is 1.01. If I go to install this, you get an error message saying, it has the package type of DotNetCliTool, and it's not supported by the project. Well, it is supported by the project, it's not supported by Visual Studio.
But what we can do in here is, now that we have checked the version, just modify that to 1.01. We now have all of our packages that we need to migrate our application to DotNet core.
- Creating the .NET Core project
- Adding Entity Framework
- Migrating the data access layer (DAL)
- Configuring services and the HTTP pipeline
- Adding remaining services to the dependency injection container
- Migrating controllers and actions
- Testing the services