The purpose of this article is to discuss and document the core set of files produced by Visual Studio Express when one creates a simple Windows application. If you have not already installed your free copy of Visual C# Express, and you want to follow along with this article, I would suggest that you download it and install it.
In the old days of programming people could write single file programs, compile them and run them, but such is no longer the case. There is a core set of files you get every time you create a project with C# Express and it is very useful to know what those files are and how they function together to produce a program.
Start with an Empty Windows Application
If you are following along with your own copy of Visual C#, you can create an empty Windows Application by clicking File | New Project and then clicking the "Windows Application" Icon. Name your project "SimpleWindow" and hit Ok.
Visual C# Express should create an empty Windows project with a single blank form. Save this project by clicking File | Save All.
If your installation of C# Express is the same as mine, it should have created 10 files and a directory hierarchy consisting of ten subdirectories. Let's examine those files and see what they do.
Solution Files
The highest level subdirectory should be named SimpleWindow, and it should contain two files -- SimpleWindow.sln and SimpleWindow.suo . In general you will not modify either of these files by hand. Descriptions follow:
SimpleWindow.sln is the topmost file used to create a program, it contains information about the structure of the entire solution such as the names of the projects contained in the solution and their locations.
SimpleWindow.suo is an entirely different animal, the Solution User Options file. It contains temporary information such debugging breakpoints and what files you have open. You can safely delete this file and it Visual C# Express will recreate it the next time you open the solution. The suo file is store in binary format and thus difficult to examine.
Project File
SimpleWindow.csproj is an XML file which contains instructions to the MSBuild Engine for how to build the SimpleWindow project. MSBuild is the (new in Visual Studio 2005) Microsoft tool used to build .NET applications. In general you will not modify this file directly; but if you want to do so, you can find complete documentation on Microsoft's MSDN web site.
Code Files
Although SimpleWindow is the minimal Windows program you can create using Visual C# Express, it creates six code files -- Form1.cs, Form1.Designer.cs, Program.cs, AssemblyInfo.cs, Resources.Designer.cs, and Settings.Designer.cs. Descriptions follow:
Program.cs is a very simple code file with a very important job. C# express expects that one and only one class in the SimpleWindow project will contain a "static void Main()", the main entry point to the SimpleWindow program. The "Main" routine contains only 3 active lines of code; and for purposes of this article its job is to create and run an instance of Form1. That's all. Program.cs is done.
Form1.cs and Form1.Designer.cs contain two pieces of Form1, the single automatically generated form in this project. At first it may seem odd to split Form1 into two files, but there is a good reason. Form1.cs is meant to be edited by hand; whereas Form1.Designer.cs is generated by the IDE visual design tools. For example, if you add a button control to Form1, the IDE automatically generates all the actual code to draw the button on Form1 and places it in the Form1.Designer.cs file. All forms generated by Visual C# Express are split this way.
Settings.Designer.cs The code in this file provides easy and direct access to the application and user settings for the program. Application and User settings are data generally having to do with the operation of your program which you might want to change on a per installation or per user basis; for example, a database connection string or the location of a directory the program uses. This data should persist after the program is done executing. This file is automatically generated by C# Express from information you add to the Settings.Settings file (discussed later in this article), so you should not edit it the C# code in this file directly.
Resource.Designer.cs This file is also generated automatically, from the XML Resources.resx file. It contains code to provide easy and direct access to resources such as images or waves.
AssemblyInfo.cs is a very interesting code file which C# Express has stuffed into the "Properties" directory of the SimpleWindow project. AssemblyInfo.cs has just what you would expect, information about the assembly (executable file) built by this project. The information is stored as a set of C# attributes. You can change the attribute values to change your assembly information using only the C# code editor. Furthermore, because the information is in a C# file it gets compiled into your program and thus is available to you, the programmer, to use at run time. This is a very nice way to do things, and I will devote a future article to the topic of how to access Assembly information. I recommend you examine the contents of this file.
Resources and Settings
I mentioned the Resource.Designer.cs and Settings.Designer.cs in the "Code Files" section of this article, but how are they created? The answer is they are both created visually using designer tools provided in the C# Express IDE, and they are stored in an XML Format. Descriptions follow.
Settings.settings is the XML file containing user and application settings which are defined in the Settings Designer visual tool. This file is compiled into the C# file Settings.Designer.cs by the SettingsSingleFileGenerator tool.
Resource.resx is the XML file containing resource information which is defined in the Managed Resources Editor visual tool. This file is compiled into the C# file Resource.Designer.cs by the ResXFileCodeGenerator tool.
Debug Support
SimpleWindow.vshost.exe is a "hosting process" file. The Hosting Process was introduced in Visual Studio 2005 to provide improved debugging support. It allows for such features as faster debug startup, partial trust debugging, and design time expression evaluation. These features will be discussed in more detail in a future article.
Summary
When you create a new solution/project in C# Express you get a lot of files. It is handy to know what those files are for, particularly if your project gets corrupted somehow. In this article we looked at the files that are created when you first create a simple Windows solution/project. My next article will examine files that are created when you do a complete build.