To create a new project, you use the New Project dialog box shown in figure 2-2. This dialog box lets you select the type of project you want to create by choosing one of several templates. To create a Windows Forms application, for example, you select the Windows Forms Application template. Among other things, this template includes references to all of the assemblies that contain the namespaces you’re most likely to use as you develop a Windows application.
Note that you can select a template from the Installed category as shown here. You can select a template from the Recent and Online categories. Or you can search for an installed template using the search text box in the upper right
corner of the dialog box.
The New Project dialog box also lets you specify the name for the project, and it lets you identify the folder in which it will be stored. By default, projects are stored in the Visual Studio 2015\Projects folder under the My Documents folder, but you can change that as shown in the previous figure.
If you want to change the location that’s shown in the New Project dialog box, you can click the Browse button to select a different location; display the Location drop-down list to select a location you’ve used recently; or type a path
directly. If you specify a path that doesn’t exist, Visual Studio will create the necessary folders for you.
When you click the OK button, Visual Studio automatically creates a new folder for the project using the project name you specify. In the dialog box in this figure, for example, InvoiceTotal is the project name and C:\C# 2015 is the location. By default, Visual Studio also creates a new folder for the solution using the same name as the project. As a result, Visual Studio will create one folder for the solution, and a subfolder for the project. Then, you can add another project to the same solution by selecting Add To Solution from the Solution drop-down list in the New Project dialog box. (This list is displayed only if a solution is open)
If a solution will contain a single project, though, you may want to store the project and solution in the same folder. To do that, you can deselect the Create Directory For Solution check box. Then, the solution is given the same name as the project. In the applications for this book, the project and solution files are typically stored in separate folders even though most solutions contain a single project.
Incidentally, the terms folder and directory are used as synonyms throughout this book. Although Microsoft started referring to directories as folders some time ago, most of the Visual Studio documentation still uses the term directory.
That’s why this book uses whichever term seems more appropriate at the time. By default, the new projects you create target .NET Framework 4.5.2, which is the version that came with one of the updates to Visual Studio 2013.
If you use any of the features that come with this framework, you should know that any computer that you want to run the application on must also have .NET Framework 4.5.2. If that’s not the case, you can change the target framework using the drop-down list at the top of the New Project dialog box. Then, only the features of the framework you choose will be available from Visual Studio.
How to create a new C# project
- Use the File->New->Project command to open the New Project dialog box.
- Choose Visual C# from the Installed->Templates category, and choose the Windows Forms Application template for a Windows Forms application.
- Enter a name for the project, which will enter the same name for the solution. Then, enter the location (folder) for the project (and solution).
- Click the OK button to create the new project.
- The project template that you select determines the initial files, assembly references, code, and property settings that are added to the project.
- If the Create Directory For Solution box is checked, Visual Studio creates a folder for the solution and a subfolder for the project. Otherwise, these files are stored in the same folder.
- If the Save New Projects When Created option is on as shown in the previous figure, the project is saved right after it’s created. Otherwise, the New Project dialog box asks only that you select a template and enter a name for the project.Then, when you save the project, the Save Project dialog box asks for the other information shown above.
- If you want to target a version of the .NET Framework other than version 4.5.2, you can select the version from the drop- down list at the top of the dialog box. .NET Framework 4.6 is the most recent version, and it’s the version that comes with Visual Studio 2015. You won’t typically need to use the features of this framework, though.
This article is an excerpt from Murach C# 2015 by Anne Boehm and Joel Murach
Reproduced with permission from Murach Publishing