DevOps for ASP.NET Developers: Hosting NuGet Packages

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
take control of your dependencies wrestle them together and publish them out with ease using nothing more than hosted nuget packages learn how on on.net [Music] [Applause] hello and welcome to another episode of on.net i'm here with abel wang abel how's it going hey jeremy great to see you again man good to see you we're going to talk about hosting nuget packages yeah it's super super important right because um a lot of times when i talk to our customers they ask me questions like oh we have a team we have this shared library how are we supposed to manage like the dlls right because i if i change the source code it's going to affect them and the answer to that ultimately is by using nuget packages and the idea is you have a central location where you store your packages and what's cool is now you get to version it basically versions up your dlls right versions of your libraries so then when i create my solution or when i create my project i can say you know what use this library this specific library and also this specific version and it'll go ahead download it and then it'll you know i'll compile and and use that library so this is super cool can then if if another team that owns that library creates a new version of that library but they introduce breaking changes to the api well the version number increases my code won't break because i'm still pointing to the right version and when i'm ready i can go ahead and upgrade go up to the next version and make my code changes right so this gives us a nice controlled way of dealing with libraries so it sounds like i'm used to nuget obviously built into visual studio there's a standard place where you would get your nuget packages when we release products we release them there and it's nice because there's a set of dependency rules and version rules etc but what you're talking about is in addition to that sort of i guess we would call it official repo there's also a way that you can host your own packages internally you don't have to put them out there in the public to take advantage of nuget yeah so nuget's freaking awesome right with with the public new gets feeds and stuff but there are times when you want your feeds to be private like these could be internal libraries in an enterprise well you just don't want to throw them into like the public new get feed right so the way that you can handle this is you can actually spin up your own private instance of a new get feed and you can do this inside of azure devops for instance or even inside of github as well so awesome so i don't even know how to get started with that how do we spin up our own nuget host all right let me go ahead and show you let me share my screen with you really quickly so what you're looking at is of course visual studio right and we're all detonate developers so we understand this really well to make sure that you create a new get package this is easy enough if we right click on the project let's go to properties if we click on packaging well guess what if i click on generate new get package on build every time i build this solution it's going to go ahead and create that nuget package for me so i can fill this form out right give it an id give it a version number so on and so forth so literally that's all i need to do and now when i build my solution it will go ahead and create that nuget package for me of course i can also right click and instead of build i can say pack and that will go ahead and create for me that new get package as well so a couple different ways we can do that and of course there's going to be people that love the command line as well so from the command line you can net pack and hooray for that you can create your new packages as well but as you know i'm kind of a devops guy right so i want it to be all this done in an automated pipeline so let me show you how you can do that awesome all right so let me bring up azure devops services and you notice one of the things that it has let me go ahead and scroll all the way down is the artifact repository so this artifact repository you can basically create whatever feeds you need and now you're creating private nuget feeds that only people that can log into azure devops will be able to see so i created a feed called my test feed and as you can see is just completely empty right okay connect to the speed let's go ahead and click on it let's say we want to connect with uh nuget.exe it will give you exactly how you need to configure everything right if you want to use the the.net cli well it shows you how to do that as well if you use visual studio so on and so forth now inside of azure devops services the artifact repository it doesn't just do nuget it also does npm maven gradle pip twine and also universal packages which is my favorite because it's basically just you can package up any directory and be like okay that's gonna be my package so okay super powerful now to use this is super simple so let's go ahead and jump to our pipeline and what i'm going to go ahead and do is let's kick off a build so here's my build let's go ahead and run this pipeline and what is this pipeline doing right so while this is building let's go ahead and take a look at this so if we look at this pipeline and i'm doing everything using the visual editor usually i use yaml yaml is awesome but it doesn't demo very well right a big wall of yaml is it doesn't demo well so i use the visual editor this time but i'm a huge fan of yaml this is my build it's doing nothing special right restore from nuget build my solution from visual studio and if you look at this you can see that i'm not doing anything special with my build i'm just saying build build i run unit test haha i didn't write any unit test for my little library and then i published my symbols back up right all right so that's all it does it's just build my application so if we look at that build and of course it's still building so let's look at one that's already done you can see here is my artifact repo well this is the the build artifacts and what do i have i have my dlls and so here's the dlls that it creates and it created for me my new get package because remember you just build the solution one of your build artifacts is going to be this nuget package so if this build is successful it kicks off my release pipeline so here's my release pipeline and i made this really simple it's just basically one job and what does it do all it does is i used the nuget push task if you need to find it let's go ahead and search for nuget and oh yeah here's my nuget task so that's all i'm using and i'm doing a nuget push let's take a look at the properties here i have a path to my nuget package and i'm using one of the feeds for this particular solution and i pick my test feed and yeah dude that's it that's all i do so now let's go ahead and jump into our pipeline and see what's going on it looks like we've built successfully to our releases we can see that now it's kicking off the release so let's jump into the release live and see exactly what it's doing so now of course it's waiting in a queue it's kicked it off and remember it's really this release really isn't doing a whole lot right all it's going to do is it's just going to go ahead and push my packages up to nuget so while it's doing this any questions does that make sense that makes sense so if i understand correctly we basically had uh three steps right you had the step to enable the pack on build so that becomes the build artifact you had this step to go into your artifacts and say hey i want to have a nuget feed that's exposed internally through azure devops and then the last step was you added a task to push that artifact into the feed yep that's it it is literally that simple so here's something interesting we had a big fat error right why is it uh because i chose the wrong feed but but you build it you push it and you push it directly into into the feed and pray for that it's done and remember the feed is just a nuget feed which means all of your other projects can connect up to it the exact same way simple simple to do so question uh yeah i was gonna ask this is great for azure devops but what if i'm maybe not using azure devops what if i'm just using github github actions or maybe some other infrastructure is it possible to host nuget anywhere else absolutely so you can host new get in a variety of places right new get packages one of the places where you can create private feeds is also github so check this out in your github account right so i'm able squid head if you look you have a section called packages that right there is a package repository right right there's it can hold nuget packages it can call maven packages so on and so forth so this is really cool as well and to use it it's dirt simple let's go ahead and check out so here is this exact same project right this project really isn't a whole lot i just have one add method uh yeah i know that's pretty lame but let's go ahead and do one thing right so this is my cs proj file so there's a couple things that you have to have right first of all you have to say that this is a library let's say the version is one dot oh let's go ahead and edit this let's change the version number to 1.0.3 i'm the author of course you can give it a description but this part here is something that you have to have so you need to give it your repository url and the type of repository it is so this is just my repository right able squid head slash package hosting demo and this is a git repo so you need this in your cs proj so let's go ahead and check that in and i have a github action that builds my my application as well and publishes the package to nuget so let me show you how that's done uh we'll jump into the actions and you can see it's kicked it off and if we drill in here we'll be able to see it running live right so what is this really doing let's go look at how i configured my action sure so if we jump into the actions more yaml more yaml uh there is no visual editor right so it's going to be a wall of yaml but luckily the schema for github actions is pretty clean and it's pretty easy to understand and so this section here i basically check out my code i set up my.net and i build my application and run my unit tests right so that's going to create the dlls that i need the next thing that i do is i set up my.net core so that it's pointing to my correct nuget package so since i'm pulling the new get i'm sorry the new get repository so the repository that i'm pushing to is going to be in github so which is why it says nuget.pkg.github.comablesquidhead.index.json right so that's going to be your source url and of course it's secured so i do need to pass in my token my github token yep uh the next thing that i do is i run the.net pack command which is going to create for me that nuget package um all of this is debug nonsense that usually i would take out but it you know i'd have to debug the the uh github action equivalent of console writeline all over the place 100 that's exactly good and then so in theory after i run this call right after i run the pack that's going to go ahead and create for me my new get package and then if i do a net new get push and i point it to the nuget package well that's going to push my new new get package into the repo right so let's see if this actually works and it knows where to push it because you have it defined in the cs proj file so exactly so everything all right for that that's all is good so if we look here we can see that it ran everything right including it generated the package and it pushed it up to our registry all right so if we go back to our package registry and let's refresh this from a two now it's 1.0.3 dot so granted this was a dirt simple demo but that's kind of my point i wanted to show people how easy it is to create a nuget package but more importantly how easy it is to actually host your own private nuget package and then rub some devops on it and make it all devopsey and just automate the whole thing in your pipeline and you can use a tool like a sim version or whatever to automatically iterate the versioning so you don't have to manually go in and and tune the dial although sometimes people want to do that right and manually create releases and i guess the the other thing that is important for people to understand if they're not familiar with nuget is the the whole versioning principles i love the way that you have a convention for specifying the version so you can say i need this exact version or anything above this version is fine or this major version so a lot of flexibility to manage your project dependencies yeah this is this is super powerful and again like you know the best case scenario for this is if you're working on you know multiple teams are sharing a library and they all have access to that source code right you can't just have people come in there and willy-nilly start changing the library because it's shared but if you store them and version them as nuget packages everyone that consumes it can specify exactly which version they're consuming and then upgrade on their own time sounds great well there you have it if you want to manage complex dependencies or even simple dependencies we had a application that just adds two numbers this is how you set up host your feed and consume your feed too so thanks for that abel absolutely thanks jeremy [Music] you
Info
Channel: dotNET
Views: 4,328
Rating: undefined out of 5
Keywords: .NET, dotnet, devops, dev ops, Azure, Azure DevOps, CI/CD, nuget, github, pipelines, packages, hosting, publishing, coding, software, development, asp.net, aspnetcore, asp.net core, applications, Microsoft, Windows
Id: 8zWcH6DwDKQ
Channel Id: undefined
Length: 14min 55sec (895 seconds)
Published: Thu Jan 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.