Creating NuGet Packages the easy way with .NET Standard in C#

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
new get packages are away a share versioned code with the world if you've done ain't development c-sharp you've probably used a nougat package even if you didn't know it almost every template in Visual Studio is made up of nougat packages then allows us to create flexible applications that upgrade parts of itself without how to upgrade everything for instance if a new version of dapper comes out I can continue use my old version or it can upgrade to a new version if I have a problem with a new version I can roll back to the old version we take these packages for granted but while almost every developer uses nougat packages relatively few ever create new get packages part that comes from not thinking about code reusability beyond a given project the larger part of it comes from not knowing how to create nougat packages today we're gonna address that second issue and at least touch on the first one now NuGet packages have become so easy to create we'll actually spend more time on deploying managing and hosting our package anyone actually creating it but before we dive in I do not mention that I have a special offer this month on patreon anyone who is a current patreon member at the $10 a month level or higher by the end of July so either you are not yet you can either upgrade your package or you can you know sign up now so by the end of July by the end of July you'll receive an exclusive pdf I've created just for you one of the struggles developers sometimes have is knowing what type of sample application to create so I've put together 15 great ideas these aren't throwaway application ideas either these 15 ideas can be real applications you can actually use as an even bigger bonus we're getting really close to the first big milestone on patreon once a few more people come on board I apologise eanes mini-documentary on how I create Monday videos I'll give you a tour of my office I'll look at how I play a video what testing I do before I start and more along with the actual video creation that video will be exclusive to patreon members at any level now finally I'm going to write a Christmas and July sale soon they'll be exclusive for my mailing list members so if you aren't on the mailing list now is the time of join the link is in the description ok let's get started we're gonna start by creating a new project and we're gonna do a dotnet standard class library now there's a couple reasons for this the the best are the biggest reason why you want to create a a dotnet standard library is because dotnet standard can target a number of different platforms if you notice here Android iOS Linux Mac Windows these are all different platforms that a dotnet standard library can target the other thing here is with the dotnet standard comes at a much easier way of creating nougat packages and we'll talk about the alternatives because if you have a dotnet framework library it's gonna be a few more steps I won't cover those steps today but we'll talk them a little bit so let's create our dotnet standard library let's call this the helper library and I call this the nougat demo solution so know your demo and it'll create this and once we do we're going to delete that class one that it creates by default let's delete that and yes you wanted to delete that permanently and now let's right click on helper library good properties this is one of those things you don't have to do if you don't want but I'm going to do it because I want the names Patil but a little bit different so I'm gonna say the default namespace is I am Tim Corrie helpers okay which means that every class from now on will get that I am Tim Cory taught helpers as the namespace or the starter namespace let's create a folder in here it will call this calculations we can close out of this we can right click here and this is all just demo code we're not gonna do anything really in-depth here so I say calculator let me get public this is my pretty standard I need create class library just to demo something calculation so public static double add double X double Y and we can just do the simple return X plus y and let's do one more public static double subtract double X double Y return X minus y ok so now we have these two super helpful methods 1 adds two numbers together the other subtracts one number from the other ok so that's that's gonna be the foundation of our library now we'll add probably another thing or two to this but that's the foundation of our library now if we want to share this this library with another project there's a few different ways we can go about it one way is to compile this get the dll and then import that into another project another way is actually put a project in this solution remember that this solution is just a a bucket essentially that that holds more than one solute or one more than project potentially so that they don't normally have a relationship but if you add a reference then you can create that relationship which essentially what it does is it brings a DLL from our library and puts it into another project that has a reference to this library so those things you can do but there are limitations to this the the limitations are that either you are manually taking care that dll or you're bringing in the project into the solution and either way you don't have the idea of rollback so what happens if you make a change in this library and it negatively impacts your front-end library your friend project let's just say we introduced a bug or we changed how subtract works so now it takes in three variables instead of two well now the front end has to change but maybe you don't want the friend to change maybe you want to use the old version not the new version with the different subtract method well we could Korea second subtract method and do an overload and have the old code and the new code but the problem is that's a legacy nightmare if you want to go forward and do things differently then do them differently don't do in the old way and the new way and then try and support both it's hard to do so the idea of this legacy support or the idea of having versions different versions being used by different applications can be important also if we are bring this dll everywhere and let's just say we have five different projects that use this dll and we make a change because a bug in the code maybe we had the divide method and we had divided by your zero error well what we do well we'd have to build this library and then take the dll to all five projects and then override the current DLL then open the prize up rique pile them and then redeploy them and that's a little tricky especially if you don't remember which pride is relied on it so nougat solves a lot of these problems or at least makes things easier first of all with versioning a new gift we were a click on dependencies can go to manage nougat packages let's just look at well here's the dotnet standard library that we're using for our library that's a nougat package and notice the version now I can't go back because it's blocked by project but I could otherwise select a different version now if I wanted to install a new package let's say Newton soft at JSON I can say yeah 12.0 dot two is cool but I actually want for point 0.3 and you can install that version and that allows you to go backwards compatible or move back in time if you have a dependency on an older version or if the newer version doesn't support the platform you're on and so there's a lot of power here and if for example Microsoft came out with a version 2.0 point for that being this list we can upgrade it now there's a couple more things about mentioned before we get into actually using our code and there is a little bit of a half a do before I get there so the first thing to talk about is the idea of these names these names are actually reserved meaning when you create a name for your new get package that then can't be used by somebody else okay so it's it kind of kind of a domain name once you have it nobody else can use it on that hosting platform so this right here comes from nougat itself the public repository and if we look here at scene it says nougat or maybe small but new gorg so I'm new Georg I can't create a net standard dot library package they'll say no no you don't own that that's somebody else so your name is kind of important because once you choose that name you also can't then decide I'm gonna change that name we will break everybody's package so you would have then two different packages instead of one package with a new name the other thing to note is where you publish your package this is on nougat org which is a public site which means everyone has access to your code to download it that doesn't mean you can't charge your code if we look here in the Browse we could actually find and they're not usually at the top we can find items where there's a paid version as well as a free version or there's a trial version that's a media package so there are ways of going about that however in this video what we're gonna do is we're gonna take our our library and we're going to publish it to a private repository the idea here is we're working at a company or even just personally and we have code that's proprietary to us it's not open source and we don't want to give it to everybody but we want to have nougat packages just for us internally and so that's what we're gonna do today now to create a public nougat package on new georg not much different okay but this way we can demonstrate how to keep our code to ourselves - or just our company or just our colleagues okay so that's the plan now we're gonna publish it first manually and then we'll create an automated way to publish or semi-automated through ash or DevOps alright so let's get started the first thing you need to do is set up a new get package feed add send this package - once we create the package to do that let's go over to my ashore DevOps site okay as your DevOps which I've already created I have an azure DevOps organization and in here I have just four different projects now if you don't have one yet you know Visual Studio calm and there's a sign up there for free for as your DevOps once he creates your DevOps account you can log into it and then if you don't have a project yet create a project doesn't have to be anything significant because what we're going to do is use as your artifacts and that's free and it's across all of our projects so it doesn't even matter which of these I click on because it will use the same back-end let's do docker tools and we go to artifacts now this is our art of or as a DevOps artifacts and this is where we can store our packages now there's a lot of cool benefits to storing your own packages one of the benefits is it can even cache the public packages that you use let's say you use dapper I'm a big fan of damper so I used a per all the time well I can cache it here in artifacts the benefits to that are a couple first of all if nougat org goes down I still have access to dapper for my projects I can still do builds also if the tool the team behind dapper decides you know what we're gonna pull it out of the marketplace that would be kind of devastating now it shouldn't happen and it should be that even if the aside we're not gonna manage anymore it still stays in the marketplace but let's just say they're gonna pull it out I still have a copy I can use for my projects that keeps me going until I can create a replacement for dapper that I can then upgrade to but the most important thing here is I can host my own private packages so that's we're gonna do today so let's create a new feed in the feed name I call this demo feed and the reason why is a couple reasons first of all this is for just a demo but the other thing is that once you publish a package to a feed like I said you've reserved that name and that name will stay in your feet so whenever going to create a demo NuGet package and publish it to a feed I'm gonna use a demo feed like this because that way at the end I can delete the feed and all those package reservations go away as well so just note that's what I'm doing for myself personally I will have my own full feed that I use just for real projects this is the demo feed now visibility people in Tim quarry which is kind of an odd way of saying that it's my organization name is Tim quarry so members of the same organization can use my packages I can also lock it down just specific people if I wanted to I'm going to say everyone that has access to my a DevOps account has access to this feed and that's the default also notice use packages from public sources through his feed that's that caching I talked about where it's going to save the copy of dapper that I use and then I can pull from this feed instead of from nougat org let's create this and now I have my feet that was really simple to connect to my feet I have to do a couple of things first here is my package source URL this is what we'll use in Visual Studio to say this is demo feed I copy that now the next thing is we have to download new get plus credential provider what this allows us to do is manually publish packages up to our nougat feed we'll get to that in just a minute but I've already download that so we're ready but you can download that package and and stret extract it to some folder on your machine just make sure it's a folder you want to keep around for a while now this isn't something you have to do if you're not gonna manually push packages and once we do the manual push I'm going to show you an easier way of doing it that will bypass the need for everything from here on down okay so just note you don't have to do this this is just for purely manual pushes okay so I've copied this link here and come back to visual studio and there's a couple different ways of getting to this if you're already in the manage new get packages there's a gear icon right here at settings and it takes you right here the other option is in tools options and then again nougat package manager package sources I'm gonna create a new source I call this demo feed and paste in that URL and hit update and I will move that to the top okay now when I right-click on my dependencies and say manage nougat packages when I go browse under nougat org here's all these packages but if I do the pull down and say demo feed they'll be no packages here because they haven't pushed any packages to my demo feed yet so that's the next step we're going to do is actually push a package to this demo feet now also notice you can say all and then what we'll do is it will pull from all these different sources and including your feed so you can actually search across everything okay we've kind of done almost set up we've talked about how you know to set up a or a artifact site and all the rest but how he actually create a new get package well it used to be with dotnet framework that you'd have to create this whole configuration file and it was quite a quite complicated or at least a number of extra steps that weren't necessarily documented in the most easy-to-use fashion however now it's a lot easier right click on your dotnet standard library got properties got a package generate new get package on build we can say require the License Agreement or not we're not gonna require a license agreement for a license it's a let's skip down here I'm going to say that I want them to use the MIT license which is pretty much a permissive do whatever you want with this license the package ID must say I am Tim quarry dot helper this is it's like a namespace and so you want to name this something that is intuitive and easy to understand and the convention is not to use dashes or underscores but instead to use dots and no spaces so in this case I am Tim quarry is my base namespace name for this and then dot helper library so that the next time when I bring in my data access library I would say I am Tim quarry dot data access library now a package version this is one of those that's going to as you get further into nougat is going to be something you have to think through how to do well and that's the versioning now for this demo I'm going to use the simplest technique because that's the one you're going to start off with most likely and that is I'm gonna manually update the every time I push a new version out there however down the road you may want to have some sort of automation system to help you with these versions right now we have major version minor version and patch version in semantic versioning which is a pretty popular way of numbering things we would never have a gap in our versioning meaning 1.0.1 we don't go then to 1.0 0.3 we always go to 1.0 0.2 or one point 1.0 or 2.0 point out now there's tools to help you with this including a tool called git version which will do some automation here it will look at your commits and help you figure out how you want to do this but for now again we're just gonna do it manually author Tim quarry company it fills it in automatically as Tim quarry I could change it I wanted to but I won't and this we're gonna call this the this is called this the Tim Cory's helper library this is kind of a title it will be displayed if you don't have a product name that's going to display this package ID as a product name description these are all optional things down here so we don't have to fill in everything I'm going to fill in a few things just to show off that where we'll show up and how it will show up so this is my description of my helper library copyright let's just put 2019 I have the license already now if you want to look into what licenses are optional or available you can do that there's a whole list and I'll include a link down the description to a list of where you can find out more information about ever every field here and how to fill it in product URL I don't have one for this demo project so I'm just gonna put my www I am Tim quarry dot-com icon URL if you have an icon for this package other than you don't want to use a standard one you would put the URL in here and that URL should lead just to an icon not the page where the icon is located the actual icon URL I don't have one we'll leave it blank singer repository URL and type tags they're pretty important this is how you help people find your package so this would be and the its space delimited so every time you put a space that's a separate tag so I'd say I am Tim quarry is a tag so you can find you know my packages and then we'll say that calculations and let's do one last one of helpers release notes this is the initial release and we'll leave the rest the same notice the assembly version and the file version are all 1.0 0.0 0.0 if I were to change this package version to 1.0 point one and then I click off it notice it's gonna change the assembly version and assembly file version to match now of course rest start off with 1.0 0.0 I hit save and now if I were to right-click on my project and say pack it's going to build that file for us I right-click again and say open folder and file explorer and I go to my bin folder debug and there is the the package file okay so I am Tim Coryell / library 1.0 0.0 dot n u PK g that by itself has everything inside you need for your nougat package in fact if we were to change the extension here to dot zip and then open this up notice it opens up as a zip file that's all it is now inside here we have our new spec file which is all those properties we have set up that's in there notice the Lib SN or 2.0 and that helper library DLL and then in the package it has anything that relies on which doesn't rely on anything right now so there's all the information which is pretty simple it's there's not much to it that's only information we need about our helper library let's rename is back and now we have our this is what we're going to use in our new kit package library so we need to upload this to our our repository for packages our our artifacts location so this is what we're going to use this second and third line so first we have to add the feed to nougat now I have already download the the nougat + credentialed writer that's the nougaty XC and the credential provider VSS exe i've downloaded those to my c colon slash temp folder now the one thing I haven't done is put them on the the path which is so I can't just go to PowerShell and say nougat because it doesn't know where to look for nougat ixc so I'm gonna do I'm gonna open up PowerShell and it's quite basically shrink it down here so I can't just say nougat Exe hey I can't do you know why because I actually put it into my system 32 as well the problem with that is that when I did that it is in the path so I take care of it but this credential provider dot VSS exe won't run in system32 it crashes on me so that's a problem so let's do this it's clear screen I am going to run this directly so I might get a full path to my XE the first we want to do is I want to get the location where this package is so now I copy this link and I'm going to move it off a screen and I'm going to change the directory to be that directory which is quite long but that's the directory where my my new get package is next I'm gonna do I'm gonna copy this right here and I'm gonna paste it in a notepad and notepads my friend I use notepad a lot and this allows me to then change anything I need to now in this one I don't need to change anything because it's just setting up demo feed as a source and that's putting the actual URL in for demo fee so that's not a problem so I can just paste this in directly and run it and I've been added I already had that in a new nougat so next I need to push this package so let's copy this and again paste it into notepad but this time notice the API key is just as your dev ops that's you can use any key you want there but that's the one that it defaulted to so that's not a problem but this my underscore package dot and u PKG is a problem that's not the right name so let's copy this name and paste that in place and now that's our actual path but nuga AFC works off of my windows / system32 which is a problem so I can just say C colon slash temp slash nuga XE to point to the correct nougat which shouldn't be a problem for you but you still might have to point to the correct nougat so there we go so the reason I did it this way is because I didn't want to have to say push and the this right here happy preceded by all of this so instead I just put C slash temp slash nougat IX e instead and now this will work at the with a write exe and it will still be relative to this folder so that it when we say just this package file it's going to look in this folder for it okay so it's gonna push that file up to demo feet we hit enter and it gives me there and that's because I have been doing this demo beforehand to make sure I got it all correctly and I left that source on there so if I were to do AC slash temp you shouldn't have to do this but I want to show it on screen so that when you do if your first ml you don't have to run the same problem go okay whether Tim do and not know so new get exe I want to say sources and let's let's shrink us down a little bit so you can actually see the command sources and I want to remove and the name is demo feed and that didn't work so let's find out why so new get oops C colon slash temp slash nougat exe sources list and so we have three sources we have nougat org we have Microsoft's offline packages and we have demo feed that's the only want to use but notice it's demo space feed okay so the issue wasn't that I had an old version here though use from testing the issue was I named it something slightly different in Visual Studio so if we go up to this command right here it should be that our source is new as demo space feed let's try that there we go now it's pushing it up now for mine it hasn't prompted me for credentials and the reason why is because I've already put my credentials in for you it will do the first time it will pop up a box and it's the Microsoft's authentication system use the same credentials that you used for your ads or DevOps right here and you should be good to go so now that I've pushed that if I hit refresh here I have one package I am Tim quarry dot helper library so that package if we click on it we can see all the information about it including the home page the license how people have downloaded it and the publisher more information about it the description the release notes for this particular release everything we need to know for this package so let's do this let's go to visual studio let me create a new version of Visual Studio and this time I'm going to create a new project and let's do a console application so let's say console for some reason it's filtering I'm not sure why so let's say all product types all platforms and all Lang well not all language is just c-sharp so a filter doesn't have a clear filter somewhere which it should but now I'm searching for just c-sharp but all platforms all projects and I get the console app and dotnet core version let's do that one let's call this our console let's call it console UI and new gidge demo console our new get demo new demo UI how about that or app there we go mamie's hard new get demo app and we'll create this I want to be totally separate they want to just really show the fact that this is nothing that there's no connection here between the two projects so now if I go to have references by right-clicking on dependencies and saying manage NuGet packages and I select demo feed I'm gonna browse there's one package I am Tim Corita helper library I can install this and once I install it now I can come over here to my project library and I can add a using statement using I am Tim quarry dot helpers with that that can make calls to that helper library so I could say I am Tim quarry - helpers dot but they re put they use it - it there I can say calculations oh there we go I am Tim Court interesting that wouldn't let me use they use into it let's find out why in a minute ah calculator the controlled dot there to add the user to it calculator dot add ok so I put the wrong I put one level too shallow on so calculator to add I just pass in five and two and actually let's control access and do a console.writeline and say the sum of 5 and 2 is and do that calculation and make sure this in fact runs let's run this and that's really smallest let's fix that let's change the font to be something much more readable still small there we go so the sum of 5 and 2 is 7 so we have a valid calculation based upon our nougat package okay I'm gonna hit enter here and close this out so now we have an application that's using our new get package now let's go back to our other project for a minute we're going to look at this nougat calculation there's one more thing I want to do let's right-click on a helper library and let's add a new item let's get a text file search for text text file and we're gonna call this readme.txt now sometimes with your package you want to have some type of initial help because for example it was kind of tricky and know what the namespace was to use calculator so you might want to add that so this is my readme file well this file is gonna do is this is going to open up when we want us to open up when the user installs our package so let's create a really simple really file to use this library add a using statement for I am I am too Corie dot helper library dot calculations and then call let's and then call calculate or dot and or calculator dot subtract really basic stuff here but venice gives us a sample readme file now you want this to pop up whenever anybody installs our package however that's not gonna do it by default we have to actually make a change to do that single click on your project file notice it opens up in this new editor it used to be that if we want to modify our CS proj file we actually had to unload the project and then edit it well now we can edit without having to unload the project so it's single click opens up our project CS proj file after property group create an item group inside here on create content and rest say include breed me dot txt and we're going to say pack inside here is true notice that pack didn't show up in the intellisense that's okay and package path is a backslash okay so that's very important i missed that if you do not pay attention that backslash right there is between the package path tags so pack is true and then package path is the backslash we save that and we can say reload all and that's going to reload that file of course it's gonna error on me even though it worked before let's find out what the what the problem is so let's edit that file and for some reason I have a double quote at the end of content not sure why that's there XML files in Visual Studio have never worked quite right there's always been some kind of weird issue the biggest one is if you're in c-sharp and you type double quotes at the end here it's gonna just move your cursor beyond the double quotes in XML it's going to put another double quotes and cause problems that's probably what happened as I probably just you know without thinking about it I put another double quotes let's close it out and let's reload the project there we go life is good again and we're all set so let's right-click on our project and go to properties and change this version now to 1.0 point 1 - I hope you add as that readme file but now let's do a pack and now we can go over we can go back to our powershell let's clear this window and do the exact same push only this time we're gonna push the 1.0 point 1 version now I know that's there because I just packed it but I could go and look to make sure it's there but it is there let's run this and it's gonna push this version now once this is done we can go to our other project our nougat demo app we can go to dependencies right click manage NuGet packages and now notice updates has one after it because we're on version 1.0 2.0 but we can't upgrade to the latest stable version of 1.0 point 1 let's do that it's updated and now notice readme.txt has opened and there's my readme so we've just changed versions and we've got that new rimi dot txt now note Rema dot txt is not over here on the right in my solution it's missing so where is it well if you hover over the tab it gives you the path and that path is to the actual helper library into the packages so that's where the readme is located it's actually with the package so we can close out of this and once we do it's going to gone we can't like get it back without going into the packages itself and finding it but that way we can help our users out when it comes to starting up with using our package so that's all there is to Korean nougat package but we're not done yet because this manual process is a little bit clutch so let's create an automated process let's go back to as your dev ops and I'm gonna create a new project let's call this nougat demo and really leave everything else as it is and hit create or create a new repository for this for this project so inside our repo let's add a readme and create get ignore file for visual studio and say initialize and then we're going to click the clone button to grab that URL to clone it now let's do this let's write inside my temp folder right click and say git bash here and then inside get bash I'm gonna say git clone I'm going to do my leaves shift insert yep to paste that in and hit enter and I said clone my repository which is pretty much empty there's not much to it it's just the git ignore file and the readme let's go over and find our new get package so let's go our we get package here go right click at my solution open folder and file explorer and claw close this out and then I'm going to grab these two files I'm gonna copy them and I'm gonna paste them into my new repository folder which essentially I just did was I just add this to source control I had an existing application I'm now putting in the source control let's open up this solution and once I do once it loads then we can add all of this to source control so let's select everything whereas stage at all and just say initial code commit let's stage that and they'll go a sink and we'll push this out that way we have everything on our repository okay so if we refresh this we should see that we have our solution file and all of our project files in our repository now note that when I made my copy I didn't just copy a solution file this is a common misconception this solution file is just a file it says here's where all the projects are located on your hard drive it doesn't have any code in it you can't just copy a solution file and expect it to work anywhere else the real application although you know that the meat and potatoes of your application is inside of folders and here we have our CS proj file which again is not enough we also need our CS files that's that's where the actual code look lives but if you want give it to somebody else or if you want to add it to a repository you have to select a solution file and every other folder in there that is related to a project okay select all of those and then you can put it into your repository or if you want to email to somebody you need all of those so now you have a code in our repository we can go to pipelines and go to builds and let's create a build and we're gonna not do a yeah mole build the Emma builds can be kind of tricky instead I want to use a classic editor down here and I say nougat demo repository and team project from the master branch and let's do a build and let's just say that this is a what said dotnet if it's dotnet desktop but we're gonna write dotnet desktop or it's gonna worry about the fact that it's a dotnet build hit apply it's gonna use a version new get 4.4.1 which we can make some change of this we're going to because we want to actually use a different version of nougat or actually a different feed in fact we're gonna use this feed demo feed right here for a restore not just the standard restore B's otherwise you look in nougat org we want to look in demo fee because that's where we had our packages from now in this case doesn't matter because we'll actually have any dependencies but in the case that we did where we had dependencies on other products in our private repository or privates artifacts location this is what we need to do okay so we don't have to do this because the fact we're not having any restore is being done but we're going to anyways now it's gonna build the solution but let's get rid of the testing let's get rid of symbols and let's get rid of copy files and instead we're going to add one more task and that is gonna be a nougat task so the nougat task and this nougat attachment move right after the build solution but instead of restore it's going to be a pack okay so it's going to look for a CS proj file to pack and it's going to build it and put the artifact stating directory let's go to our triggers here and say write enable continuous integration and let's add this for all branches that's where the star means press save as and queue it which means it will create a new build for us let's change it to 2019 and we're good to go and now it's going to queue up and run we click on this will watch it connect and we'll watch it start to build our project this might take a couple of seconds to get started but it should be fairly quick once we start using an especially since we don't have a whole lot that it has to do there's not going to be any restores that need to do and there's not much code to compile so once we start using this actually pretty quick to do but really your build process unless you do a ton of it you don't have to worry too much about the speed of it because the fact that it's not something you do all the time it's something you do a few times a day ok now once the organization yes build process becomes important but with that build process being important then you can invest more money in making sure you have better speed all right so we have an error on the new get pack step so it's saying it's unable to cast to the new get got framework version so let's find out what this means ok so it says that we're unable to cast a because kind of small I understand but we're unable to cast the object of type system dot string to type new get frameworks nougat framework dot and the version number I think the issue here based upon a little bit of research is actually in our build itself we go back to edit this if we look at our new get version we have version 4.4.1 there's a newer version of new get out and we'll make sure we get the latest version if we click on list of available versions there's actually five point one point oh sorry it's a little small there we go five point one point Oh out so let's actually move to that version instead so four point nine point one is what I've heard works let's go to five point one point oh and let's look at this version as well so this right here is task version we were on version zero version one is the latest version and CEO only is a latest version your task when you're creating something but once you start using it you see careful not to upgrade your tasks unless you check to make sure it's not going to break your build so this one under advanced it has a new get version and it's enabled I'm not quite sure what's changed in the nougat tool installer so I'm not sure why one point I was better than zero point O or point star but we're gonna use it latest version and now we have five point one point oh let's save and Q is again and see if that makes a difference in our build it should so the problem was that it didn't understand about dotnet core and so when I tried to to build it had a problem and since dotnet standard supports dotnet core that was kind of the issue at least that's my understanding of what the issue was okay so now we're using the correct version of nuclear at the latest version of nougat we just did a restore which doesn't really need to do anything because there's no package to restore but it will at least have on the machine we're doing the build on it'll have the latest version of nougat the build a solution it's should be done pretty quickly like I said there's only one thing to compile one class not a lot of code a lot of work it has to do okay the pack is now running and it did succeed and so now we have a successful build they have to go to the artifacts go a drop inside this drop folder we can see that nu p kg that's the one point 0.1 so now we can go to release and create a release for this build or for any build now with our builds its it's called continuous integration meaning when every push code up it's going to integrate our code by building it and creating that package file however we're not going to release automatically we're not gonna have continuous delivery and the reason why is because otherwise we'd have partially completed packages being released we don't want that you want packages to be released in a controlled manner only certain builds get pushed as releases so it was manually let's create release and we're going to say we could use a template but I don't believe they have one for nougat there's no new get template because new it's really simple to do so let's start an empty job and I call this release to production like so I'll close this out we need to add an artifact so the artifact is a build and since you've already done a build we can select a build and it will understand what that is so we selected our our build from a pipeline and hit add now if you want to make this automated we could click the lightning bolt for can continuous deployment okay but we're not gonna do that instead we're going to do it manually now under click on the one job zero tasks link and in here we're going to do our our nougat package first we're on change the the agent pulled a Windows 2019 with vs to a nineteen I like to have the latest version that's all there really is to that now let's hit add on our agent job or sa nougat right hit add all right click on it and our options here are restore pack or push we're into a push the target feed is going demo feed and we're gonna check this box to allow duplicates to be skipped what this is gonna do is we already have a one point 0.1 version which we do and we try and do a new push a one point 0.1 package it's gonna say just skip it and say that we completed successfully versus erroring out and saying we had a failure that way if we accidentally try and push something then it'll stop us essentially now if you want that error maybe you you want to have that feedback that that no this didn't actually get pushed then you want uncheck that box note you cannot overwrite a version so if you already have a one point 0.1 but it's got bug in it you can't just say let's overwrite that with a new version called one point one point one that doesn't work you'd have to come out with a 1.0 0.2 you can retire one point 0.1 so people can't get it but you cannot overwrite it okay so now it's gonna do a push and let's just call this production release and if we got Vance options we have for paucity of detailed and we can say this enabled or disabled and if you want to continue on error so you want to have that error so uncheck that box but continue on error okay you can do that as well let's save this and now we have our release so let's do this let's go back to our our new get demo and we're gonna make a change here I'm gonna add a new public static double multiply double X double Y and return x times y so now we have a new version so I'm going to right click on my project got properties package and change this to version 1.0 0.2 it's a minor change I hit save I don't have to do PAC instead I go to my changes in my team Explorer and whoops not branches changes and I'm going to select these two things right here and stage the reason we have a CS proj file is because that version changed solo did they compare we can see the version from 1.0 point 1 to 1.0 0.2 that's the change right that both of those and now we can say add multiply option now the user can multiply values or a commit stage and sync that's going to push it up to the repository and once that's done we can come back over to our as your DevOps and go builds and notice this new builds of an add add multiply option and that is cued up once this is done and it's it's started already once this is done we're going to go to our release window and create a new release but first we have to make sure this goes all the way through the build process I'm gonna do is I'm gonna pause the video just because I don't want you to waste your time not much time but I don't wanna waste your time if you don't have to all right so that's complete it took 1 minute 13 seconds I can go to release and create a release so create a new release and we're going to use the artifact which is version 3 with the third build so you leave all that alone and say create and this will queue up a new release all right so it's been queued we can click on this link and hey they've as new things to release page we can look at that later notice the in progress so let's go to in progress and watch as it connects to the age and hopefully pushes our new get package up so it's already download and/or it pushed and it got one warning no packages match a search pattern so that's a problem so let's find out why let's go back up to edit and go back over here to our push and ah here's why we didn't change our path let's click on this and look at our build our drop and it's click on the package itself and that will change the the path exactly the right name but notice it's it's now 1.0 0.2 that's not great because we don't want to publish only the 1.0 0.2 version so let's hit star just go look for any nu PKG file in the drop folder let's save that and now let's go back and queue it again so we can go to production release create a release and hit create and now I can click on this and look at what's happening in our release we click on queue and send connect to an agent once it connects then we'll be able to watch and see if this one succeeds or not now we we checked that box that said ignore any errors and it assumed that it worked anyways so it gave us a warning so it's kind of important to watch those warnings now if we uncheck that box and say go ahead and fail then it will it'll tell us hey this was a failed job now let's say that push I successfully let's go over to our our package artifacts and look at hey helper library I changed the default namespace it looks like so now we have helper library version 1.0 0.2 whoops but notice now you have two different versions so we have the helper library and I am Tim quarry - helper library and that's why you don't want to do it two different ways but now we do that have that we can come over to our demo app and we can't update because we have two different packages there's no update here we got a browse this is one you want so let's install this one and it's gonna get some errors that's okay let's let's install this one and now we have our correct installation now if we run this it should still run but let's first copy this and say the and I forget it's not some afraid the multiple you know the well I hate forget the wording it's been a while since I've in math class so many the comments let me know five times two is instead of add we're going to do multiply and now if we run this we get five times two is ten so we're good to go okay so with that all being set up now we have our new nougat package that's in a build process and our release is just a matter of going to this site going to our pipeline releases and saying create a new release there's no more going the command-line and learn the commands and in all that we just had to say click the blue button it says create release and hit OK and it will Korea release for us and push it out to nougat now the one thing I didn't do here that I did do my builds is you noticed the edit the first we have here is the use nougat version and that was essential to making sure we have the right version of nougat we reason Laius version and we don't have that in our release so let's do that just to be sure we have the latest version so let's go ahead and hit edit and under jobs we're gonna hit add and rests a nougat nougat tool installer move that to the top and make sure that we have the latest version so it's gonna get the latest version for us but the version we know that is available in five point one point oh let's save this and now just for giggles let's go ahead and change our our version here so let's right-click and go to properties and change the version to 0.3 and say never changes and commit this just a version change so is it that this is the pattern you would do once you decide had got some code I wanna change you would change the version either before or after I would do it after you make the change that way you're still on the old version it won't publish the new package but then once you change the version then it will publish new package when you hit that publish okay now in this case I gotta change any code I has changed the version and that was it and now we go to our our builds it's running a new build okay and I'm gonna do is when I pause this and come back to it once we're ready for a release okay so ready for release so we go that releases and they create a release and hit create so I have to do once we do that it's going to create release - three and it's going to this up again I'll pause this until this is done okay we're all done now we can go back to our artifacts and if we look we now have a new version here so we have helper library version 1.3 if we look at versions we have 1.3 which is currently selected but also 1.2 so we now have the different versions of our library going back so this is how we can use Azure DevOps to help us deploy and store our artifacts makes it a lot simpler to do that than running the command line options now if you just want to deploy a new version your package you don't want to have your stuff in source control and you don't want to have to set up a pipeline what you can do is create some easy batch scripts for yourself just to do those uploads in a more automated fashion but still just in a computer so either way is possible whether it's the manual upload or the automated upload that we're doing here either way you can use this artifacts now as your your personal feed that can pull both your your private packages as well as archive or cache your other packages that you use from new georg okay so that's how to get started creating your own nuget packages now why would you ever use a new get package why would you ever do this well as you can see it's very easy to put your own code in and then use it in different projects that allows you to have code sharing across projects I always encourage new developers to start early but wherever you're at your development process create your own libraries you do code over and over and over again if you watched my videos you've seen me create dapper code quite often if I use dapper a lot whenever I have to access data especially from sequel Saturday I'm sorry a sequel server I used a per so I have some special code that I use that makes life a little easier now my videos I just retype it and put in a class library in my personal projects I don't do that because that's just a waste of my time and whenever I tweak something that's I don't want to have to then go to every single project and put that tweak in my code there so instead I create nougat package for myself now I encourage you to do the same that way you can always have your different versions and you don't have to upgrade versions but if you create some cool code somewhere and say oh you know that this is an improvement to dapper in this area and you go to a different project you can just get that new version and now you have that code from the other product you're working on it makes your projects faster and faster and faster so I definitely encourage you if you haven't already start creating your own class libraries and put them in nougat that way you can have this reusable code base that makes you faster and more efficient we're developing okay so that's nougat kind of a nutshell it's an intro we didn't go into things like dotnet framework NuGet packages which are a little harder and the idea of how to version things that can be a little bit tricky at times like I said and as well as maintenance seing this nougat feat taking old packages offline that can be tricky as well so for example if I say you know what actually I want to get rid of this version entirely I can say delete latest which doesn't do a whole lot I can go in here and I can say well let's unlist this that's great it's unlisted but now it's still here it's still available it's just it's not in the list anymore so I can't really delete it entirely because there are dependencies on this package so it we still reserved that so that's something to think through your naming conventions important to get right from beginning or at least get close to right you'll never be perfect but get close to right so get that and then figure out what your versioning strategy is going to be you know and if it's major changes are breaking changes then make sure you figure out a system that indicates that to the user so if I go from version 1.0 to 2.0 that's probably breaking change and follow that pattern okay so if I go from 1.0 point 1 to 1.0 0.2 that should not be a breaking change if it is that's probably at least a minor if not a major change okay so think through those things but to just get started this video should give you everything you need to start playing around let's start trying and don't be afraid to fail try it use it and then over time you'll get better okay so it for nougat thanks for watching and as always I am Tim quarry [Music] you
Info
Channel: IAmTimCorey
Views: 46,577
Rating: 4.8951726 out of 5
Keywords: creating nuget packages, create nuget package visual studio 2019, create nuget package from dll, create nuget package, create nuget package tutorial, nuget, c#, c# nuget package tutorial, c# nuget command line, c# nuget package, .net standard, c# .net standard, vs2019, tim corey, iamtimcorey, nuget tutorial, azure devops, azure devops artifacts, azure devops artifacts nuget, azure devops artifacts feed, continuous integration
Id: AF1y9gLcxjQ
Channel Id: undefined
Length: 74min 57sec (4497 seconds)
Published: Mon Jul 15 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.