Creating Your First Project3:50 with James Churchill
In this video, we'll use the .NET CLI on macOS to create our first console app project.
Let's create a project using the .NET CLI. 0:00 Here we are at a terminal prompt on macOS. 0:03 We can verify the .NET Core is installed by running the dotnet command. 0:06 This gives us some basic information about our .NET Core installation 0:11 including the version number. 0:14 To create a project, let's first create a new directory, and 0:16 then browse that directory. 0:20 From here, 0:24 we can run the dotnet new command to create a new console app project. 0:25 If we list the files in our directory, we can see that two files were created, 0:29 Program.cs and project.json. 0:33 We'll take a look at these files in just a moment. 0:36 Before we can run our app, we need to restore any dependencies our app might 0:39 have by running the dotnet restore command. 0:43 If we list the files again, we'll see that we now have a project.lock.json file. 0:47 This file, which needs to be present before we can run our app 0:53 represents the complete dependency graph for our app. 0:57 Now we can run our app using the dotnet run command. 1:01 And here's the output from our console app Hello World. 1:06 Let's review our project files in Visual Studio Code, 1:10 the cross-platform open source code editor from Microsoft. 1:13 I'll open our current directory and code by running the command code. 1:17 Notice that when I open the program .cs file, Code prompts me to install 1:23 the ms-vscode..csharp extension. 1:28 Out of the bo, Code doesn't provide any special support for editing C# files. 1:33 But by installing this extension, we'll have an editor experience 1:39 that's similar to what the full version of Visual Studio provides. 1:43 I'll click show recommendations to browse to the extensions panel, 1:46 then click Install on the extension to install it. 1:51 Once it's installed, we can click the Enable button to enable it. 1:55 We'll be prompted to restart Code. 2:00 And once it restarts, we'll now see syntax highlighting and 2:02 reference counting on our class and method. 2:06 Now that we have the C# extension installed and 2:10 enabled, Code recognizes that we're working on a .NET Core application. 2:13 And asks us if we'd like to add the required assets to build and 2:17 debug our project. 2:21 I'll go ahead and click on yes. 2:23 With all that out of the way, let's take a closer look at the Program.cs file. 2:25 Not much happening here, this is just a regular old console app. 2:30 We've got a class named Program and a public static method named Main 2:34 that writes to the console the string literal, Hello World. 2:40 Let's look at the project.json file. 2:44 The project.json file is being replaced with a CS project file. 2:46 So I'm not going to spend a lot of time explaining the parts of this file, but 2:52 I do want to highlight some things. 2:55 The dependencies property list the dependencies for our app. 2:58 Our app currently doesn't have any dependencies. 3:01 But that will change in just a moment when we convert our project to a web app. 3:04 Each dependency represents NuGet package 3:08 that needs to be restored before the app can be built and ran. 3:11 Dependencies typically have their own dependencies. 3:15 So this list doesn't represent the full list of NuGet packages that your app 3:18 depends upon, but rather just the top level dependencies. 3:22 The frameworks property list the frameworks that we're targeting. 3:27 In this case, netcoreapp1.0, which is .NET Core. 3:30 Overall the project.json file becomes more complicated when 3:35 working with ASP.NET Core and VC web app. 3:40 After the break, 3:43 we'll see what it takes to convert our console app project to a simple web app. 3:44
You need to sign up for Treehouse in order to download course files.Sign up