1 00:00:00,430 --> 00:00:05,010 We now have all the dependencies our JsonToDb program needs to do its job. 2 00:00:05,010 --> 00:00:09,200 Now we need to do is use these libraries in our code and write the program. 3 00:00:09,200 --> 00:00:12,520 Because this workshop is about package management with NuGet, 4 00:00:12,520 --> 00:00:14,660 we'll leave that task for another day. 5 00:00:14,660 --> 00:00:18,790 To play with some more features of NuGet, let's create a whole new project. 6 00:00:18,790 --> 00:00:23,013 This time we'll create a project for an ASP.NET MVC application. 7 00:00:23,013 --> 00:00:27,450 So we'll click File > New > Project. 8 00:00:27,450 --> 00:00:31,447 Under Web, click ASP.Net Web Application. 9 00:00:31,447 --> 00:00:36,090 For this demo, just leave the project name and location the same, and click OK. 10 00:00:38,130 --> 00:00:43,907 We'll create an MVC web application and uncheck this box to host in the cloud. 11 00:00:43,907 --> 00:00:47,020 Pay attention to what happens when I click OK here. 12 00:00:47,020 --> 00:00:51,449 Because this is the first time I've created an ASP.NET MVC application on this 13 00:00:51,449 --> 00:00:56,040 computer, it will take a bit longer than usual to create this project. 14 00:00:56,040 --> 00:00:59,820 The reason for this is because most of the libraries that are needed to 15 00:00:59,820 --> 00:01:03,370 create an MVC application are downloaded from NuGet. 16 00:01:03,370 --> 00:01:04,960 when we look at our project, 17 00:01:04,960 --> 00:01:08,540 we can see that there's already a packages.config file. 18 00:01:08,540 --> 00:01:12,400 If we open the file, we can see a list of all the NuGet packages that our 19 00:01:12,400 --> 00:01:17,040 project needs, and we have a lot of assemblies listed under References. 20 00:01:17,040 --> 00:01:20,470 These were all installed from NuGet when the project was created. 21 00:01:22,460 --> 00:01:25,005 Let's add another package to our project. 22 00:01:25,005 --> 00:01:29,060 ELMAH is a popular way to add error logging to a website. 23 00:01:29,060 --> 00:01:31,990 It makes it much easier to troubleshoot errors that happen 24 00:01:31,990 --> 00:01:34,110 in ASP.NET applications. 25 00:01:34,110 --> 00:01:37,500 Since we only have a single project in our solution, just right-click 26 00:01:37,500 --> 00:01:41,240 on the project name to manage the NuGet packages for this project. 27 00:01:41,240 --> 00:01:45,180 In the search bar under Browse, we'll type elmah. 28 00:01:46,320 --> 00:01:53,100 Since we're creating an ASP.NET MVC application, we'll select Elmah.MVC. 29 00:01:53,100 --> 00:01:54,880 Look over here in the details. 30 00:01:54,880 --> 00:02:00,090 Notice that this package has a dependency on the ELMAH core library package. 31 00:02:00,090 --> 00:02:03,758 Nuget packages can have dependencies on other Nuget packages. 32 00:02:03,758 --> 00:02:10,500 By installing Elmah.MVC, it will install elmah.corelibrary for us automatically. 33 00:02:10,500 --> 00:02:14,260 So NuGet not only manages the dependencies of our project, but 34 00:02:14,260 --> 00:02:17,650 also the dependencies of those dependencies, and so forth. 35 00:02:17,650 --> 00:02:22,820 Here it says that Elmah.MVC will work with 36 00:02:22,820 --> 00:02:26,550 version 1.2.0 or greater of elmah.corelibrary. 37 00:02:26,550 --> 00:02:29,330 Let's go back up here and expand the Options area. 38 00:02:30,330 --> 00:02:35,430 These options don't only apply to the Elmah.MVC package we've selected. 39 00:02:35,430 --> 00:02:37,610 Changing these options will change them for 40 00:02:37,610 --> 00:02:40,210 all future packages we want to install. 41 00:02:40,210 --> 00:02:44,160 But we can change these options each time we want to install, update, or 42 00:02:44,160 --> 00:02:45,460 uninstall a package. 43 00:02:45,460 --> 00:02:48,120 Just be aware that they will remain set that way for 44 00:02:48,120 --> 00:02:52,050 the next package you want to install unless you change them again. 45 00:02:52,050 --> 00:02:55,710 Here we have a few options for how to deal with dependencies. 46 00:02:55,710 --> 00:03:00,710 Inside the Dependency behavior drop-down we see an option for Ignore Dependencies. 47 00:03:01,790 --> 00:03:03,180 If this is selected, 48 00:03:03,180 --> 00:03:06,930 then none of the dependencies of our packages will be installed automatically. 49 00:03:06,930 --> 00:03:10,610 These other options allow us to control which version of the dependencies 50 00:03:10,610 --> 00:03:11,660 should be used. 51 00:03:11,660 --> 00:03:14,180 NuGet assumes that all packages are versioned using 52 00:03:14,180 --> 00:03:16,380 the Semantic Versioning schema. 53 00:03:16,380 --> 00:03:20,340 Semantic Versioning refers to three numbers separated by dots. 54 00:03:20,340 --> 00:03:21,461 It's pretty straightforward. 55 00:03:21,461 --> 00:03:25,522 The three numbers correspond to the major, minor, and patch version numbers. 56 00:03:25,522 --> 00:03:30,087 [SOUND] When versioning the library, we should increment the major version number 57 00:03:30,087 --> 00:03:34,785 when we make breaking changes to the API, meaning code that worked with the previous 58 00:03:34,785 --> 00:03:39,039 version might need to be changed in order for it to work with the new version. 59 00:03:39,039 --> 00:03:42,954 We should increment the minor version when we add new features to the library 60 00:03:42,954 --> 00:03:46,300 that won't break any code that uses the library. 61 00:03:46,300 --> 00:03:49,820 And we should increment the patch version when releasing a version that 62 00:03:49,820 --> 00:03:51,850 only contains bug fixes. 63 00:03:51,850 --> 00:03:55,680 Finally we can identify prerelease versions of the library 64 00:03:55,680 --> 00:04:01,100 by appending -alpha, -beta and so on to the end of the version number. 65 00:04:01,100 --> 00:04:05,830 When searching for NuGet libraries, we can see packages that are only in prerelease 66 00:04:05,830 --> 00:04:07,900 by checking this check box here. 67 00:04:07,900 --> 00:04:11,960 This is handy when we want to experiment with future versions of a library. 68 00:04:11,960 --> 00:04:17,120 With Semantic Versioning in mind, the rest of these options start to make sense. 69 00:04:17,120 --> 00:04:20,377 Lowest refers to the lowest version that can be used. 70 00:04:20,377 --> 00:04:25,360 In the case of elmah.corelibrary, this is 1.2.0 because that's 71 00:04:25,360 --> 00:04:29,371 the lowest version that Elmah.MVC says it can work with. 72 00:04:32,285 --> 00:04:37,550 Highest Patch refers to the lowest minor version, but highest patch version. 73 00:04:37,550 --> 00:04:42,620 In the case of elmah.corelibrary, the lowest minor version is 1.2. 74 00:04:42,620 --> 00:04:46,180 But it should get the highest patch of 1.2 available. 75 00:04:46,180 --> 00:04:48,910 Highest Minor would get the highest minor and 76 00:04:48,910 --> 00:04:53,060 patch version for elmar.corelibrary that has a major version of 1. 77 00:04:53,060 --> 00:04:57,648 Highest gets the latest and greatest non-prerelease version of the library. 78 00:04:57,648 --> 00:05:01,790 By default, NuGet comes preconfigured to always install the lowest version of 79 00:05:01,790 --> 00:05:03,090 the dependency. 80 00:05:03,090 --> 00:05:07,100 However it's usually best to use the latest version of the library possible 81 00:05:07,100 --> 00:05:10,200 because it probably contains the fewest bugs and 82 00:05:10,200 --> 00:05:13,410 we can use it longer without it becoming too far out of date. 83 00:05:13,410 --> 00:05:16,540 You might think that NuGet should always install the highest version that's 84 00:05:16,540 --> 00:05:19,520 guaranteed to work with the library that depends on it. 85 00:05:19,520 --> 00:05:23,750 In that case, we would always want the highest minor version. 86 00:05:23,750 --> 00:05:27,962 The reason NuGet doesn't select this by default is because not all libraries 87 00:05:27,962 --> 00:05:30,379 are versioned using Semantic Versioning. 88 00:05:30,379 --> 00:05:34,444 They may use their own versioning system where a minor version may contain breaking 89 00:05:34,444 --> 00:05:34,976 changes. 90 00:05:34,976 --> 00:05:37,977 elmah.corelibrary uses Semantic Versioning, so 91 00:05:37,977 --> 00:05:40,710 I'm going to pick Highest Minor. 92 00:05:40,710 --> 00:05:45,175 This means we'll get a later version of elmah.corelibrary then we would have 93 00:05:45,175 --> 00:05:46,680 had we left this at Lowest. 94 00:05:48,120 --> 00:05:52,670 I mentioned earlier that NuGet packages have the ability to add files to a project 95 00:05:52,670 --> 00:05:54,630 other than just libraries. 96 00:05:54,630 --> 00:05:58,870 The File conflict action option here tells NuGet what to do if the file it's 97 00:05:58,870 --> 00:06:01,880 trying to add already exists in the project. 98 00:06:01,880 --> 00:06:06,395 We can also tell NuGet what to do when a package is uninstalled from a project. 99 00:06:06,395 --> 00:06:09,933 By checking this box, we tell NuGet to uninstall any dependencies 100 00:06:09,933 --> 00:06:13,800 that were installed with the package when this package is uninstalled. 101 00:06:13,800 --> 00:06:16,366 The second checkbox, Force uninstall, 102 00:06:16,366 --> 00:06:21,287 has to do with uninstalling packages that are dependencies of other packages. 103 00:06:21,287 --> 00:06:26,115 By checking this box, NuGet can uninstall a package even if there is another package 104 00:06:26,115 --> 00:06:28,097 in the project that depends on it. 105 00:06:28,097 --> 00:06:33,589 In most cases we want to keep Remove dependencies checked and 106 00:06:33,589 --> 00:06:36,287 Force uninstall unchecked. 107 00:06:36,287 --> 00:06:40,513 Let's click the Install button to install Elmah.MVC. 108 00:06:42,604 --> 00:06:45,800 Now this preview makes even more sense. 109 00:06:45,800 --> 00:06:49,900 We can review here the versions of the packages that will get installed. 110 00:06:49,900 --> 00:06:55,511 We can see here that instead of installing version 1.2.0 of elmah.corelibrary, 111 00:06:55,511 --> 00:07:00,894 we're getting 1.2.2 instead because we chose to install the highest minor and 112 00:07:00,894 --> 00:07:02,740 patch versions available.