0.3.10 Navigating a Solution With Solution Explorer

Solution Explorer Is Your Map of the Project

A Visual Studio solution can contain many files.

Opening files by guessing from the Windows file system can make the project harder to understand.

Solution Explorer gives you a structured view of the solution, its projects, and their files.

You have already seen the hierarchy:

Solution → Project → Files

Now you will use that hierarchy to locate the source related to a particular programming task.

Start at the Solution

When a supplied course solution is open, Solution Explorer shows the solution at the top.

Beneath it are one or more projects.

A simplified example might look like:

Plain text
Solution 'SoccerTracker'
└── SoccerTracker
    ├── App.xaml
    ├── MainWindow.xaml
    ├── MainWindow.xaml.cs
    ├── Player.cs
    └── SoccerTracker.csproj

The actual course project may use different names.

Use the names in the supplied solution rather than renaming files to match an example.

Expand Only What You Need

Projects can contain many items.

Expand the project and locate the file named in the current directions.

If the task concerns a Player type, a file such as Player.cs may be relevant.

If the task concerns behavior associated with a WPF window, a related .xaml.cs file may be relevant.

Do not assume every file needs to be opened for every task.

The requirement should guide your navigation.

File Type Gives You a Clue

Common files include:

.cs

C# source code.

.xaml

WPF user-interface markup.

.xaml.cs

C# code associated with a XAML file.

.csproj

Project configuration.

.sln

Solution organization.

Recognizing the file type helps you avoid editing configuration or markup when the task actually calls for C# source.

Open the Existing File

Double-click the intended source file in Solution Explorer.

Visual Studio opens the file in the editor.

Read the surrounding code before making a change.

The line you need is part of a larger source file with a purpose and location.

Do not copy a small snippet into a new file simply because it is easier to see there.

Work in the supplied structure unless the course specifically directs you to add or move something.

Find the Relevant Part of a File

A source file can be longer than the few statements involved in the current task.

Use the structure of the code to orient yourself.

Look for:

If the file contains several sections, confirm that you are editing the correct one before changing code.

Solution Explorer and the Editor Work Together

Solution Explorer answers:

Where is the file?

The code editor answers:

What is inside the file?

Later IDE tools can answer other questions.

For example:

Knowing which tool answers which question keeps troubleshooting focused.

Preserve the Project Structure

A supplied solution may be used by:

Avoid:

Changes to project structure can create problems that are unrelated to the concept you are trying to learn.

Navigate From the Requirement

Suppose the requirement says:

Observe the code that decides whether a player appears in the available-player list.

A useful navigation process is:

  1. Open the supplied solution.
  2. Find the relevant project in Solution Explorer.
  3. Locate the file named by the course or specification.
  4. Open the file.
  5. Find the section associated with that behavior.
  6. Read the nearby statements before setting a breakpoint or making a change.

The requirement gives you the destination.

Solution Explorer helps you get there.

Keep the Map Available

As applications become larger, memorizing every file becomes less practical.

Use Solution Explorer as the project map.

The ability to locate relevant code in an existing solution is part of programming work—not an extra step that happens before the “real” programming begins.