ASP.NET Core
Microsoft Video Courses · 21 lecciones · Gratis en YouTube
Introduction to .NET Core
Sobre este curso
hi my name is Kevin Jones and this is the introduction to dotnet core class from winter lack now dotnet core is a new cross-platform version of.net from Microsoft so this version of.net runs on
Windows as you’d expect there’s also a version that runs on Linux other version that runs on Mac OSX in this class we’ll take a look at how we install and initially use dotnet core thought Mac
core comes with a set of command line tools and it’s also supported by Visual Studio so we’ll see both of these uses we’ll see how to use the command line tools both on Windows and on Linux and
we’ll see the visual studio support in action by building a project inside Visual Studio so in this class we’ll take a look at installation so how to install dotnet core again we’ll take a
look at how we install this on Windows we’ll take a look at how we install this on Linux and how we use the tools from Linux let’s take a look at those command line tools what they provide for us how
we use them and we build projects and how we run projects we’ll take a look at unit testing so how do I bring unit testing into my dotnet core project how do I include the appropriate packages to
use unit testing we’ll take a look at how we use this inside Visual Studio how to install it inside Visual Studio how Visual Studio can use net core projects and finally we’ll take a look at mixing
dotnet core with other dotnet projects so on the basis that you’re not starting from scratch that you don’t just build dotnet core projects but you have existing dotnet libraries out there how
do we use these together okay so let’s dive in the first thing we’re going to do is take a look at installation how do we install net cool so when you install dotnet core you get
a new set of command line tools which ever platform you install botnet caught onto so tooling for Windows tooling for max and tooling for Linux the installation for each platform is
slightly different so on Windows we install this as part of Visual Studio 2015 to do this we need to install bridges vo 2015 update 3 and then run this dotnet core one zero zero
tooling preview it’s a tooling preview that gives us a dotnet called command-line tooling that we need this obviously is at the time of recording and definitely going forward will get
release versions of these tools will come as part of Visual Studio for Linux the installation is like is slightly different for different versions of Linux and at the moment that are only
certain supported versions of Linux we’ll take a look at when to 16:04 hands and install.net caught on that to do this as you’ll see we need to set up the correct repository we then run apt-get
to get the packages and this gives us access then to the dotnet core tools okay so let’s go and see how we do this now for both platforms so to get instructions on how to install on the
various platforms you can go to Microsoft comm slash net slash core and then on here you’ll see you can click on Windows Linux Mac and there’s also a darker install and whichever of these
buttons you click on and get information on how to install dotnet caught on that platform I’m not going to run through installation on Windows here it’s not something you want to sit down and watch
me do if the amount running the Installer and watching an install the two parts list you have to make sure you have Visual Studio update 3 installed you can install that on any of the MSDN
releases a visual studio or on Community Edition the second part though is to install the tool in preview one thing to be aware of when you install the tool in preview my bad this happened to me each
time I’ve installed it is it will occasionally fail it will come up with this message saying setup failed please repair Visual Studio if you see that the way around it is to run the installation
with this skip and the school VSU and the score check equals one that would skip the update check and then go ahead and install the tools that you need once you install the tooling on Windows you
can then go to the command prompt and run got net what we see here is the output from running the dotnet tooling on windows if I run dotnet – – help then
we’ll get the help for this I’m going to take a look at this in more detail through the rest of this class so what I’m going to show in a little more detail is how to install dotnet core on
Linux and for this we’re going to use Ubuntu this is version 16.04 which is one of the supported versions of Linux there are other supported versions so Abunda 1404 there’s a Red
Hat Enterprise version some Debian versions for Dory’s so that I quite a lot of supported versions of Linux the.net core will run on so to install this on Linux we’ll do this through the
through the terminal application so in here we’re going to run some commands those commands and going to change at the package manager to point at the correct repository we need to add a key
so that trusts that repository and then once we have that we can then get apt to go and download dotnet core for us so three steps that we have to go through so the first command is this what this
command does essentially is that it adds a new package repository to the list of packages through buns who knows how to use and we do that by running the Deb commands using sudo hook here to be
running this as a super user one second of my password then it will add the name that repository to the locally he’ll list of repositories so when I use apt know it knows it can use this repository
to get some get some packages from once we have sent we has a town apt that it can trust this repository so we do that by hat by adding a key so it’s going to get the key
no trusted repository and then we need to tell apt to update the list of packages that it knows about so in this case we’re going to add to its into a list of packages the set of dotnet
packages that come from Microsoft you do a sudo apt-get which is the apt tool and then tell it to update itself so this could take a while it goes to a list of repositories it knows about and download
the package details from those repository including now with the.net repository once we have this we can now install net now at the moment when we’re installing
still a preview version of.net in the future this will just be a 1 0-0 release but currently we’re still on the preview here so we say to apt by using the apt-get tool go and install this package
for me so ask me though do I want to continue the operations I want to install these packages I’ll say yes so we download these packages creates the appropriate links for me within swith
inside Linux and this should now be ready to use so if I run net here then we get information about the dotnet build and again if I do net – – help we get the same help information that we
saw on on windows so it’s relatively straightforward to install these packages on Linux even if you are a complete newbie to Linux it’s not hard to install these not harder – to try
these out and to play with dotnet on Linux so now that we’ve seen how to install dotnet core we’ll take a look at the tooling and here we’ll take a look at the command-line tools and we’ll do
this on windows so dotnet core comes with a set of command line tools and these tools are used to both generate build and run applications the name of the tool that we use primarily is net we
can use this to create a project for us and then we can use this to compile and run that project code this generate a project or JSON file this is likely to change so since the latest release
candidates might Microsoft of announced that they’re moving back to the CS proj type projects rather than Jason type projects so using XML to hold the project structure this project file
contains project references and details of the application or library that we are building so for a demo we’re going to use the tooling to create a simple application and run the application just
to show how it works once you have that in place we then build a slightly more complex application where we’ll build both a lie very a dll and we’ll build an
application to actually use that library so let’s see how we do that now so we saw a few minutes ago but to run the dotnet tools from the command line we use the dotnet command
this comes up with some version information some simple health information and tells us that we can run dotnet help to get a bit more details so we do that we run dot that minus minus
help then this tells us that we can pass various arguments to this tool so at the bottom here we see that we can say dotnet new and that will initialize a basic.net project for us we see that we
can also do some other things like building the project running the project and also doing things like restoring dependencies when we see each of these commands as we go through this over the
next few minutes so I’m in a demos directory here and I’m going to create a new directory called character counter and change that directory and it’s in this directory that we will build a
project so we’ll start with a simple project and then we’ll show how we can build a multi-part project so a project that uses both a library and an application so to build the project
using dotnet core we simply do dotnet new and that creates a project for me and if I look in this directory you see that we have two things we have a program dot CS file we have a project
JSON file so before we go any further let’s take a look at that project or JSON file so I’ve opened a project of JSON file inside Visual Studio code and we can see here the section it contains
so it’s telling me that this is version 1 of the application is telling me that I have no dependencies it’s also telling me that I’m using the.net core framework here if I open the program CS file as
I’d expect it’s a very simple hello world application so it creates this this code for me he creates the namespace equal the program it adds public static void
main I mean this writes out hello world once we have that in place we can run the application but before we do that we have to run dotnet restore to restore any dependencies that this application
relies on so before we run dotnet restore let’s remind ourselves what’s in this directory so we have a program CS file a project ID JSON file so if I run dotnet restore now look in the directory
it chris another file called project lock jason and if i open this file in visual studio code we can see this contains a whole set of information about the dependencies this application
uses so when you run restore the tooling goes away looks at the dependencies of our project and then tracks all their dependencies and builds this dependency tree it also downloads any extra
packages that we need to use this is sort of like the packages of config file that we get in current node projects that tells us what packages this project depends on so if this file is the
equivalent of the project project level packages file where are the packages themselves of dotnet call stores these packages in a central location so it’s your home folder which will be used as
slash user names or kevin jones in my case slash NuGet slash packages and if i look in here we can see that there’s a whole set of directories that contain various dotnet libraries the allows
packages license information basically we’ve downloaded the packages that were in new get so local to a local cache for us to use them i can safely delete this packages folder and then if I run dotnet
restore again it’s now going to go away and recreate that folder for me and if I look back inside my nougat directory sure enough the package them out back so let’s try one one other
thing if I delete the packages folder so that’s now gone I’m going back to my application and I’m going to remove the character counter application the application is now being deleted if I
then recreate the application so from here now I’m going to run net new to create a new application so now this is as if I’m running dotnet for the first time there’s no packages
folder there’s no application and this is probably what you will see the first time you run dotnet from a command line after you’ve installed it at this point it says are you’re going to need these
packages so the first thing it does is goes away and recreates its packages folder for me so from now on every time I create a new dotnet application that packages folder exists and it’s
pre-populated with the dependencies that will typically need which part of our application ie all the dotnet dependencies from here I still need to run dotnet restore dotnet resource
stills creates that locked file form it’s a project lock Jason so don’t know restore but he looks at our project our JSON file and then from that works out the tree of dependencies
that this project needs if there’s anything in that tree that isn’t in the packages folder it will go away and download those packages as well and we’ll see that a little a little later
the lock font you don’t need to check in the source controls you should check in your project JSON file you track tracking needs CS files but you don’t need to
check in the lock file that’s easily recreated just by running dotnet restore so now that we have this application created we can do dotnet build that’s going to build the application for me
and if I look at the generated code for this so we have a bin folder debug folder got no collab folder inside here we don’t have an exe file we have a DLL so when I run the application this is
run by a dotnet core and don’t make all loads of DLL for me looks for the entry point and execute that entry point so very similar in the way Java works in Java we end up with dot class files that
we load and we look for an entry point core main so a similar thing here we haven’t dot the ll we load a file we look for entry point if it’s there then that application will run so I go back
to my command line I can do dotnet run that runs the application ensure and I who prints out hello world now I don’t need to do any separate steps I don’t need to build and
then run if I run and the application needs to be compiled again it will be recompiled for me and we can see that if I delete the bin and lobster Ector ease and then go back to my command line and
do net run compiler code runs it and sure enough we get hello world so this is obviously a very simple application it’s just hello world when we create more complex applications we have to
manage things like the layout of our code to where the things go on disk and there’s a structure that’s recommended that we use when we build dotnet core applications and that’s to have two
folders a source folder and attached folder closed source files in one location in the source folder and then put any test files that we have in the test folder and we’ll see the tests a
little later on in this class so what we’re now going to do is we’re going to make a slightly more complex application that has both a library and an executable so a Lebanon taxi so a Lib
and an application if you like and when we do that we want to put our code into the correct structure so the first thing I’m going to do is to create a source directory and then change into that and
then in here we’ll create through projects one that will be the EXCI one that will be the lid and one will depend on the on the other so from here I’m going to create two projects I’m going
to create a project called character counter Lib and that would be our library that will contain the helper code inside it I’m going to create another project called character count
that app in the Lib folder I’m going to again do a net new to create the project JSON file and the initial code we don’t we won’t need the programs ES file in here so we’ll delete that eventually and
then in the character counter app folder I’ll do the same thing so if I look in the source folder and look at character counter Lib sure enough we have a project JSON file I program CS I’m going
to delete CS file here we don’t need that if I go back into character counter app we have the same thing we have a project JSON file and a program CS file so this
course isn’t about how to write bank code so I’m not going to show you step-by-step how to write this code what I’m going to do is to bring the code in and then show how to amend the project
JSON files then show it a critic top level global JSON file that allows us to set up a multi project application so first things first let’s take a look at the project JSON files so this is the
one for the app and at the moment this will be exactly the same as the one for the for the library for the DLL notice in here it says omit entry point true so that says that it needs to emit into its
metadata the fact that this is Mac see that it has an entry point which will be main in this case if I open up the project JSON file for the Lib look inside here this also says emit entry
point true but this is not going to be an ACCI it’s just going to be a dll so we can get rid of that here now the other thing that we gotta have here is a dependency our application will depend
on the library so I need to add that dependency into the project JSON file let us do that we have to tell the project JSON file that we are adding a project dependency not a dll dependency
and that we depend on the project called character counter Lib so to do that in my dependency section add an entry called character counter Lib this is the key for my my dependency and inside here
we specify the target for the dependency the target is going to be that it’s a project dependency so we’re now saying that our application project depends on the Lib project so now that we have the
project files for these projects let’s take a look at what this application actually does so if I look at the library first of all what this code is going to do is something quite
straightforward it’s going to read a string that we passed to it and count the numbers of care in that string so numbers of a number of B number of C’s and so on and so forth
and pass back the information to the to the caller so we hold a dictionary that’s the character against the account for that character we turn the string into a char array and for every letter
that we have inside the phrase we just increment a counter we can pass back that dictionary so a user this application gets back a list of the characters and the number of characters
inside this string so a very very straightforward little little library and the application code that we have for this well basically let me do two things I can either pass with a file and
then I can pass that entire file off the character counter library or I can enter a phrase from the command line and I can pass that phrase off the character counter library and at the end of this
year we can see that the code create a new character counter so that’s the library code cause it’s passed string method and just prints out the count for each letter that’s in the data that
we’ve passed here so this is a multi project application and to let dotnet call know that we have to create a top-level JSON file called global JSON and that global dot JSON file lists all
the sub projects to make up this one large project so in my demos character counter folder I’m going to create a new file called called global Jason I’ll open that inside Visual Studio code and
inside here we are a JSON object that contains a project key and that key will reference an array and that array just contains the location of the project folders that we’re going to use so the
primer use of this is when we have multiple folders so when we have a source folder and a test folder so at the moment we only have a source folder so we leave it as it is for now when we
change the project to add tests to it a little later we’ll come back to this and we’ll add the tests folder to it so we’ve now created everything we need for this project back at the command line
here I’m in the top-level directory if I go into my source directory I’m going to carry the counter app say from here I can run dotnet restore and that will look at my project JSON file look at the
dependencies and set up my project lock JSON file I also need to do this for my Lib folder however if I go back to the root folder for the project the one that contains global da JSON and the source
folders and do net restore from here this will look in the source folder in there it will it will pass down through all the child folders find a project or JSON file in the lib folder find a
project or JSON file in the app folder and then generate the appropriate log files in those folders so the major benefit of having a global JSON file is the fact that I can run dotnet restore
at the top level I don’t need to run this for each sub project that I have I can just do the restore and create a log file in one single place now that I have the project structure set up and I have
the restore run and we have the dependencies all set and the app knows it depends on on the Lib I can go into the app directory and run the application so I can do net run the
first thing this will do is compile the application and then it will run the app and the app says enter a phrase so I can say something like this is a test I will output the count for me this one
a what a and so on and so forth if I look in the appropriate directories here – in character counter Lib look in the bin folder then we have the lid and the PDB if I go back to a character counter
app and look in its bin folder then we have the apps DLL and the PDB but we also copy across here the Lib DLL and PDB so that dependency been resolved we copy a crop across the
appropriate libraries that we need to use notice when I ran this I just did dotnet run and didn’t enter a command line parameter so it just asks for a phrase from the console we type
something in it does the count so I run this with a parameter so say dotnet run and then passage say program dot C S will reprogram CS as its input and in this case it doesn’t need to recompile
everything everything’s already compiled and again walks through program cierra outputs these count onto the screen so in this case you have 44 A’s and 61 E’s and so on and so forth so you can pass
command-line parameters into the applications by passing the parameter to the run command itself so what good is a project without tests so now that we have the code in place we’ll add some
tests obviously this is backwards we should be doing the test first the idea here is obviously to show you how to use dotnet core not best practices when it comes to dotnet development necessarily
so let’s get on to testing we are going to add unit testing to the project we do that by adding a unit test project as part of our main project so we create a separate test folder and into that test
folder we create another project and inside there we create the code that runs the tests and so this we’re going to use X unit as the as a test library so previously we created the character
count app application and inside here we have the source folder and then the app and Lib folders now what I want to do here is to go back and also create a test folder it’s inside that test folder
that will create a test project and inside there add the test that we’ll use to test the character count at Lib in this case so with the dotnet command-line tools we can get help at
the global level so we’ve seen that I can run dotnet minus minus help but we can also get help for each of the commands so if I do net new minus minus help then it tells you the options that
I can use in the dotnet new command and one of those options is – tea – tea lets you specify the type of project I want to build one of the types of projects we can build is a test project using X unit
as a test library so from here if I do dotnet new – t and then say X unit test then that will have created me a test project so if I look in the test folder that I created we have two things you
will project JSON file and a test CCS ronica a program that yes you could create a test CS that contains the outlines of the test project if I open in the test folder that project or JSON
file will see that in here it holds information about how we’re going to do the test as a dependency on dot neck test X unit it has a pressure honor which is the X unit test runner
and if I open up the test file we see that this is specifying that we have a classical test the next unit uses facts we have a fact that’s an attribute on the test one massive first task we will
run back at the command line if I run dotnet we store here on the test project this goes away and downloads all the dependencies we need for testing in particular if I
scroll back up through this list will see that X unit is now in that list so now that the project’s in place let’s go and write some tests so I’m going to change the name of this from just tests
to be character kinda tests I’m going to change the rate I’m going to change the name of my class to the name of the test that’s going to be Gantt can’t four-letter and then change name of the
test to specify what this test should do and that’s going to be should be to an account of one for the single letter to pass and then in the code create a new character counter call
pass string passing a single letter and assured that we get back account of one for the letter A now let me have the code in place you can do a dotnet build the bill fails and the reason the bill
fails of course is that we haven’t added the project reference to our project JSON file so let’s go back and do that now see if you remember we do this in the
dependencies so in here we say we want to dependency on character counter Lib and this dependency the target type for this is a project and if we now do a dot next restore and then a dot net build
the code builds okay and we can do a dotnet test and that will run the tests okay just as an aside I hate seeing test run succeed first times I’m never sure if the test is correct or not if my code
is correct or not I’d like to see test fail so to do that let’s change the assert here so let’s say I’m expecting the value to come back and this should fail so if I save the code go back build
it again and then run the test again sure enough now the test fails that proves to me that we are actually running the correct test I always like to see that so there’s one last thing to
do here we need to update our global JSON file so you remember this file look like this it says we have some projects in the source folder and now we need to add the test folder to this if I do that
and go back to my command prompt and go to the top-level directory this is where global duration lives from here I can now do a dotnet restore and that will run restore both on the source folder
project and on the test folder projects and that’s how we add tests into a dotnet core project so we’ve seen the command-line tools what about Visual Studio so to use this
current version of.net call inside Visual Studio you at least need to use update 3a Visual Studio you can download that from Microsoft and go and install it you know also I dealing to install
the command line tools as well as we saw earlier update three can open the Jason project file so understands the file format that is using we can use it to build and run the code and we can also
use it to run unit tests as well so everything that you’ve seen me do from the command line we can do it just as easily from inside Visual Studio so we’ll take a look now at how we do that
we’ll do that by opening up our project that we’ve been using and then build on our project inside Visual Studio so the first thing I want to do here to show you how to create a new project inside
Visual Studio so if I do file new project here in create a dotnet core project I’m going to create a class library project let’s just as this is just a temporary project I’ll create the
project in my temp directory and say ok so what this does is it creates the project for me I have a solution inside the situation notice we have a global JSON the file I can look at that and
inside here it’s telling me a project folders we go into ham so source and test and we have a project JSON file and we have a class a class file so class or not CS is just a standard Lokmat class
so then my project JSON file contains my project dependencies just like before and if I look in the temp cabin folder we can see we have the same structure so we have a global JSON file here it
secured to the dotnet solution file for me and then we have a source folder with the project JSON file inside here and then a my class file inside inside here as well notice we also have this X
project file here so the X project file is the dotnet core equivalent with CS project file at the moment Visual Studio uses both uses the JSON file to contain the dependencies and then the X PRIZE
file to contain the build information although it’s like it that in the future we’ll move back to using a CH approach file format rather than the ex project file format so once you’ve created this
project we can build it in the same way we’d build any other dotnet project and we could run it in the same way that we would run any other dotnet project except of course you rebuilt a DLL
rather than a console application so the code won’t run directly at the moment so what about the projects we’ve built previously the character counter Lib and the atom attached project and we can
import those in the dotnet I can go file new project and then create a visual studio solution and I’m going to put this in my character counter folder and we’ll call it character counter so once
we have that in place I’m going to add a couple of solution folders one called source on one called test and these are just here to mirror the folders that we have on the file system so we can
structure our visual studio solution in the same way that we structure the projects on the file system we’ve done that I think I can then add an existing project so I’m going to go to character
counter source Kitely counter lid and open up the project JSON file and we add that in and it just puts in the source folder opens up the to increase the project JSON file
for me to use so we just read this as as if it was any other visual studio project if I look on disk now and look at the lib folder we’ll see what Visual Studio is created an ex-pro project file
for me so in the same way that we did this by doing file new project by importing it equates the export file for me as well the other thing we could do if I go into least add project from
Visual Studio go back to the directory and delete the X proj files as well and then in visual studio to add existing project and go to the app project instead and open up each project JSON
file notice that Visual Studio is smart enough to look inside the app project recognize the fact that had a dependency between the Ataman lib will import both of those into my
solution in fact we do the same thing if I open up the test project file as well so we’ve recognizes attach project depends on the lib project and read both of those into the solution as well so
let’s go and add the test project now so we do add existing project go to the test directory find the project file showing up it brings in the test project as well so notice when I’ve done this
with the test project and getting some little sort of green squigglies here so there’s something not quite right it’s something not something that’s disastrous for those who probably come
up in red if I hover over this it tells me that the version of action has changed and probably updated you may have noticed this earlier when I was running these tool this tooling from the
command line and get warning me of a different version of action that was available so rather than running this RC 219 double to 0-8 build and I was it build one double O one five I can use so
if I pin the solution folder open open up the test project and change this to build one double O one five then save the solution file notice that it says restoring one package so it does a
package restore for me automatically and everything now goes green if at the underscore should have disappeared in the project JSON file as well if I reopen that then they’ve gone as well so
Visual Studio is trying to be helpful to us and trying to give us little warnings about things that we could fix inside the inside the project so I can also manage packages using new get so if I
right click and to manage NuGet packages and look at the anchor unity sends it up to date if I include pre-release here we see that both 4x units and the dotnet tastic X unit there are pre-release
versions so if I update each of these I get the usual new get dialogues and do the same for X units my code is now fully up-to-date to notice that my project JSON file has changed it’s now
showing me the 2.2 preview release of X units so the project reference information is held in the project JSON file at the moment okay so if I close that I can now
use this isn’t as a normal visual studio environment so I can do a build I can build a solution that’s going to build the add the Lib and the test projects for me if it needs to I can also run the
app in its identify the character counter app is the application so I can run this is actually to enter a phrase so again this is a test and getting the output from the front from the phrase we
can also pass the command line parameter to this so it seems as we did before so programmed at CES and if I save the project file this will be the X project file in this case and then run the code
again we get similar output so 44 A’s and 61 EE so the same as before so this is very very similar to the normal dotnet Visual Studio experience when we’re using dotnet core so one other
thing we can do is we can run tests so if I got a test explorer and do run or if it’s identify the tests that are part of the project when we doing run all it runs the test forming shows the test
passes and again just to prove that we are running the correct test if we change that value to two and save it and do run all again then the test now fails so it is running the correct tests so
one last thing I want to do here is to add another new guy package just to show that we can add other libraries into our dotnet libraries so if I go to my test project and to manage NuGet package
again I’m going to find the library called fluent assertions the fluid assertions lets me write my test assertions were so true in a slightly different way in was it in using what’s
called a fluent style so if I install this into my project notice as a restoring packages look in the project JSON file and it references the fluid surgeons assembly
and then in my test code rather than using its assert equal here I can now use a style something like this so I can say count again count letter dot should and this comes from fluent assertions
don’t be one so I’m now evil I’m not able to read my assertion code left to right so uses flu and style to do this I’m using language including the surgeons which is a standard dotnet
package I can use this in any of my dotnet projects and if I build the code everything builds okay go back to the test explorer and run all the tests again then the tests pass so everything
is green so we can include packages instead I would donate cool projects and make use of those so our last topic is mixing thought make call with other dotnet project types so we can do this
and we do this R inside Visual Studio so what we’ll do is we’ll create a new visual studio project and so that we land a dotnet core project and we’ll show that how that still works inside
Visual Studio is with the standard donate core project and how the tests will run and then we’ll add a dotnet console application and show that interacting with the.net core project we
show the changes we might need to make to the project files to get that to work so now that we have the project loaded the visual studio well I now want to take a look at is how
we can mix and match dotnet core projects and standard Visual Studio projects and to do that I’m going to start from scratch again so we’re going to create a bigger city
solution we can create a dotnet called library and that solution will reuse the code that we had previously but we’ll create a new project JSON file and then to that we have a dotnet console
application not a dotnet core console application so dotnet 4.6 console application so to do this we’ll do file new then we’ll quit a project and it’s going to be my visual studio solution
project and we’ll call this character counter and replace it in the character counter demos for then in here we’ll do what we did before so I’ll add a new solution folder called
source and then into here we’ll add a new project and this time we’re a dotnet core class library project and we’ll give it the same name so we’ll call it character counter Lib and we’ll make
sure it goes into the source folder here and this is going to be a dotnet core class library project so we say ok for that it restores the packages and everything is good to go so there’s the
project inside the source folder if I go to Explorer here we can see we have our character counter source character counter lib and then we have this class one CS file so I’ve saved a copy of the
old project hose and we have character counter Lib here I’m going to grab my CS file from there and copy it into this folder and I’m going to delete the class one CS file I notice when I was doing
that over in solution Explorer we’ve now it identifies that we have a current account of cs file here and not a class one C as well so this is different than the way Visual Studio
works with sort of standard dotnet project in a standard dotnet project we have a tell Visual Studio what files to include in the project the.net core project we tell it what files to exclude
from the project which default behavior is to include all the files in the project directory which is why here we see that we have the character count of CS file already installed into the
project I didn’t need to go in and know write clay can do show hidden files and that add the follow on I wanted to see in there it does all the marketing for me my opinion that’s a much better way
of doing things it’s much easier to include files in the putting the project that way so we have the Lib let’s go back in and bring the test project back over just to show that we can run tests
we clear from the command line against a project we created inside with Listeria so again we’ll do new solution folder and call this thing test go back out to the old
application and there was my test project and there is my test project and I’ll copy that across to here and then inside was a studio add existing project and we’ll add in our test project so the
project JSON file resource references and if I go to test Explorer and run the tests so identify the tests and sure enough the test tool runs so before we add in our console application and show
that running against the dotnet core library so I’ll show you one other thing and that’s the difference in the project JSON files between these two projects the three projects being the one that we
created on the command line earlier on the one that has been created by visual studio this is the project file from the command line and in here we can see we’ve got our versions and build options
no dependencies and the framework details here and the inputs we need to use the framework uses dotnet core app 100 and it might have gotten a core app if I look at the project JSON file the
visual studio bills it’s much much simpler so in here we have our version we have a dependency on what’s called a dotnet standard library and then the framework
is this dotnet standard one point six which importantly annex core to dotnet standard this is the new naming convention essentially for us for the standard dotnet libraries what we used
to be the core piece Els now called Ahmed standard so there’s information out on the web as to what it means by dotnet standard this up and this article here for example a witch land it and the
thing I wanted to show you here is if I scroll down as a table here which shows that the version of.net standard and which version of.net framework it corresponds to so we are
running on dotnet Sun of 1.6 so I go back to visual studio we can see dot next on Allegra 1.6 and I corresponds to dotnet core 1.0 and the next version of the dotnet framework then dot next I
want for correspond to botnet framework 4.6.1 for example so you’ll start to see more and more NuGet packages for example using dotnet standard and they depend
for the for the dependencies so we more or less back to where we were previously except that we don’t have a console application currently so what we can now do is go into here and do add new
project and while I’m good add now is a standard windows console application when we call this again character console app so to this I’m going to add a reference the reference I’m going to
end because we’re mixing and matching projects project types here so it has to be a DLL reference so I’m going to browse the library and add the reference from the library so if I browse to
character counter Lib then debug I put it into the stock next on a 1.6 library so it’s separate out separate the different versions of my dealers into the different standards that they
support so it puts the code in to stop net standard 1.6 library and there’s character counter lip so say ok and we now have a reference in our app to the lip so we’ve referenced the library
inside the app I’ve changed the app code so that we have exactly the same code as we have previously so this is my program dot C s file from the previous solution so again either takes a command line
command line parameter which is a file name or it lets me enter some data on the on the command line I’ve made the app the default project so I can just I can run the thing from it from inside
here so if I go to this and run the application the application fails and it fails to and a load version system at runtime 4.1 so why is that so if we go back to the Lib and look in Protege s’en
the framework this is using this donate the standard 1.6 if I look at my application then this is targeting net framework 4.6.1 previously we saw that table that showed
which versions of.net standard worked against which versions of the.net framework if I look at dotnet framework 4.6.1 that works with Nexon of 1.4 so back in
my project file I need to say is it’s not using dotnet sign of 1.6 it’s using dot next and of 1.4 so we need to make sure we change the visual studio project file to get this to work because I’m
waiting does have restore packages so what the pack is an out and out to date so once we’ve changed the version of.net standard and we build a code if we now run this again it still fails and of
course the reason this fails is that when we handed the reference to the application of the library which character count idli we ended it when he was being billed for net Sun at 1.6 and
we’re now building against on it’s done at 1.4 so we need to remove that reference and add the correct library so if I go to add reference and browse and go to the debug 1.4 folder and then add
the library and now run now the application works as expected so now we’re getting the correct output the application runs we’re building a dotnet 4.6.1 console
with a dot next a non 1.4 library and life is good so we’ve just seen the dotnet core is a cross-platform true set from Microsoft with the same tool set running across Windows OSX and various
flavors of Linux the tooling supports multi project applications so we can create more than one project within the application itself we can also create test projects the tooling support
creating those projects for us as well as running the tests we can load these projects into Visual Studio either one of the standard editions from MSDN or into the community edition as long as
you have the right update in place we’ve seen it we can mix dotnet core projects with other dotnet projects we mix a dotnet 4.6.1 console application with a dotnet core application
so that was an introduction to dotnet core thank you I hope you enjoyed the class
SIEMPRE HAY ALGO MÁS