Chapter 1. Getting Started with Visual Studio

In This Chapter

  • Surveying the available versions

  • Installing Visual Studio

  • Understanding projects and solutions

  • Exploring the different types of projects

Much that you most likely have discovered about C# can be run using a command prompt and cs.exe. Fact is, that's a less-than-wonderful way to program. It's unforgiving and slow, and it's hard to remember the specifics of the language. An Integrated Development Environment (IDE) is a program that provides a platform for development. It helps make development easier.

Programmers who are used to starting with a blank screen and a command line often dismiss an IDE as a slow, bogged-down waste of time. However, I have never failed to see any of those coders change their tune after working in Visual Studio. It's quick, easy to use, agile, and smart.

It's true that you don't have to use an IDE to program, but if you're going to use one, it should be Visual Studio. It was purposely built to write C# code, and it's made to construct Windows programs. (Sales pitch over — Microsoft, I'll take my 20 bucks now.)

Seriously, ever since I did a deep dive to write Effective Visual Studio .NET, I have been a fan of Visual Studio. It truly makes writing software easier. It doesn't replace knowing the language or understanding object-oriented programming or the .NET Framework, but it sure makes life a little smoother.

This chapter introduces you to the various versions of Visual Studio and discusses the C# projects available to you.

Versioning the Versions

Visual Studio has lots of different versions (a metric ton of them — a bushel and a peck, even).

The reason is its famous licensing problem. If they just sold the whole package for what it was worth, only the Fortune 50 could afford it, and they would cut out about 99 percent of their audience. If they make a lot of different versions, and try to incorporate the features that different groups of people use, they can capture nearly 100 percent of the audience.

Tip

This book focuses on the Professional Edition, as I mention in the introduction. However, much of the sample code works in any version — though the step lists are different.

In this chapter I run down the features and benefits of all the major editions. At the end of the section, a grid shows the major features and what each edition includes.

Express

Express is the free version of Visual Studio.

Yes, I said free, as in "without cost."

Express is made for hobbyists, but many professional programmers I know use it as their "home" edition, for small personal projects, or for working on open source projects.

Although Express is significantly less functional than the Professional Edition, nearly every code sample in this book can be compiled in Express. It has the power of the .NET Framework, which is also free, and gives you a significant means of learning C#.

Express edition is not designed for making production software. It lacks several project types and many of the tools for team development. Nonetheless, it runs C# as well as anything else — remember that C# is just a language.

Express has a number of different subeditions. They split the main technologies of .NET into parts. You can't build packaged software for sale using these editions, but you sure can learn with it. The different subeditions are described in this list:

  • Visual C# Express: This edition provides much of the power of C# in a free package. Most of the project types are available, including WPF, Windows Forms, Web Forms, and service applications. The only kicker — you can't deploy. You can't deploy for production anyway, without breaking the license agreement.

  • This version is great for learning the language and for participating in open source application projects, though. Open source projects (in which you just contribute code, not a whole project for pay) are a good use for Express editions. I recommend that you get started here if you have nothing else. Much of the material in Books I and II work in Express.

  • Visual Basic Express: Like C# Express, Visual Basic Express is a free implementation of the language. It isn't for production use, though you can learn the language and participate in open source projects. Most of the project types are available.

  • Visual Web Developer: VWD is an interesting free edition of Visual Studio. It's designed around the creation of Web pages using ASP.NET or Silverlight. Because those languages aren't compiled, you can write production software for free. All the better for you and me.

    Both VB and C# are supported as of this writing, and most of the functionality of the Web projects in Visual Studio is available. Find out more at www.microsoft.com/express/vwd.

Professional

Professional Edition is designed for professional programmers. This edition of Visual Studio is the one I use daily. It's made to generate standalone programs that solve specific problems.

Microsoft is on the ball, with three goals for its Professional Edition:

  • Enable emerging trends

  • Inspire developer delight

  • Ride the next-generation platform wave

That hits the nail on the head. This is the edition that the entire book is built on, and what I recommend for the production of most programs.

As good as it is, Professional doesn't have every feature that Microsoft has to offer. The comprehensive team management features, reporting, check-in, and testing features are reserved for the pricy version: Team System.

Team System

Visual Studio Team System, usually referred to as VSTS, is the grand pooh-bah of the Microsoft platform. It connects to Team Foundation Server (a Microsoft product that provides team metrics for software development), which provides a plethora of software creation metrics when teams are involved in the development.

Figure 1-1 shows a little of what I'm talking about. Build statistics and development details can be gathered using the dashboard provided in SharePoint.

Facts are facts — Team System is cool software, but it just doesn't work without a big enterprise environment around you. It needs SharePoint, Exchange, and SQL Server to work right.

Managing software development with Team Foundation Server.

Figure 1-1. Managing software development with Team Foundation Server.

MSDN

The Microsoft Developer Network (MSDN) subscription is by far the best way to get Microsoft products. It seems like setting up a development environment to develop anything of significance would be impossibly expensive. This is not necessarily the case.

The MSDN subscription is exactly what it sounds like — a subscription to a majority of the Microsoft products that matter. For around a thousand dollars a year, you get access to everything you need. This isn't actually an edition of Visual Studio.

That sounds like a lot, but think about it this way — even if you do only one project a year on your own time, your investment will pay off. Considering the fact that Visual Studio alone is half of that, and it gets a revision every two years or so, it's a bargain. Along with Visual Studio Professional, you also get subscriptions to

  • Microsoft Office

  • Windows client platforms

  • Windows Server platforms

  • SQL Server

  • Neat middleware like SharePoint and BizTalk

  • Weird bits that you never used before (but will now)

Basically how it works is this — you go to Amazon or elsewhere and buy an MSDN license code. Then you go to msdn.microsoft.com and register the code with your Live account. From there, depending on your license level, you can download the software for development use only.

That point is an important one. The products you get from MSDN are for development purpose. So, yes, you get SQL Server (for instance). No, you can't put up your new Widget store on the Internet using the MSDN license.

So the operating system in the MSDN license is for development only. That's okay. This is a development book. If you can get MSDN, get it.

Academic

If you can't afford MSDN but you're a school student or an instructor, buy the Academic edition of Visual Studio, intended just for learning institutions. It's less expensive than MSDN, but is even more limited from the licensing perspective.

The Academic edition now costs only a hundred bucks or so. That means it costs more than the free Express edition, but it has all the features of Professional. If you're just in it to learn, it's a helpful option. If you want to deploy production software, though, you have to look elsewhere. This product isn't licensed for it.

Students, teachers, head over to the school bookstore. If they don't have Visual Studio Academic, tell them they should get it.

An edition breakdown

Table 1-1 describes the big features that Microsoft sees and the features in different versions. I use it every time I recommend software to a client, and I hope you find it just as useful.

Table 1-1. Visual Studio Versions

Visual Studio 2010

VS 2010 Professional with MSDN

VS 2010 Premium with MSDN

VS 2010 Ultimate with MSDN

Team Foundation Server

****

****

****

Development Platform Support

****

****

****

Testing

*

***

****

Database Development

 

****

****

Debugging and Diagnostics

**

***

****

Architecture and Modeling

 

*

****

Lab Management

  

***

Installing Visual Studio

Visual Studio Professional, the edition that I use for most of this book, installs much like any other Windows program. First, assure yourself that your machine can run Visual Studio. Then you run the setup program (or it automatically runs from the DVD) and make a few decisions.

Then you wait. Visual Studio is big. It takes a while.

The official requirements for Visual Studio are shown in this list:

  • Operating system:

    • Windows® XP Professional with Service Pack 2 installed, Windows Server 2003, or Windows Vista in 32 bit

    • Microsoft Windows Server® 2003 with SP1, Standard x64 Edition (WOW)

    • Microsoft Windows Server 2003 with SP1, Enterprise x64 Edition (WOW)

    • Microsoft Windows Server 2003 with SP1, Datacenter x64 Edition (WOW)

    • Microsoft Windows Server 2003 R2, Standard x64 Edition (WOW)

    • Microsoft Windows Server 2003 R2, Enterprise x64 Edition (WOW)

    • Microsoft Windows Server 2003 R2, Datacenter x64 Edition (WOW)

    • Microsoft Windows XP Professional x64 Edition (WOW)

    • Windows Vista

  • Client software:

    • Internet Explorer® 6.0 with Service Pack 1,

    • Microsoft Office 2003 with Service Pack 1 or

    • Microsoft Office 2007, MDAC 9.0, .NET Framework 2.0

  • Hardware:

    • Minimum: 2.0 GHz CPU, 512MB RAM, 8GB HDD

    • Recommended: 2.6 GHz CPU, 1GB RAM, 20GB HDD

You can run on this configuration — I have tried it and it works. It's not pretty. Visual Studio 2010 is all written in WPF, which can (with this size of an application) be a resource hog.

Seeing how that is the case, I am sure you aren't surprised to find that I have a collection of suggestions for installing Visual Studio.

First, here is what I consider to be a realistic base configuration for Visual Studio:

  • 2.4 GHz 64 bit dual core processor

  • 64-bit Windows 7 with 8GB of RAM

  • 250GB of available HDD space

  • Dual monitors (or a laptop with an external monitor)

Seems excessive? It isn't. First, I recommend that you use a virtual machine for any project that does anything to your base install of Windows. Virtual PC is free, and you can usually get a 180-day trial of Windows 7 without a problem. Change the settings on Virtual PC to run only the clock while the machine is running, and you have a perfect test bed.

Tip

To find Virtual PC, search for Virtual PC on download.microsoft.com. To find the hack to change the clock on virtual PCs, go to the Virtual PC Guy's blog at www.virtualpcguy.com and search for "clock only while active."

This plan takes power, though. You must have 4GB of RAM so that you can give 2GB of it to the virtual machine. The virtual hard drives are usually around 13GB, so you need space. Two monitors make it possible to easily see the host operating system while still running the virtual machine full screen.

Even if you aren't going to run in a virtual PC (but I recommend that you do), you still want a solid, dual core processor and lots of RAM. Why skimp? Hardware is cheap. Your time isn't!

Breaking Down the Projects

All there is left to do after you have run the setup program and set your default settings is to start on a project and get your fingers dirty. All the project types (expect maybe one or two) in the first two minibooks were Console applications, meaning they are meant to be run at the command prompt. There are a lot more projects available.

Notice three main kinds of projects in the Visual Studio New Project dialog box.

  • Windows projects are rich client applications that compile into .EXEs and run right on your computer. Microsoft Word is a Windows application.

  • Web projects make Web sites and require a Web server to run. (A Web server is included with Visual Studio for development purposes.) Microsoft.com is an example of a Web application.

  • Special projects include things like setup projects (projects that build setup programs) and database projects (projects that give a framework for databases). They usually are used with a Windows or Web application. The Setup.exe program you run in the preceding section to install Visual Studio is an example of one of these special project — a setup project.

Exploring the New Project dialog box

Let's start with a breakdown of the New Project dialog box, shown in Figure 1-2. This screen is an important part of the usability of Visual Studio. You open it by clicking the New Project link on the setup page.

The section of the dialog box to the far left is a tree-view selector, similar to the one in Outlook. You have three options — Recent Templates, Installed Templates, and Online templates. Installed Templates is selected. These templates, as Visual Studio calls them, are project types.

Within the selector is a WPF style tree viewer. Instead of maples and oaks, this tree viewer has all the project categories described in upcoming sections of this chapter.

If you click, for example, the Visual C# option in the tree view, all the projects for Visual C# appear in the window just to the right. If you click one of the suboptions, just those project types — for Visual C# —appear.

To specify the version of the .NET Framework you would like to develop for, you can use the drop-down list just above the project list that currently says .NET Framework 4.0. To change the sorting options, use the Sort By: drop-down list directly to the right. One more step to the right and you can change your view options.

So many (project) options!

Figure 1-2. So many (project) options!

In the upper-right corner is a search box, which isn't as silly as it sounds given the large number of templates now in Visual Studio. Just below the search box is the description panel, where you can see a text description of the selected project type.

At the bottom are three important text boxes:

  • Name: The name of this project.

  • Location: The path to the project file.

  • Solution: The name of the solution. Solutions are collections of projects.

For more about solutions and projects, see the next section.

Understanding solutions and projects

Visual Studio project files, and the solutions that love them, are a constant topic of interest to Microsoft developers. You work on one solution at a time, with a number of projects within. How you organize your solutions and their projects will make or break you when it comes time to find something.

You can think of solutions as folders that hold projects. They're just folders with special properties. In fact, note the check box shown earlier, in Figure 1-2. It's the one labeled Create Directory for Solution. That's what I mean — the solution is really an organizational "folder" for the projects.

Projects are where you put the code files for your programs. They store all kinds of things, like references to the .NET Framework, resources like graphics or files, and what file should be used to start the project.

Solutions do the same thing for projects that projects do for files. They keep the projects in a folder, and store certain properties. For instance, they store which project should be started when debugging starts.

Neither the project nor the solutions have much to do with a finished program. They are just simple organizational structures for Visual Studio. The installation of finished program is determined by the setup project. The solution itself is just a logical storage mechanism for the source files.

In reality, the solution is more than a folder. It's a file in a folder that is used by Visual Studio to manage the developer experience. So, inside the folder for the solution is a file describing the projects within, and then a bunch of folders with the projects themselves.

There are files for the projects, too — files that describe the resources and references for the project. They are all XML files that contain text references to the values that you set using Visual Studio.

When developing in Visual Studio, you shouldn't worry about that. In 14 years of working in various versions of Visual Studio, I have had to look at a solution or project file only a few times, and only in special situations. Knowing how they work, however, will help you design your project structure.

The way I work is to look at what I want to be a finished program and consider it a solution. Above that, I have a client folder. The result looks like Figure 1-3.

My preferred project structure.

Figure 1-3. My preferred project structure.

This strategy keeps me much more organized and works with the Visual Studio model. All I have to do is use the Browse button to change the location of the project and solution. It also helps to make the main project of a solution first (like the user interface) before the rest of the solution.

A brief survey of the available project categories

The following list describes the project types listed in the New Project dialog box in Visual Studio. These kinds of finished programs are ones you can make using the installed templates.

  • Windows Projects: Windows projects in Visual C# are programs that compile into a running program, like Microsoft Word, or Visual Studio itself. The projects include

    • Windows Forms Application: The classic "program." Compiles into a program that runs with its own window and with a red close box (with the little X in it) to exit. This is the original Windows Program style, gradually being replaced by Windows Presentation Foundation.

    • Class Library: Makes a DLL when you're all done. This is the basis of the .NET Framework, and COM before that. It's used to make blocks of reusable code.

    • WPF Application: The new "program." Also compiles into an EXE, but uses a new user interface format called Windows Presentation Foundation. I cover this in depth in Book V.

    • WPF Browser Application: Just like a WPF application but runs in Internet Explorer. This is not a Silverlight application; it's an XBAP application, short for XML Browser Application. It has a smaller set of available user interface toys but is still powerful.

    • Console application: These EXEs are designed to be run from a command prompt.

    • WPF Custom Control Library: This is a way to make actual controls that appear in the toolbox that you can use in your WPF applications.

    • Empty Project: Just what it sounds like — a project that's empty, poetic. It's used to build a program for which you don't have a template.

    • Note

      Windows Services: These programs appear in the Services control panel. Didn't know you could make those with .NET? You aren't alone. It's a powerful feature that few people know about. Windows Services are essentially terminate-and-stay-resident, or TSR, programs. (Remember those from your DOS days? They stay in memory.) Check out the article on the topic at csharpfordummies.net.

    • WPF User Control Library: The finished product of this looser control format doesn't appear in the toolbox but is much easier to build because it doesn't require coding the whole thing in C#.

    • Windows Forms control library: Like the WPF control library but for Windows Forms. It helps to build a control that you can use from the toolbox.

  • Web Projects: Web projects are programs that require a server to run (well, usually) and are used from the browser. They render HTML to the browser, rather than fancy formats like Silverlight. Projects include

    • ASP.NET Web Application: This is the centerpiece of the Web development space. It creates an application that can be run on IIS, which presents a Web page to the user.

    • ASP.NET Web Service Application: This is a class library for service-oriented applications. If you're going to distribute applications over several machines, or provide broadly distributed applications, this project type will provide a standards-based implementation for your service offerings.

    • ASP.NET AJAX Server Control: Asynchronous JavaScript And XML is a development style that provides a significant quantity of user interactions within the Web browser. This allows you to build controls that support this pattern.

    • WCF Service Application: This project belongs in the Communication Foundation section. It's like the ASP.NET Web Service Application, except it provides a number of different standards-based implementations for your service offerings. ASP.NET Web services only provide one.

    • ASP.NET Server Control: This Web control would appear in the toolbox, enabling you to drag the selected functionality right onto the Web page in development.

    • ASP.NET AJAX Server Control Extender: This control extends the functionality of another AJAX control. It targets a control and adds a feature.

    • Dynamic Data Linq to SQL Web Application: This is an ASP.NET Web application that uses Linq to make a data-active Web page.

    • Dynamic Data Entities Web Application: This ASP.NET Web application uses ADO.NET Data Entities to make a data-active Web page.

  • Office Projects: Office projects are part of the Visual Studio Tools for Office package, and use Office as a platform instead of Windows or a Web browser. To find out more, look at the Book I coauthored with Peter Jaunovich, Office Development For Dummies. Office Projects include

    • Excel 2007 Workbook: Has a Microsoft Excel Workbook (a collection of Excel worksheets) as an output.

    • Word 2007 Template: Has a Microsoft Word 2007 template (a .dot file) as an output.

    • Project 2007 Add-in: Creates an add-in for Microsoft Project.

    • Visio 2007 Add-in: Creates an add-in for Microsoft Visio.

    • Word 2007 Add-in: Creates an add-in for Microsoft Word.

    • Excel 2007 Add-in: Creates an add-in for Microsoft Excel.

    • Outlook 2007 Add-in: Creates an add-in for Microsoft Outlook.

    • Word 2007 Document: Has a Microsoft Word 2007 document as an output.

    • Excel 2007 Template: Has a Microsoft Excel 2007 template (an .xlt file) as an output.

    • InfoPath 2007 Add-in: Creates an add-in for Microsoft Infopath.

    • PowerPoint 2007 Add-in: Creates an add-in for Microsoft PowerPoint.

  • Communication Foundation Projects: Windows Communication Foundation is Microsoft's way to provide a mechanism for programs to speak with one another:

    • Syndication Service Library: Creates a syndicated feed service (RSS) that speaks either ATOM or RSS.

    • WCF Service Library: A class library for Communication Foundation.

    • Declarative Flowchart Service Library: Makes a set of services that use a flowchart-style workflow to provide services.

    • Declarative Sequential Service library: Makes a set of services that use a sequential-style workflow to provide services.

  • Workflow Projects: Workflow Foundation is the standard library for creating workflows in Microsoft programs. You can set up standard approvals, movement of documents, and the like:

    • Activity Designer Library: This project assists you with creating a user interface for creating activities.

    • Activity Library: If you aren't in the mood to create user interfaces for the creation of activities, you can create an activity.

    • Flowchart Workflow Console application: This project, and the sequential project, provides a way to test WF workflows in a safe environment.

    • Sequential Workflow Console Application: This is just like the flowchart WF project, but for sequential workflows.

  • Special Projects: Refers to anything that doesn't fit into the preceding bullets:

    • Test Project: If you're working in Visual Studio, right-click a method, and select Create Unit Test, you will get this kind of project. In the case where you want to make a test project manually, this is your project.

    • Silverlight: Admittedly, Microsoft Expression would be your best choice for Silverlight. If you want to use Visual Studio, however, you can use this project.

    • SQL Server Project: Again, I would rather use Microsoft SQL Server Management Studio to make database projects. If you have to use Visual Studio for some reason, this is your project.

    • Reports Application: You can include reports right in your Windows or Web application. If you're deploying directly to Reporting Services, this project does the job.

  • Other kinds of projects: It's easy to make a project type for Visual Studio, and there are a bunch of them out there. Some of them are patterns, some of them are languages, and some of them are new project outputs. Here are a few of my favorites:

    • ASP.NET MVC: Model View Controller (MVC), a project type that allows for a separation of duties between development teams. This project type allows you to make ASP.NET applications using MVC. Search MSDN for more information.

    • MVC4WPF: Allows for Model View Controller development for Windows Presentation Foundation. It has automation and templates just like regular WPF applications. Check it out at www.mvc4wpf.com.

    • IRONRuby: An implementation of Ruby in Visual Studio.

    • IRONPython: An implementation of Python in Visual Studio.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.117.56