Chapter 1: Getting Started with Visual Studio

In This Chapter

check.png Surveying the available versions

check.png Setting up Visual Studio

check.png Understanding projects and solutions

check.png 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.)

There are other options, however. MonoDevelop is a tool built for Linux users to write .NET code, but works in Windows. SharpDevelop is another IDE that has some awesome potential as a testing platform. These tools are both free.

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 Microsoft just sold the whole package for what it was worth, only the Fortune 50 could afford it, and it would cut out about 99 percent of its audience. If Microsoft makes a lot of different versions and tries to incorporate the features that different groups of people use, it can capture nearly 100 percent of the audience.

tip.eps 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, you can compile nearly every code sample in this book 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. The subdivisions of Express divide the Microsoft development sphere into technological sections: one edition for each major platform. This way, the hobbyist developer can be allowed to focus on his passions.

check.pngVisual Studio Express for Windows 8: The Windows Store and its applications are going to revolutionize the world of Windows. Express for Windows 8 makes it possible to develop your Windows Store style apps for free and just have the deployment costs associated with using the store. You can develop C#, C++, and JavaScript Windows 8 apps using this edition, as well as related components. 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.

check.pngVisual Studio Express 2012 for Windows Desktop: Like the Windows 8 edition, the Windows Desktop edition of Visual Studio allows you to write apps that run on Windows Desktop in Windows 7 or 8 (or the server editions) in a variety of languages. It isn’t possible to have large multi-tier applications like you would find in big companies, but it is possible to write a pretty solid WPF or Windows Forms program and component pieces.

check.pngVisual Studio Express 2012 for Web: Web edition is an interesting free edition of Visual Studio. It’s designed around the creation of web pages using ASP.NET, ASP.NET MVC, 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.

check.pngVisual Studio Express editions for Windows Phone: As of this writing, the Windows Phone edition of Visual Studio is still version 2010, but I am betting it will be 2012 by the time you read this. WP Edition was one of the first platform-specific editions created and was clearly the model for this batch of Express editions. This package gives you all of the things you need to build, debug, and deploy Windows Phone apps using XAML and C# or VB.NET.

Professional

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

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

check.pngEnable emerging trends

check.pngInspire developer delight

check.pngRide 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, although it costs money.

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.

9781118462058-fg040101.eps

Figure 1-1: Managing software develop-ment 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

check.pngMicrosoft Office

check.pngWindows client platforms

check.pngWindows Server platforms

check.pngSQL Server

check.pngNeat middleware like SharePoint and BizTalk

check.pngWeird 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 http://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 under MSDN

Table 4-1 describes the big features that Microsoft sees and the features in different versions. The asterisks represent level of support for a given feature. I use it every time I recommend software to a client, and I hope you find it just as useful.

Table 4-1

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:

check.pngOperating system:

• Windows 7 XP1

• Windows 8

• Windows Server 2008 R2 SP1

• Windows Server 2012

check.pngSupported architectures:

• 32-bit (x86)

• 64-bit (x64)

check.pngHardware:

• 1.6 GhZ or faster processor

• 1GB of RAM

• 10GB of available hard disk space

• 5400 RPM drive

• DirectX 9-capable video card at 1024x768

You can run on this configuration — I have tried it, and it works. It’s not pretty. Visual Studio 2012 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:

check.png2.4 GHz 64 bit dual core processor

check.png64-bit Windows 8 with 8GB of RAM

check.png250GB of available HDD space

check.pngDual monitors (or a laptop with an external monitor) with one being a touch screen

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 8 without a problem. Change the settings on Virtual PC to run the clock only while the machine is running, and you have a perfect test bed.

tip.eps To find Virtual PC, search for Virtual PC on http://download.microsoft.com. To find the hack to change the clock on virtual PCs, go to the Virtual PC Guy’s blog at http://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 (except 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 four main kinds of projects in the Visual Studio New Project dialog box.

check.pngWindows Store projects are full-screen packaged apps that go in the Windows Store for Windows 8 users. They aren’t (usually) packaged for distribution, but rather deployed to the store for distribution there.

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

check.pngWeb projects make websites 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.

check.pngSpecial 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 projects — a setup project.

Exploring the New Project dialog box

I 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.5. 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 (icon size in the dialog box).

9781118462058-fg040102.tif

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:

check.pngName: The name of this project.

check.pngLocation: The path to the project file.

check.pngSolution: 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 in the lower right corner of 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 the finished program is determined by the setup project.

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.

9781118462058-fg040103.tif

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.

check.pngWindows Store Projects: These are full-screen, touch first applications for Windows 8. They can be developed in C#, VB.NET, C++, or HTML5.

Blank App: Just what it sounds like, a barebones Windows Store app.

Grid and Split app: Two pretemplated sample apps for Windows Store that show off the listview.

Class Library for Windows Store: Helps you build a .NET DLL.

Windows Runtime Component: The templates to build WinMD components for Windows 8.

Unit Test library for Windows Store: The add-on project for unit testing in Windows 8.

check.pngWindows 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 (or Windows Explorer).

WPF Custom Control Library: This is a way to make actual custom 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.

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.)

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.

check.pngWeb 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 (AJAX) 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.

check.pngOffice 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 2010 Workbook: Has a Microsoft Excel Workbook (a collection of Excel worksheets) as an output.

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

Project 2010 Add-in: Creates an add-in for Microsoft Project.

Visio 2010 Add-in: Creates an add-in for Microsoft Visio.

Word 2010 Add-in: Creates an add-in for Microsoft Word.

Excel 2010 Add-in: Creates an add-in for Microsoft Excel.

Outlook 2010 Add-in: Creates an add-in for Microsoft Outlook.

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

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

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

PowerPoint 2010 Add-in: Creates an add-in for Microsoft PowerPoint.

check.pngCommunication 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.

check.pngWorkflow 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.

check.pngSpecial Projects: Refers to anything that doesn’t fit into the preceding Bullet1s:

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. (You can also now run NUnit, xUnit, and other popular unit test frameworks right inside Visual Studio. For example, if you like NUnit, see their NUnit Test Adapter in NUnit Documentation.)

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.

check.pngOther kinds of projects: It’s easy to make your own 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