20
|
Chapter 1, Master Projects and Solutions
#4 Hack the Project and Solution Files
HACK
By using Enterprise Templates, you can also take advantage of some prefab-
ricated projects called building blocks that are located under the Enterprise
Template Project folder in the New Project dialog. An architect could create
a number of Enterprise Templates to dictate how solutions should be built
and organized inside his organization. Instead of starting from scratch,
developers would use the template to dictate their general architecture.
HACK
#4
Hack the Project and Solution Files Hack #4
Discover the format of these two Visual Studio files and learn about a tool to
convert these files between versions of Visual Studio.
Solution and project files are an essential part of working with Visual Stu-
dio. You will almost always work with the solution and project files through
the IDE, whether adding projects to your solution or configuring your
project. The purpose of this hack is to describe the format of these files for
two reasons. If your project or solution files become corrupted, knowing the
structure of these files might help you fix the file without having to re-create
the entire project or solution. Also, knowing the structure of these files will
help you if you want to convert these files or write a tool that works directly
with these files.
You must edit these files with extreme care. The format of
these files is not published or documented and could change
drastically in future versions. You should normally need to
work with these files only through the IDE, and unless you
find a compelling reason to, I would not directly edit these
files. If you are interested only in converting the version of
these files, then you may want to look toward the end of this
hack under “Project and Solution File Conversion” to read
about a tool that will do the conversion for you.
Solution Files
Visual Studio creates two separate files when you create a new solution in
Visual Studio. The first file is the .suo (solution user options) file, which
stores user settings such as the location of your breakpoints. This file is
stored in binary format, which does not lend itself to easy editing. Since
there are no compelling reasons to edit this file, I am not going to document
the format of it here. If you think that this file is preventing your solution
from opening, you can actually delete the file and Visual Studio will create a
new one when you open the solution and save it when you close the IDE. By
deleting the file, you will lose any of your user-specific settings like break-
points, but this is a small price to pay for saving your solution. The .suo file
Hack the Project and Solution Files #4
Chapter 1, Master Projects and Solutions
|
21
HACK
is a hidden file, so you will need to make sure Windows Explorer is config-
ured to show hidden files (this can be set through Tools
Folder Options
View in any Explorer window).
The second file that Visual Studio creates is the .sln file. This file stores
information about the projects that make up this solution, source control
settings, and other global settings that apply to all of the projects in the solu-
tion.
The first line of the solution file contains a declaration including the version
of Visual Studio that this solution is built for:
Microsoft Visual Studio Solution File, Format Version 8.0
The version number used in the solution file is a little different than the ver-
sion number you are used to seeing in the Visual Studio product name.
Visual Studio .NET 2002 solution files have a version number of 7.0. Visual
Studio .NET 2003 solution files have a version number of 8.0 (as opposed to
the 7.1 number you are used to), and Visual Studio 2005 solutions files have
a version number of 9.0. Visual Studio 2005 Beta 1 contains an additional
line under this first line, which contains just the following:
# Visual Studio 2005
This line causes the icon of the file to be changed to a Visual Studio 2005-
specific icon, and if removed, will prevent Visual Studio from opening this
file when you double-click on it.
The next portion of the solution file contains a section for each of the
projects that are contained in this solution:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HacksWinApp",
"HacksWinApp\HacksWinApp.csproj",
"{75B7D1AE-1896-409D-B717-64D9AFCF0F59}"
ProjectSection(ProjectDependencies) = postProject
{89EE0E8E-C5C6-4772-A5EE-D347E40FB0E4} =
{89EE0E8E-C5C6-4772-A5EE-D347E40FB0E4}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HacksLib",
"HacksLib\HacksLib.csproj", "{89EE0E8E-C5C6-4772-A5EE-D347E40FB0E4}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
You can see that the syntax of the file is somewhat similar to Visual Basic.
Each project has a
Project and EndProject tag as well as a ProjectSection
tag to track the dependencies for the project. The first GUID in the project
tag is used to identify what type of project this is. In this instance, the
GUIDs for both a C# Windows Forms project and a C# library project are

Get Visual Studio Hacks now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.