Join Walt Ritscher for an in-depth discussion in this video Explore an empty project template, part of Visual Studio 2015 Essentials 07: Understanding Project Types.
- As you go through this course you'll learn about the various project categories and see some examples of the project templates. It's best if we start with a look at an empty project, so that you'll appreciate what benefits the complex templates bring to your development cycle. I'll be using the Solution Explorer and talking about the XML contents of the project files. If these topics are unfamiliar to you, no worries. I've created another course, shown here on the screen on our lynda.com site named Visual Studio 2015 Essentials number 03: Exploring Projects and Solutions.
This course spends 90 minuted delving into these topics. I'll start in Visual Studio by creating a new project. While I'm in the New Project dialog I can search for templates, I'll type in the word empty, Visual Studio filters down my list of available project types to the ones that are considered to be empty projects. The one I'm looking for here is this Empty Project with the language of Visual C#, but as you can see there are other empty projects with different language types.
I'll put my new project in my Exercise File folder on my Desktop, and I'll name it FirstEmptyProject. Look at Solution Explorer, there's not much there, there's a Solution that contains a single project, there is a single reference here inside this section, this Reference section, and there's one file, App.config. What I'll do next is look at the contents of the CS project file. This is an XML file. To look at the contents I'll right-click and choose Unload Project, then I'll right-click again and choose Edit.
Under normal circumstances you would rarely need to look at the XML content of this file, but examining its contents now will help me illustrate some key concepts. Let's review the purposes of the CS project file. It contains information that is consumed by Visual Studio and also by the Microsoft build engine. When you open the project file in Visual Studio it reads the contents of this file and uses the information within it to configure Visual Studio and to populate various tool windows in the IDE. When you build the project the build engine uses the contents of this file as build instructions.
So this file is vital. What you're seeing here is the minimum needed for a viable project. There's not much in this XML file, there's a section at the top that contains configuration information, there's that section that contains some debug instructions here, and then down here you see there's a single item in this ItemGroup named App.config, that represents the only file that is loaded by this project. Now I'll reload the csproj by closing this file, and right-clicking here and choosing Reload Project.
Next, since this is an empty project I have to start doing the work of building up the project. I need to add some class files, I need to put some methods in my code, I need to add some assets, maybe I need to make some changes here in the Properties section. Maybe I need to change the Assembly Name, the Default namespace, put extra Assembly Information in here about my Company, or the Title of this application.
So when I've filled out this information you'll see that Visual Studio added this second file, AssemblyInfo.cs. I'll add a Class file. I'll call it SimpleClass. And as you can see Visual Studio stubbed in a little bit of code for me, a little bit of information here. We'll talk more about that later. Next I'll add some image files and an empty folder.
Here's my new folder, I'll use this to store my class models. Like that. And then perhaps I'll have an Assets folder. Within this Assets folder I'll right-click and choose Add Existing Item, and I'll move up to my Desktop, and I'll open this Assets folder. Next I need to make sure I'm looking for all the files, so I'll click on this filter drop down and choose All Files. And then I'll look in the Images folder, and in the Travel folder, and pick one of these files.
I think I like this one. So that was placed inside my Assets folder. I'll also add a reference to another library, so I'll right-click on my References folder. There's a lot of (mumbling) assemblies. I'll filter down my list by typing here in the Search Assemblies. I'll look for the speech API. There it is. So I'll click on it once, then put a check mark here, then click on OK. Now as you can see there is three items now, I didn't explicitly add this System item, but Visual Studio did that when I added the System.Speech reference.
Now I'll save everything. And I'll go and show you the contents of this file. You'll see some differences. Here is a set for references. Now Visual Studio will put those in my Reference node and tell the build engine when I compile that I might need to add references to these DLLs. You can see that there's also a Content folder here. Notice that my image ended up inside the Assets folder, there's my empty Models folder, and here's my SimpleClass file that I added and there's also the one that was added by Visual Studio when I went to the Properties window.
Let's see if I can compile this. No I can't. So when I start creating an empty project I'm responsible for doing everything. One of the things you need to have in every .net project is you need to have a static method named Main, otherwise you can't compile. That means I need to pick one of my Classes in my project and put this method in there. Well, I only have one Class, so let's put it in SimpleClass. It has to have a capital M on it, C# is a case sensitive language.
That should do it. And it builds successfully. Let's talk about what we're seeing here. I've had to do a lot of work. Just to get started I had to add a Class, I had to add some references. The point is with an empty project you have to do all this work, add the files, add the references, add the assets, determine the location of the files, you have to do all this work just to get the project ready to start programming. To mitigate this Visual Studio supports custom project templates. Each template is configured with the items needed for that application category.