C# 4.0 – Ch:02:D – Projects & Solutions

Posted 4 years 41 days ago ago by Tanuja     
  • Currently 0.00/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

If you like this article, please click on +1 button and share with your friends.

...continued from article "C# 4.0 – Ch:02:C – Hello C# World Up-Close : Continued

In our previous article, we finished with the dissection of the code in Program.cs file.  But, that does not mean that we looked at everything. Visual Studio just did not create the template code for us in the file Program.cs, but it did a lot of work for us.


Take a look at the above image of the “Solution Explorer”. If you have not changed any of the default settings in your Visual Studio, you will probably find the “Solution Explorer” at the top-right corner of your Visual Studio. If you don’t find it there, there is no need to worry about, just go to the View menu and select Solution Explorer.

It’s almost impossible for us to write a program containing all of its source code in one file in .NET. If you take a look at the Solution Explorer, you will see not just the Program.cs file but you can find four more items. If you follow the files in the Solution Explorer, at the top of the tree, you will find a Solution file, next item is the Project file, which is followed by two folders namely Properties and References in order.

Once a project is compiled, Visual Studio creates a couple of more folders called bin and obj.

Note: Sometimes the Solution file does not appear in your Solution Explorer. In order to see it, go-to Tools –> Options and from the dialogue window that appears, in the tree-view select Project and Solutions and select the option “Always show solution” by selecting the checkbox next to it.

The folders bin and obj also does not appear in the Solution Explorer by default. You can view them by browsing the folder where your project is saved, or by clicking on the second icon in the Solution Explorer.

  • Project : A project is a collection of all the source code files & resources that the C# compiler will combine to produce a single output, typically an executable (.exe) or a library (.dll).
  • Solution : A solution is the set of all the projects that make up a particular software package (application).

The solution is described by a file with the extension .sln and in our example, it is named Demo1.sln. The project is described by various other files in the project’s main folder. You can open these files using a Notepad. These files plain text files and in accordance with the principle that .NET and .NET tools rely on open standards wherever possible, they are mostly in XML format.

Note: If you are developing a huge project, you might not wish to put all your code in one single file. You can split your code into multiple files. For better management of the application you might want to further group them into UI related code and business logic separately. You can have all these UI related source code files in one project, say Windows Forms (.exe) while you can have the business logic related source code files in another project, say a library (.dll).

By having both of these projects into one solution, you can work with the exe and the dll as though you were working with one single project or one file all at once.

By the way, Visual Studio always requires a solution—even if you’re building just one project, it is always contained in a solution. That’s why the project’s contents are shown in a panel called the Solution Explorer.

Check out the image below, where in all the folders are expanded and you can see it all the files in the solution with the Program.cs file we have been examining at the bottom.


Under the Properties folder, you can see the file AssemblyInfo.cs. This file is generated automatically by Visual Studio, when you create a project using a template. AssemblyInfo.cs is used for configuration of the assembly manifest. The compiler reads the assembly attributes to inject the specific information into the manifest. If you open the file, you will find the configuration information about the Assembly. Below is contents of the AssemblyInfo.cs file from the Demo1 project.

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Demo1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Demo1")]
[assembly: AssemblyCopyright("Copyright ©  2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("37b99ff5-155a-4ad2-826d-84146378b911")]
// Version information for an assembly consists of the following four values:
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("")]
[assembly: AssemblyFileVersion("")]

The attributes that are prefixed with the word assembly: marks an assembly level attribute. In contrast to other attributes, all Assembly level attributes are not attached to any specific language element. The arguments that can be used for the assembly attribute are classes of the namespaces System.Reflection , System.Runtime.CompilerServices , and System.Runtime.InteropServices .

Visual Studio provides an interface titled “Assembly Information”, to configure these assembly level attributes. You can access it from the menu Project –> [Project Name] Properties and from the Project properties window Select  Application settings tab and then “Assembly Information” to open the interface. You can see the interface in the image below:


I will be covering the AssemblyInfo.cs in depth later on in the series.

In the next article, I will continue with the “References” folder.

…. continued in next article “C# 4.0 – Ch:02:E – Projects & Solutions : Continued

If you like this article, please click on +1 button and share with your friends.


Leave Your Comments