Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no...

38
Lecture Set 1 Part C: Understanding Visual Studio and .NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Transcript of Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no...

Page 1: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Lecture Set 1

Part C: Understanding Visual Studio and .NET – Applications,

Solutions, Projects(no longer used – embedded in Lecture

Set 2A)

Page 2: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 2

Objectives

Understand basic terminology – Visual Studio, .NET. Solutions, Projects, Applications, etc.

Learn how to create new Solutions, new Applications/Projects

General navigation around the Solution Explorer and Forms and applications windows in the Visual Studio IDE

Compiling and running programs

8/10/2008 6:34 PM

Page 3: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 3

Console Applications

Visual Studio supports the creation of a number of different types of Applications

Each different type of Application has a different structure and automatically provides support for different applications code

Types of Applications we will work with in this course Console Applications Windows Applications Web-based, Client-Server Applications

8/10/2008 6:34 PM

Page 4: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 4

Types of Applications

8/10/2008 6:34 PM

Page 5: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 5

The Console Class

Console is System class (it is in the System Namespace) – it is part of the mscorlib* library which as we have seen is one of the library DLLs that is automatically loaded with the execution of ALL VS applications.

This Console class supports a number of methods, including methods performing actions related to keyboard input (Read and ReadLine) and screen output (Write and WriteLine)

*mscorlib will briefly be discussed later8/10/2008 6:34 PM

Page 6: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 6

The Console Class (in the flesh)

Console Class Represents the standard input, output, and error streams for console applications. This class cannot be inherited.

Namespace: System Assembly: mscorlib (in mscorlib.dll)

Syntax Visual Basic (Declaration)

Public NotInheritable Class Console

Visual Basic (Usage) C#

public static class Console

. . .

XAML

Not applicable.

Remarks The console is an operating system window where users interact with the operating system or a text-based console application by entering text input through the computer keyboard, and reading text output from the computer terminal. For example, in Windows the console is called the command prompt window and accepts MS-DOS commands. The Console class provides basic support for applications that read characters from, and write characters to, the console.

Console I / O Streams

When a console application starts, the operating system automatically associates three I /O streams with the console. Your application can read user input from the standard input stream; write normal data to the standard output stream; and write error data to the standard error output stream. These streams are presented to your application as the values of the In, Out, and Error properties.

By default, the value of the I n property is a System.IO.TextReader object, and the values of the Out and Error properties are System.IO.TextWriter objects. However, you can set these properties to streams that do not represent the console; for example, you can set these properties to streams that represent files. I /O operations using these streams are synchronized, which means multiple threads can read from, or write to, the streams

8/10/2008 6:34 PM

Page 7: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 7

Comments re Console Applications

Recall that Visual Studio 2005 provides us with a convenient interface for applications development.

We now examine the VS 2005 interface for a Console Application. VS interfaces are different depending on the application you are writing.

The Console Application provides a Module for you to write code (a Windows App provides by default a Form for the insertion of tools).

You have a minimal set of referenced namespaces (classes from the FCL)

For example, there are no classes to support Forms or Drawing, etc because these are not relevant to console applications

8/10/2008 6:34 PM

Page 8: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 8

VS Interface for a Console Application

8/10/2008 6:34 PM

Page 9: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 9

Windows Applications

We now move on to examine (more thoroughly) Windows Applications

We begin with a look at the Visual Studio 2005 interface for a sample Windows Application. It is similar to the Console interface but not identical

Note the default list of References and the Form (as distinguished from what we saw in the Console interface)

To get full views of information )all files, etc. click on “Show All Files” (top of Solution Explorer window)

More solution information shows up after you do a Build

8/10/2008 6:34 PM

Page 10: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 10

VS 2005 Interface for Windows Application

8/10/2008 6:34 PM

Page 11: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 11

Solutions and Applications

Look again at the VS 2005 Interface for a Windows Application (one slide back)

What do we see? Applications? Solutions Projects Other “stuff”

Look at the files associated with solution

8/10/2008 6:34 PM

Page 12: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 12

Introduction to Visual Studio Solutions and Projects

A solution is a container for all your work on an application A solution contains several folders that

define an application’s structure Solution files have a file suffix of .sln

A solution contains one or more projects The project file is used to create an

executable application A project file has a suffix of .vbproj Project properties are set using the

project's property pages

Page 13: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 13

Project Property Page – Application tab

Page 14: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 14

Sample Show

Page 15: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 15

Solution with Two Projects

8/10/2008 6:34 PM

Page 16: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 16

What are these things?

Solution Each Application that you create is

organized by Visual Studio into a Solution The Solution file is the heart of an

Application’s structure – it is the container for all that you do

A Solution in turn consists of numerous files and folders, including one or more Projects

Multiple folders – look at slide 11 The is also a Solution File (.sln)

(not to be monkeyed with)

8/10/2008 6:34 PM

Page 17: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 17

A Visual Studio Solution

Visual Studio implements conceptual containers called solutions and projects to enable the integrated development environment (IDE) to apply its wide range of tools, designers, templates, and settings. Also, Visual Studio provides Solution Folders to organize related projects into groups and then perform actions on those groups of projects.

A project includes a set of source files, plus related metadata such as component references and build instructions. Projects generally produce one or more output files when built. A solution includes one or more projects, plus files and metadata that help define the solution as a whole:

8/10/2008 6:34 PM

Page 18: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 18

A Solution – As Seen in Your Files System

8/10/2008 6:34 PM

Page 19: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 19

Project Characteristics

Again, refer back to Slide 11 A project contains one or more

namespaces Every project has one root namespace But projects can have many other

Namespaces Every project has a type (Console, Windows, Web

etc.)

Each project gets compiled into an Assembly

Every project has an entry point A Sub procedure named Main or a form Forms apply only to Windows Application

projects

8/10/2008 6:34 PM

Page 20: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 20

A Project (continued)

Visual Studio

Projects as Containers

To help you to organize and perform common tasks on the items that you are developing, Visual Studio projects are used as containers within a solution to logically manage, build, and debug the items that comprise your application. The output of a project is usually an executable program (.exe), a dynamic-link library (.dll) file or a module, among others.

A project can be as simple or as complex as you need to meet your requirements. A simple project might consist of a form or HTML document, source code files, and a project file. More complex projects might consist of these items plus database scripts, stored procedures, and references to an existing XML Web Services.

Project Files

Each project template creates and maintains a project file to store the metadata specific to that project. This project file is created and maintained for you while you work within the (IDE). In general, the project file stores the configuration and build settings you specify for the project and its set of items. Some projects keep a list of the files associated with the project and the location of the file.

8/10/2008 6:34 PM

Page 21: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 21

Project References

A project has references to .NET Framework class library namespaces (next 2 slides)

.NET automatically adds references to commonly used namespaces based on the type of project template

Use the References tab of the project property page to add additional namespace references

8/10/2008 6:34 PM

Page 22: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 22

Project Property Page – References tab

8/10/2008 6:34 PM

Page 23: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 23

Some FCL Namespaces That Can Be Referenced

8/10/2008 6:34 PM

Page 24: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 24

Creating a New Solution

(You might want to get Visual Studio 2005 running on your computer while reading this)

Click on VS 2005 Icon on your desktop. Click on Create New Project to display

the New Project dialog box Specify the project template and the project

file name OR pull down the File menu and follow

the same directions Different templates appear based on the

installed Visual Studio edition 8/10/2008 6:34 PM

Page 25: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 25

New Project Dialog Box

8/10/2008 6:34 PM

Page 26: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 26

Creating a New Project

A new project does not exist in a vacuum – it must be part of an application

In VS, you begin with the application you wish to create, and VS organizes everything you do into a Solution (with one or more Projects)

The Application, and everything related to it is encapsulated in a Visual Studio solution There may be multiple projects inside a

solution The solution takes on the name of the first

Project created 8/10/2008 6:34 PM

Page 27: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 27 27

View of a new project (in a solution)

Solution with Three Projects

Page 28: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 28

Solutions and Projects

HangmanGame is the name of the solution – the name of the container for everything you do

A new solution is created from a project template

This solution contains three Projects (Note – pick your solution, projects, and components names carefully.)

Each allows you to rename – DO IT – in a meaningful way before you do your first save.

The solution file has a suffix .sln. Do not change this extension

Template Application Solution (with one or more projects)

8/10/2008 6:34 PM

Page 29: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 29

Saving a Visual Studio Project

Click File, Save All to save the solution the first time

Specify the solution name and the folder where the solution will be created By default, a new folder is created for a new

solution Again – pick all names carefully

8/10/2008 6:34 PM

Page 30: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 30

Save Project Dialog Box

8/10/2008 6:34 PM

Page 31: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 31

Organization of a Visual Studio Solution

The Solution Explorer is used to manage the elements of a solution The folder named My Project contains

configuration information common to all projects

The file AssemblyInfo.vb contains assembly metadata

The References folder contains references to other assemblies

The bin folder contains the executable file produced as a result of compiling the application

A project contains one or more parts8/10/2008 6:34 PM

Page 32: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 32

Solution Explorer with All Folders Expanded

8/10/2008 6:34 PM

Page 33: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 33

Using the Solution Explorer

The Solution Explorer is a tool window as opposed to a document window Use the drill-down interface to expand and

collapse folders Icons appear to identify different file types File names appear to the right of the file

type icon Use the Solution Explorer to rename files

rather than Windows Explorer

8/10/2008 6:34 PM

Page 34: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 34

The Solution Explorer Toolbar

The Properties button displays the Properties window

The View Code button displays the Code Editor for a module

The View Designer button displays a visual designer

The visual designer varies based on the file’s contents

Not all files have an associated visual designer The Refresh button synchronizes files The Show All Files button displays all folders and

files The View in Diagram button displays a class in a

hierarchical view

8/10/2008 6:34 PM

Page 35: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 35

Windows of the Visual Studio IDE

Windows are of two types Tool windows are common to all applications

Tool windows are used for development in all Visual Studio languages

Document windows are used to create the visual interface and code for an application

8/10/2008 6:34 PM

Page 36: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 36

Tool Windows

The Solution Explorer groups the elements of a solution

The Properties window is used to set properties for objects

The Toolbox contains controls that are created on a form

Several tool windows exist for debugging Refer to Appendix A

The Error List window displays syntax errors

The Output window displays information as a project is compiled

8/10/2008 6:34 PM

Page 37: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 37

Displaying Tool Windows

Tool windows can be anchored along an edge of the IDE The process is called docking Docked windows can be Auto Hidden

Auto Hidden windows appear when the mouse is positioned over the hidden window tab

Floating windows appear anywhere on the desktop

Some tool windows can be configured to appear as document windows

8/10/2008 6:34 PM

Page 38: Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)

Slide 38

Appearance of Windows in the Visual Studio IDE

8/10/2008 6:34 PM