Back to description
Ever since we have been developing software, there has been a need for tools to help us write, compile,... more
Ever since we have been developing software, there has been a need for tools to help us write, compile, and debug our applications. Microsoft Visual Studio 2008 is the next iteration in the continual evolution of a best-of-breed integrated development environment (IDE). If this is your first time using Visual Studio, then you will find this chapter a useful starting point. Even if you have worked with a previous version of Visual Studio, you may want to quickly skim it.
This chapter introduces the Visual Studio 2008 user experience and will show you how to work with the various menus, toolbars, and windows. It serves as a quick tour of the IDE, and as such it won’t go into detail about what settings can be changed or how to go about customizing the layout, as these topics will be explored in the following chapters.
After chapter 1, you?ll explore the common parts of Visual Studio: the Solution Explorer, the Toolbox, and Properties. You?ll see how to customize the Visual Studio IDE, and work with Visual Studio Solutions, source files, projects, source control, and version tracking. You?ll see how Visual Studio 2008 works with both Windows forms and web applications and how to use the latest .NET Framework features including generics, templates, code generation, common languages such as C#, VB, and the latest language improvements like LINQ and Windows Presentation Foundation (WPF). You?ll see all the Visual Studio features that making writing code easier including IntelliSense, code snippets, refactoring with, Refactor!. You?ll improve your software skills with software modeling, test cases, and write cleaner applications using Visual Studio?s debugging tools. You?ll protect your applications and date with cryptography and , obfuscation, and you?ll learn your many options to compile and deploy applications including MSBuild and ClickOnce.
... less
In Chapter 1 you briefly saw and interacted with a number of the components that make up the Visual Studio 2008 IDE.... more
In Chapter 1 you briefly saw and interacted with a number of the components that make up the Visual Studio 2008 IDE. Now you will get an opportunity to work with three of the most commonly used tool windowsthe Solution Explorer, the Toolbox, and Properties.
Throughout this and other chapters you will see references to keyboard shortcuts, such as Ctrl+S. In these cases we assume the use of the general development settings, as shown in Chapter 1. Other profiles may have different key combinations.
Now that you’re familiar with the general layout of Visual Studio 2008, it’s time to learn how you can customize... more
Now that you’re familiar with the general layout of Visual Studio 2008, it’s time to learn how you can customize the IDE to suit your working style. In this chapter you will learn how to manipulate tool windows, optimize the code window for maximum viewing space, and change fonts and colors to reduce developer fatigue.
As Visual Studio has grown, so too has the number of settings that you can adjust in order to optimize your development experience. Unfortunately, unless you’ve periodically spent time sifting through the Options dialog (Tools-->Options), it’s likely that you’ve overlooked one or two settings that might be important. Through the course of this chapter you will see a number of recommendations of settings you might want to investigate further.
Note A number of Visual Studio add-ins will add their own nodes to the Options dialog as this provides a one-stop shop for configuring settings within Visual Studio. Note also that some developer setting profiles, as selected in Chapter 1, will show only a cut-down list of options. In this case, checking the Advanced checkbox will show the complete list of available options.
So far you have seen how to get started with Visual Studio 2008 and how to customize the IDE to suit the way that you... more
So far you have seen how to get started with Visual Studio 2008 and how to customize the IDE to suit the way that you work. In this chapter you will learn to take advantage of some of the built-in commands, shortcuts, and supporting tool windows that will help you to write code and design forms.
In the current wave of development technology, find-and-replace functionality is expected as a fundamental part of the... more
In the current wave of development technology, find-and-replace functionality is expected as a fundamental part of the toolset, and Visual Studio 2008 delivers on that expectation. However, unlike other development environments that enable you to perform only simple searches against the active code module, Visual Studio includes the capability to perform rapid find-and-replace actions on the active code module or project, or right across the solution. It then goes an extra step by giving you the capability to search external files and even whole folder hierarchies for different kinds of search terms and to perform replacement actions on the results automatically. In the first part of this chapter you will see how to invoke and control this powerful tool.
Visual Studio 2008 is an immensely complex development environment that encompasses multiple languages based on an extensive framework of libraries and components. You will find it almost impossible to know everything about the IDE, let alone each of the languages or even the full extent of the .NET Framework. As both the .NET Framework and Visual Studio evolve it becomes increasingly difficult to stay abreast of all the changes; moreover it is likely that you need to know only a subset of this knowledge. Of course you’ll periodically need to obtain more information on a specific topic. To help you in these situations, Visual Studio 2008 comes with comprehensive documentation in the form of the MSDN Library, Visual Studio 2008 Edition. The second part of this chapter walks through the methods of researching documentation associated with developing projects in Visual Studio 2008.
Other than the simplest, such as Hello World, most applications require more than one source file.... more
Other than the simplest, such as Hello World, most applications require more than one source file. This raises a number of questions, such as how the files will be named, where they will be located, and whether they can be reused. Within Visual Studio 2008, the concept of a solution, containing a series of projects, made up of a series of items, is used to enable developers to track, manage, and work with their source files. The IDE has a number of built-in features meant to simplify this process, while still enabling developers to get the most out of their applications. This chapter examines the structure of solutions and projects, looking at available project types and how they can be configured.
Many different methodologies for building software applications exist, and though the theories about team structure,... more
Many different methodologies for building software applications exist, and though the theories about team structure, work allocation, design, and testing often differ, one point that they agree on is that there should be a single repository for all source code for an application. Source control is the process of storing source code (referred to as checking code in) and accessing it again (referred to as checking code out) for editing. When we refer to source code, we mean any resources, configuration files, code files, or even documentation that is required to build and deploy the application.
Source code repositories also vary in structure and interface. Basic repositories provide a limited interface through which files can be checked in and out. The storage mechanism can be as simple as a file share, and no history may be available. Yet this repository still has the advantage that all developers working on a project can access the same file, with no risk of changes being overwritten or lost. Most sophisticated repositories not only provide a rich interface for checking in and out, such as merging and other resolution options, but can also be used from within Visual Studio to manage the source code. Other functionality that a source control repository can provide includes versioning of files, branching, and remote access.
Most organizations start using a source control repository to provide a mechanism for sharing source code between participants in a project. Instead of developers having to manually copy code to and from a shared folder on a network, the repository can be queried to get the latest version of the source code. When a developer finishes his or her work, any changes can simply be checked in to the repository. This ensures that everyone in the team can access the latest code. Also, having the source code checked into a single repository makes it easy to perform regular backups.
Version tracking, including a full history of what changes were made and by whom, is one of the biggest benefits of using a source control repository. Although most developers would like to think that they write perfect code, the reality is that quite often a change might break something else. Being able to review the history of changes made to a project makes it possible to identify which change caused the breakage. Tracking changes to a project can also be used for reporting and reviewing purposes, because each change is date stamped and its author indicated.
Ever since its earliest days, Visual Studio has excelled at providing a rich visual environment for rapidly designing... more
Ever since its earliest days, Visual Studio has excelled at providing a rich visual environment for rapidly designing forms and windows. From simple drag-and-drop procedures for placing graphical controls onto the form, to setting properties that control advanced layout and behavior of controls, the form editor built into Visual Studio 2008 provides you with immense power without your having to dive into code.
This chapter walks you through these processes, bringing you up to speed with the latest additions to the toolset so that you can maximize your efficiency when creating Windows or web applications. While the examples and discussion in this chapter use only Windows Forms, many of the principles and techniques being discussed apply equally well to Web Forms applications.
Documentation is a critical, and often overlooked, feature of the development process. Without documentation,... more
Documentation is a critical, and often overlooked, feature of the development process. Without documentation, other programmers, code reviewers, and management have a more difficult time analyzing the purpose and implementation of code. You can even have problems with your own code once it becomes complex, and having good internal documentation can aid in the development process.
XML comments are a way of providing that internal documentation for your code without having to go through the process of manually creating and maintaining documents. Instead, as you write your code, you include metadata at the top of every definition to explain the intent of your code. Once the information has been included in your code, it can be consumed by Visual Studio to provide Object Browser and IntelliSense information.
Sandcastle is a set of tools that act as documentation compilers. These tools can be used to easily create very professional-looking external documentation in Microsoft-compiled HTML help (.CHM) or Microsoft Help 2 (.HxS) format from the XML comments you have added to your code.
Most development teams build a set of standards that specifies how they build applications. This means that every time... more
Most development teams build a set of standards that specifies how they build applications. This means that every time you start a new project or add an item to an existing project, you have to go through a process to ensure that it conforms to the standard. Visual Studio 2008 enables you to create templates that can be reused without your having to modify the standard item templates that Visual Studio 2008 ships with. This chapter describes how you can create simple templates and then extend them using the IWizard interface. It also examines how you can create a multi-project template that can save you a lot of time when you’re starting a new application.
IWizard
When the .NET Framework was initially released, many C++ developers cited the lack of code templates as a primary reason... more
When the .NET Framework was initially released, many C++ developers cited the lack of code templates as a primary reason for not moving to the .NET Framework. Generics, as introduced in version 2.0 of the .NET Framework, are more than simply design-time templates, because they have first-class support within the CLR. This chapter explores the syntax, in both C# and VB.NET, for consuming and creating generics. The chapter also looks at Nullable types, which help bridge the logical gap between database and object data; Partial types and methods, which help effectively partition code to promote code generation; and operator overloading.
Although the introduction of generics in version 2 of the .NET Framework reduced the amount of code that you had to write,... more
Although the introduction of generics in version 2 of the .NET Framework reduced the amount of code that you had to write, there were still a number of opportunities to simplify both C# and VB.NET, letting you write more efficient code. In this chapter you will see a number of new language features that have been introduced to not only simplify the code you write but also support LINQ, which is covered in more detail in Chapter 21.
One of the hotly debated topics among developers is which .NET language is the best for performance,... more
One of the hotly debated topics among developers is which .NET language is the best for performance, efficient programming, readability, and so on. Although each of the .NET languages has a different objective and target market, developers are continually seeing long-term feature parity. In fact, there are very few circumstances where it is possible to do something in one language that can’t be done in another. This chapter examines some features that are specific to either C# or VB.NET.
The release of the .NET Framework was supposed to be a revolution in the ability to rapidly build applications.... more
The release of the .NET Framework was supposed to be a revolution in the ability to rapidly build applications. However, for many Visual Basic programmers many tasks actually became more complex and a lot harder to understand. For example, where previously you could use a simple Print command to send a document to the default printer, you now needed to create a whole bunch of objects, and trap events to determine when and what those objects could print. Microsoft shipped the My namespace with version 2.0 of the .NET Framework, which gives Visual Basic developers shortcuts to common tasks.
Print
My
This chapter examines the My namespace and describes how you can harness it to simplify the creation of applications. As you’ll see, the My namespace actually encompasses web development as well, bringing the ease of development that Visual Basic 6 programmers were used to in Windows development to web applications and services. Even C# developers can take advantage of My, which can be handy for simple tasks that don’t warrant the extra effort of writing masses of class-based code.
The .NET language ecosystem is alive and well. With literally hundreds of languages (you can find a fairly complete list... more
The .NET language ecosystem is alive and well. With literally hundreds of languages (you can find a fairly complete list here: http://www.dotnetpowered.com/languages.aspx) targeting the .NET Framework, .NET developers have a huge language arsenal at their disposal. Because the .NET Framework was designed with language interoperability in mind, these languages are also able to talk to each other, allowing for a creative cross-pollination of languages across a cross-section of programming problems. You’re literally able to choose the right language tool for the job.
http://www.dotnetpowered.com/languages.aspx
This chapter explores some of the latest languages paradigms within the ecosystem, each with particular features and flavors that make solving those tough programming problems just a little bit easier. After a tour of some of the programming language paradigms, we use that knowledge to take a look at a new addition to Microsoft’s supported language list: A functional programming language called F#.
One thing that Microsoft has long been good at is providing automated help as you write your code.... more
One thing that Microsoft has long been good at is providing automated help as you write your code. Older versions of Visual Basic had a limited subset of this automated intelligence known as IntelliSense, but with the introduction of Visual Studio .NET, Microsoft firmly established the technology throughout the whole application-development environment. In Visual Studio 2008 it is even more pervasive than before, so much so that it has been referred to as IntelliSense Everywhere.
This chapter illustrates the many ways in which IntelliSense helps you write your code. Among the topics covered are code snippets, the use of XML commenting in your own projects to create more IntelliSense information, and other features as simple as variable-name completion. You will also learn how to set and use bookmarks in your code for easier navigation.
Code snippets are small chunks of code that can be inserted into an application’s code base and then customized... more
Code snippets are small chunks of code that can be inserted into an application’s code base and then customized to meet the application’s specific requirements. They do not generate full-blown applications or whole form definitions, unlike project and item templates. Instead, code snippets shortcut the programming task by automating frequently used code structures or obscure program code blocks that are not easy to remember. In the first part of this chapter you’ll see how code snippets are a powerful tool that can improve coding efficiency enormously, particularly for programmers who perform repetitive tasks with similar behaviors.
One technique that continues to receive a lot of attention is refactoring, the process of reworking code to improve it without changing its functionality. This might entail simplifying a method, extracting a commonly used code pattern, or even optimizing a section of code to make it more efficient. The second part of this chapter reviews the refactoring support offered by Visual Studio 2008.
Unfortunately, because of the massive list of functionality that the VB.NET team tried to squeeze into Visual Studio 2005, support for a wide range of refactoring actions just didn’t make the cut. Luckily for VB.NET developers, Microsoft came to an arrangement with Developer Express to license the VB version of its Refactor! product. This arrangement continues, giving VB.NET developers access to Refactor! for Visual Studio 2008. You can download it from the Visual Basic developer center at http://msdn.microsoft.com/vbasic/; follow the links to Downloads then Tools and Utilities.
http://msdn.microsoft.com/vbasic/
Refactor! provides a range of additional refactoring support that complements the integrated support available for C# developers. However, this chapter’s discussion is restricted to the built-in refactoring support provided within Visual Studio 2008 (for C# developers) and the corresponding action in Refactor! (for VB.NET developers).
Traditionally, software modeling has been performed separately to coding, often during a design phase that is completed... more
Traditionally, software modeling has been performed separately to coding, often during a design phase that is completed before coding begins. In many cases, the various modeling diagrams constructed during design are not kept up to date as the development progresses, and they quickly lose their value.
The Class Designer in Visual Studio 2008 brings modeling into the IDE, as an activity that can be performed at any time during a development project. Class diagrams are constructed dynamically from the source code, which means that they are always up to date. Any change made to the source code is immediately reflected in the class diagram, and any change to the diagram is also made to the code.
This chapter looks in detail at the Class Designer and explains how you can use it to design, visualize, and refactor your class architecture.
The Server Explorer is one of the few tool windows in Visual Studio that is not specific to a solution or project.... more
The Server Explorer is one of the few tool windows in Visual Studio that is not specific to a solution or project. It allows you to explore and query hardware resources and services on local or remote computers. You can perform various tasks and activities with these resources, including adding them to your applications.
The Server Explorer, shown in Figure 19-1, has two sets of functionalities. The first, under the Data Connections node, enables you to work with all aspects of data connections, and includes the ability to create databases, add and modify tables, build relationships, and even execute queries. Chapter 22 covers the Data Connections functionality in detail. The second set of functionalities is under the Servers node and is explored in the remainder of this chapter.
Application testing is one of the most time-consuming parts of writing software. Research into development teams and how... more
Application testing is one of the most time-consuming parts of writing software. Research into development teams and how they operate has revealed quite staggering results. Some teams employ a tester for every developer they have. Others maintain that the testing process can be longer than the initial development. This indicates that, contrary to the way development tools are oriented, testing is a significant portion of the software development life cycle. This chapter looks at a specific type of automated testing that focuses on testing individual components, or units, of a system.
Visual Studio 2008 has a built-in framework for authoring, executing, and reporting on test cases. Previously included only in the Team System Edition of Visual Studio, many of the testing tools are now available in the Professional Edition. This means a much wider audience can now more easily obtain the benefits of more robust testing. This chapter focuses on unit tests and adding support to drive the tests from a set of data.
A large proportion of applications use some form of data storage. This might be in the form of serialized objects or XML... more
A large proportion of applications use some form of data storage. This might be in the form of serialized objects or XML data, but for long-term storage that supports concurrent access by a large number of users, most applications use a database. The .NET Framework includes strong support for working with databases and other data sources. This chapter examines how to use DataSets to build applications that work with data from a database.
In the second part of this chapter you see how to use databinding to connect visual controls to the data they are to display. You see how they interact and how you can use the designers to control how data is displayed.
The examples in this chapter are based on the sample AdventureWorks database that is available as a download from http://www.codeplex.com (search for AdventureWorks).
http://www.codeplex.com
Database connectivity is almost essential in every application you create, regardless of whether it’s a Windows-based... more
Database connectivity is almost essential in every application you create, regardless of whether it’s a Windows-based program or a web-based site or service. When Visual Studio .NET was first introduced, it provided developers with a great set of options to navigate to the database files on their file system and local servers, with a Server Explorer, data controls, and data-bound components. The underlying .NET Framework included ADO.NET, a retooled database engine that works most efficiently in a disconnected world, which is becoming more prevalent today.
Visual Studio 2008 took those features and smoothed out the kinks, adding tools and functionality to the IDE to give you more direct access to the data in your application. This chapter looks at how you can implement data-based solutions with the tools provided in Visual Studio 2008, which can be collectively referred to as the Visual Database Tools.
In Chapters 11 and 12 you saw a number of language features that have been added in order to facilitate a much more efficient... more
In Chapters 11 and 12 you saw a number of language features that have been added in order to facilitate a much more efficient programming style. Language Integrated Queries (LINQ) draws on these features to provide a common programming model for querying data. In this chapter you see how we can take some very verbose, imperative code and reduce it to a few declarative lines. You will see that this gives us the ability to make our code more descriptive rather than prescriptive. By this we mean that we are describing what we want to occur, rather than the details of how it should be done.
In Chapter 23 you were introduced to Language Integrated Queries (LINQ) with an example that was able to query an object... more
In Chapter 23 you were introduced to Language Integrated Queries (LINQ) with an example that was able to query an object model for relevant customer-order information. While LINQ does provide an easy way to filter, sort, and project from an in-memory object graph, it is more common for the data source to be either a database or a file type, such as XML. In this chapter you will be introduced to LINQ to XML, which makes working with XML data dramatically simpler than with traditional methods such as using the document object model, XSLT, or XPath.
In the previous chapters you were introduced to Language Integrated Queries (LINQ) as it pertains to both your standard... more
In the previous chapters you were introduced to Language Integrated Queries (LINQ) as it pertains to both your standard .NET objects and how it can be used to query XML data. Of course one of the primary sources of data for any application is typically a database. So, in this chapter you see both LINQ to SQL, a technology that shipped with Visual Studio 2008, and LINQ to Entities, which is likely to ship in conjunction with SQL Server 2008. Both these technologies can be used for working with traditional databases, such as SQL Server. This allows you to write LINQ statements that will query the database, pull back the appropriate data, and populate .NET objects that you can work with. In essence they are both object-relational mapping frameworks, attempting to bridge the gap between the .NET object model and the data-oriented relational model.
Application design has gone through many extremes, ranging from stand-alone applications that don’t share data to... more
Application design has gone through many extremes, ranging from stand-alone applications that don’t share data to public web applications in which everyone connects to the same data store. More recently we have seen a flurry in the number of peer-to-peer applications in which information is shared between nodes but no central data store exists. In the enterprise space, key buzzwords such as Software as a Service (SaaS) and Software and Services (S+S) highlight the transition from centralized data stores, through an era of outsourced data and application services, toward a hybrid model where data and services are combined within a rich application.
One of the reasons organizations have leaned toward web applications in the past has been the need to rationalize their data into a single central repository. Although rich client applications can work well across a low-latency network using the same data repository, they quickly become unusable if every action requires data to be communicated between the client and server over a slow public network. In order to reduce this latency, an alternative strategy is to synchronize a portion of the data repository to the client machine and to make local data requests. This will not only improve performance, as all the data requests happen locally, but it will also reduce the load on the server. In this chapter you will discover how building applications that are only occasionally connected can help you build rich and responsive applications using the Microsoft Synchronization Services for ADO.NET.
Application security is a consideration that is often put off until the end of a development project or,... more
Application security is a consideration that is often put off until the end of a development project or, in all too many cases, ignored completely. As our applications become increasingly interconnected, the need to design and build secure systems is becoming increasingly important. Fortunately the .NET Framework provides a full suite of security features that make it easier than ever to build security into our applications.
In Chapter 28 you’ll see how to secure your data by implementing cryptography, and in Chapter 29 protecting your source code is explained through the process of obfuscation. However, before you approach either feature within Visual Studio 2008 application programming, you should be familiar with the basic concepts that underpin how security works within the .NET environment.
Because security is such an important requirement for many applications, this chapter introduces these concepts, rather than examining any specific technical feature of the IDE.
Anytime sensitive data is stored or transmitted across a network, it is at risk of being captured and used in an inappropriate... more
Anytime sensitive data is stored or transmitted across a network, it is at risk of being captured and used in an inappropriate or unauthorized way. Cryptography provides various mechanisms to protect against these risks. The .NET Framework includes support for several of the standard cryptographic algorithms, which can be combined to securely store data or transfer it between two parties.
If you’ve peeked under the covers at the details of how .NET assemblies are executed, you will have picked up on... more
If you’ve peeked under the covers at the details of how .NET assemblies are executed, you will have picked up on the fact that instead of compiling to machine language (and regardless of the programming language used), all .NET source code is compiled into the Microsoft Intermediary Language (MSIL, or just IL, for short). The IL is then just-in-timecompiled when it is required for execution. This two-stage approach has a number of significant advantages, such as allowing you to dynamically query an assembly for a type and method information using reflection. However, this is a double-edged sword, because this same flexibility means that once-hidden algorithms and business logic can easily be reverse-engineered, legally or otherwise. This chapter introduces obfuscation and how it can be used to protect your application logic. Be forewarned, however. Obfuscation provides no guarantees, because the IL must still be executable and can thus be analyzed and potentially decompiled.
A generation of applications built around services and the separation of user experience from backend data stores has... more
A generation of applications built around services and the separation of user experience from backend data stores has seen emerging requirements for occasionally connected applications. Introduced in Chapter 26 on Synchronization Services, occasionally connected applications are those that will continue to operate regardless of network availability. Chapter 26 discusses how data can be synchronized to a local store to allow the user to continue to work when the application is offline. However, this scenario leads to discussions (often heated) about security. As security (that is, user authentication and role authorization) is often managed centrally, it is difficult to extend so that it incorporates occasionally connected applications.
In this chapter you will become familiar with the client application services that extend ASP.NET Application Services for use in client applications. ASP.NET Application Services is a provider-based model for performing user authentication, role authorization, and profile management that has in the past been limited to use for web services and web sites. In Visual Studio 2008 you can configure your application to make use of these services throughout your application to validate users, limit functionality based on what roles users have been assigned, and save personal settings to a central location.
One of the challenges faced by developers building applications for the Windows Mobile platform is the uncertainty around... more
One of the challenges faced by developers building applications for the Windows Mobile platform is the uncertainty around the security profile of the target devices. Within a corporate environment it may be commonplace for the IT department to prescribe a given set of security settings for the company’s mobile devices. Unfortunately in the consumer space this is quite often dictated by phone carriers or manufacturers.
With earlier versions of Visual Studio, an associated power toy would allow developers to manage the security settings on the device they were working with in order to test their application behavior. Now in Visual Studio 2008 this same functionality is available via the Device Security Manager. In this chapter you learn how to work with the Device Security Manager not only to manage your device security profile, but also to manage certificates and aid in validating your mobile application.
When Microsoft released the first version of ASP.NET, one of the most talked-about features was the capability to create... more
When Microsoft released the first version of ASP.NET, one of the most talked-about features was the capability to create full-blown web applications much as Windows applications do. This release introduced the concept of developing feature-rich applications that can run over the Web in a wholly integrated way.
ASP.NET version 2.0, which was released in 2005, was a significant upgrade that included new features such as a provider model for everything from menu navigation to user authentication, more than 50 new server controls, a web portal framework, and built-in web site administration, to name but a few. These enhancements made it even easier to build complex web applications in less time.
The latest version of ASP.NET has continued this trend with several new components and server controls. Perhaps more significant, however, are the improvements that have been added to Visual Studio to make the development of web applications easier. These include enhancements to the HTML Designer, new CSS editing tools, and IntelliSense support for JavaScript. Visual Studio 2008 also includes out-of-the-box support for both Web Application projects and ASP.NET AJAX, which were not available when the previous version was released.
In this chapter you’ll learn how to create ASP.NET web applications in Visual Studio 2008 as well as look at many of the web components that Microsoft has included to make your development life a little (and in some cases a lot) easier.
Microsoft Office applications have always been extensible via add-ins and various automation techniques.... more
Microsoft Office applications have always been extensible via add-ins and various automation techniques. Even Visual Basic for Applications (VBA), which was widely known for various limitations in accessing system files, had the capability to write applications that used an instance of an Office application to achieve certain tasks, such as Word’s spell-checking feature.
When Visual Studio .NET was released in 2002, Microsoft soon followed with the first release of Visual Studio Tools for Office (known by the abbreviation VSTO, pronounced visto). This initial version of VSTO didn’t really produce anything new except for an easier way of creating application projects that would use Microsoft Word or Microsoft Excel. However, subsequent versions of VSTO quickly evolved and became more powerful, allowing you to build more functional applications that ran on the Office platform.
The latest version of VSTO was shipped as part of Visual Studio 2008. It provides significant enhancements over the previous version, including support for Office 2007 and the new Ribbon user interface, the ability to create application-level add-ins for Word, Excel, PowerPoint, Project, and Visio, and tools for building SharePoint workflows.
This chapter begins with a look at the types of applications you can build with VSTO. It then guides you through the process of creating a document-level customization to a Word document, including a custom Actions Pane. Following this the chapter provides a walkthrough showing how to create an Outlook add-in complete with an Outlook Form region. Finally, the chapter provides some important information regarding the debugging and deployment of Office applications.
In the past, building applications for mobile phones or PDAs was not for the fainthearted. It required not only a special... more
In the past, building applications for mobile phones or PDAs was not for the fainthearted. It required not only a special set of tools but also a great deal of patience to get everything to work properly. The .NET Compact Frameworka smaller, limited-feature subset of the full .NET Framework available for Windows Mobile devices, and the associated designer support within Visual Studioopened up the world of mobile application development to the general developer community. Once it was released, developers could build, test, and deploy applications just as they did Windows applications.
In Visual Studio 2008 and the .NET Compact Framework 3.5 this experience continues to improve, with richer designer support and a complete set of controls for building applications. This chapter shows you how easy it is to build and test device applications within Visual Studio 2008. In this chapter you'll notice references to the .NET Framework: unless we specify otherwise, we’re referring to the .NET Compact Framework.
Programming for mobile applications is all about optimizing the small-form factor, the mobility, and the unique functionality offered by these devices. The second part of this chapter looks at some more advanced techniques for building mobile applications, including rich support for building data applications and the new functionality offered by the Windows Mobile API.
The Windows Presentation Foundation (WPF) is one of the most significant pieces of technology to be released when it comes... more
The Windows Presentation Foundation (WPF) is one of the most significant pieces of technology to be released when it comes to building rich user interface applications. Unlike previous revisions of Windows Forms, WPF has been written entirely from the ground up to make use of vector graphics and overcome some of the limitations so often encountered with Windows Forms development.
This chapter won’t attempt to cover in any detail the WPF framework. Instead, what you will see is an overview of Visual Studio 2008 capabilities to help you rapidly build user interfaces.
In the last chapter you saw an overview of Windows Presentation Foundation (WPF), which you can use to build the user... more
In the last chapter you saw an overview of Windows Presentation Foundation (WPF), which you can use to build the user interface for your applications. Now you’ll see how you can use Visual Studio 2008 to work with the Windows Communication Foundation (WCF) and the Windows Workflow Foundation (WF). Released in conjunction with WPF as part of version 3.0 of the .NET Framework, WCF provides a consistent interface for working across a variety of communication technologies, while WF provides a solid platform for building workflow applications.
There’s no doubt that users are expecting richer and more sophisticated user interfaces in web applications.... more
There’s no doubt that users are expecting richer and more sophisticated user interfaces in web applications. High-profile web applications such as Google Maps, Windows Live Local, and Gmail have captured the imagination of web developers and led to an increased interest in pushing the boundaries of what is possible to build using HTML.
Unfortunately, web applications that are as rich and functional as these are notoriously complex to build and maintain. The tangle of technologies that is used by these applications, such as Ajax, DHTML, and JavaScript, is such that you need specialist development expertise that focuses purely on client-side web technologies.
Silverlight solves this problem by bringing the managed code to client-side development. Silverlight is a cross-platform, cross-browser plug-in that includes a lightweight version of the .NET Framework and delivers advanced functionality such as vector graphics, animation, and streaming media.
At the same time that client-side demands have increased, the complexity of the ASP.NET code on the server side has also increased. Enter the ASP.NET MVC framework. ASP.NET MVC applies the Model-View-Controller (MVC) architectural pattern, which allows you to separate an application into three components: the model, the view, and the controller. This provides better testability of the front-end code and gives you full control over the behavior and output produced by your web application.
In this chapter you learn how to build the next generation of web applications using Silverlight 2 and the ASP.NET MVC framework. In the first half of the chapter you walk through the process to build a new Silverlight component and integrate it into an existing web page. The second half explains the details and benefits of the Model-View-Controller pattern and shows you how to build a new ASP.NET MVC application.
Note This chapter covers products that were in beta at the time of writing. As such, some of the content and screenshots may have changed in subsequent releases. When the products are released in their final version, we will offer a download of the new version of this chapter at wrox.com. Just search for this book by the ISBN number 978-0-4702-2988-0, and look in the Chapter 37 folder under errata.
One of the challenges of building applications is adjusting the way the application functions on the fly without having... more
One of the challenges of building applications is adjusting the way the application functions on the fly without having to rebuild it. There’s a long history of applications using configuration files to control the way an application runs. .NET applications use a series of XML configuration files that can be adjusted to determine application behavior. This chapter explores the structure of these configuration files and demonstrates how you can store custom information using a configuration section handler.
A large proportion of applications need to persist data, and the obvious candidate for enterprise software is a relational... more
A large proportion of applications need to persist data, and the obvious candidate for enterprise software is a relational database. The .NET Framework provides support for working with SQL Server, SQL Server Compact Edition, Oracle, ODBC, and OLE DB databases. To connect to any of these databases, you need to specify a connection string that determines the location, the database, authentication information, and other connection parameters. This chapter explains how to create and store connection strings. In addition, you learn about encrypting and working with connection strings in code.
Developers often overlook the humble XML resource file, as it is often hidden by Visual Studio 2008 so as not to clutter... more
Developers often overlook the humble XML resource file, as it is often hidden by Visual Studio 2008 so as not to clutter the solution. Because its most common use is as a backing file for forms or web pages, you can write large applications without interacting directly with resource files. However, resource files are an important tool that developers need to be able to use in order to write applications that can be easily maintained and translated into other languages. The first part of this chapter explains why resource files are important and describes the features that enable developers to work with them. The remainder of the chapter explains how resource files are used to localize an application for different languages and cultures.
Debugging applications is one of the more challenging tasks developers have to tackle, but correct use of the Visual Studio... more
Debugging applications is one of the more challenging tasks developers have to tackle, but correct use of the Visual Studio 2008 debugging windows will help you analyze the state of the application and determine the cause of any bugs. This chapter examines the numerous windows available in Visual Studio 2008 to support you in building and debugging applications.
Long gone are the days where debugging an application involved adding superfluous output statements to track down where... more
Long gone are the days where debugging an application involved adding superfluous output statements to track down where an application was failing. Visual Studio 2008 provides a rich debugging experience that includes breakpoints and the Edit and Continue feature. This chapter covers how you can use these features to debug your application.
Other than writing code, debugging is likely the most time-consuming activity when writing an application.... more
Other than writing code, debugging is likely the most time-consuming activity when writing an application. If you consider all the time you spend stepping through code, looking at the watch window to see the value of a variable, or even just running the application looking for any exceptions being raised, you will realize that this is one of the most time-consuming parts of writing software.
Previous chapters have focused on how you can use the various debugging windows to retrieve information about the current status of your application, and how you can set breakpoints and tracepoints to generate debugging information. This chapter goes beyond what is provided out of the box, and looks at how you can customize the debugging experience to reduce the time spent wading through unnecessary lines of code.
Using debugging proxy types and visualizers, you can represent complex variables and data types in a useful way within the debugger. This allows you to filter out unnecessary information and zero in on the most relevant properties of an object, thereby making it easier to determine when your application is not functioning correctly and to trace the source of the issue.
With Visual Studio 2008, debugging solutions for the web is just as straightforward as doing the same for Windows-based... more
With Visual Studio 2008, debugging solutions for the web is just as straightforward as doing the same for Windows-based applications. You can use many of the same debugging windows already discussed in previous chapters, as well as deal with errors through the Exception Assistant. However, there are some differences and additional features specific to web applications that you can use to target your debugging practices more closely to the web paradigm.
In addition to the standard debugging techniques, ASP.NET also provides you with a comprehensive tracing capability, and even the capability to perform health monitoring on your system to ensure it is running in the manner you expect, and exposing problematic scenarios when it doesn’t.
Note If you are using Windows Vista with UAC you will want to launch Visual Studio with administrator rights, or you are likely to find the debugger will not attach correctly to the local web server. Right-click the Visual Studio 2008 shortcut and select Run as Administrator. To always launch as administrator, right-click the shortcut and select Properties, and then select the Compatibility tab and check the “Run this program as an administrator” checkbox.
As you’ve seen throughout the last several chapters, Visual Studio 2008 comes with a great variety of ways to debug... more
As you’ve seen throughout the last several chapters, Visual Studio 2008 comes with a great variety of ways to debug and run through your applications, including catching errors and displaying them to you for action before the code executes too far; a number of techniques for effectively debugging web applications; and other features such as breakpoints and visualizing errors.
However, there is still more functionality to be found in Visual Studio that you can use to customize your experience with debugging projects, databases, unmanaged code, and even the .NET Framework itself. In this chapter you’ll find advanced techniques for debugging your projects regardless of language or technology.
Each time a new version of Visual Studio is released there is always a delay before developers start to use it.... more
Each time a new version of Visual Studio is released there is always a delay before developers start to use it. This is primarily due to the need to upgrade existing applications to a new version of the .NET Framework at the same time. For example, the migration from Visual Studio 2003 to Visual Studio 2005 required upgrading applications to version 2.0 of the .NET Framework. With the introduction of multi-targeting in Visual Studio 2008, you can now upgrade to the latest IDE independently of moving to the .NET Framework version. This is particularly important if you still need to target older versions of Windows for which there is no support for the newer .NET Framework versions.
In this chapter you see how easy it is to migrate existing .NET applications into Visual Studio 2008. This is done it two parts: upgrading to Visual Studio 2008 and then upgrading the .NET Framework version.
Though you can build most of your projects using the default compilation options set up by Visual Studio 2008,... more
Though you can build most of your projects using the default compilation options set up by Visual Studio 2008, occasionally you’ll need to modify some aspect of the build process to achieve what you want. This chapter looks at the various build options available to you in both Visual Basic and C#, outlining what the different settings do so you can customize them to suit your own requirements.
In addition, you learn how Visual Studio 2008 uses the MSBuild engine to perform its compilations and how you can get under the hood of the configuration files that control the compilation of your projects.
When you create your .NET projects, they compile down to an assembly. By default, this assembly is open and doesn’t... more
When you create your .NET projects, they compile down to an assembly. By default, this assembly is open and doesn’t have any security on it to ensure that your users are consuming the correct version of the binary file. However, signing your assembly can rectify that issue by strongly naming the compiled application or component, which can then uniquely identify it to other applications and even system administrators who can apply a security policy against it.
In this chapter you learn how to use Visual Studio 2008 to set the assembly version number and how you can use a digital signature to sign your assembly so that it can’t be tampered with. This will also result in a strongly named assembly, which can be added to the Global Assembly Cache.
One area of software development that is often overlooked is how to deploy the application. Building an installer is a... more
One area of software development that is often overlooked is how to deploy the application. Building an installer is a simple process and can transform your application from an amateur utility to a professional tool. This chapter looks at how you can build a Windows installer for any type of .NET application.
Visual Studio 2008 also includes support for a ClickOnce deployment, which can be used to build applications that can be dynamically updated. This is particularly important for rich client applications that periodically need updating, because it solves the problem of how to roll out those updates.
In the previous chapter you saw how to deploy your Windows application via either an installer or using ClickOnce,... more
In the previous chapter you saw how to deploy your Windows application via either an installer or using ClickOnce, but how do you go about deploying other types of applications? This chapter walks you through deploying both web and mobile applications.
One of the most important aspects of building your application is to think about how you will package it so that it can be deployed. While a large proportion of web applications are only for internal release, where a simple copy script might be sufficient, if you do want to make your web application available for others to purchase and use, then you really need to focus on making the deployment process as simple as possible.
This is equally true with mobile applications. With the ever-decreasing cost of data plans, more mobile applications are being deployed straight to the device. However, for those users who still synchronize their device with their main computer it is worth building an installer for Windows that can automatically deploy your application to their device the next time it synchronizes.
Visual Studio 2008 is an integrated development environment (IDE) that lets you build several types of desktop,... more
Visual Studio 2008 is an integrated development environment (IDE) that lets you build several types of desktop, web, and embedded device applications and components. Despite being one of the premiere IDEs, there is something obvious that you will notice during your use of the IDEthe repeating of some tasks.
The development process itself contains many repetitive tasks and common pieces of code. In all development technologies and IDEs we seek solutions to save time, spare developers from doing these repetitive tasks, and let them use tools to automatically insert codes and automate their development.
Visual Studio 2008, one of the most common and well-known IDEs, isn’t an exception, and there are many features to provide this automation. Many aspects of the Visual Studio extensibility options are created to automate such repetitive tasks including add-ins, macros, code snippets, and templates. In this part of the book you are introduced to the Visual Studio 2008 automation model and two extensibility options associated with it: add-ins and macros.
You’ll learn that the automation model is a set of tools and APIs included in Visual Studio from the earlier versions, which let you access common functions in the IDE from your code rather than working directly with the IDE. This allows you to write code that automates processes.
Though the automation model is a set of APIs collected and inserted in a single architecture, they cover various aspects of the Visual Studio 2008 environment. Some of the Visual Studio Extensibility (VSX) options apply this model to provide different extensibility and automation features for Visual Studio out of the box. Add-ins and macros are two famous and common instances of these extensibility options. Both these options apply the automation model, but they have different goals and applications that are covered in the next two chapters.
In this chapter you walk through the principles of the automation model and its code representation, Development Tools Extensibility (DTE), which is one of the most common APIs in Visual Studio 2008. Before continuing to the main body of the chapter, let’s discuss the automation model in more detail.
Among the most popular and well-known extensibility options in Visual Studio 2008, and one of the two main automation... more
Among the most popular and well-known extensibility options in Visual Studio 2008, and one of the two main automation options, are add-ins.
Add-ins are a built-in part of the Visual Studio IDE, so you can start developing add-ins by installing one of the commercial editions of Visual Studio. Some of the other extensibility options require the installation of the Visual Studio SDK to work.
Moreover, add-ins have been with Visual Studio for a long time and along with macros are one of the most common extensibility and automation options in this IDE.
One of our goals in this part is to get you started with these two automation options (add-ins and macros). In this chapter you will find a good introduction to add-ins in order to know how to develop them, deploy them, and start using them.
The topic of add-ins is much broader than a single chapter, so if you want to step into real development of add-ins, you may need to refer to more resources to learn more about the topic. As you read in Chapter 51, the key point in your success with add-in and macro development is learning about the automation model and how to use the Development Tools Extensibility API to write good add-ins or macros.
Some of the major topics covered in this chapter include:
An introduction to add-ins
Step-by-step guide to using the Add-in Wizard in Visual Studio
The anatomy of an add-in
The structure of .AddIn files
.AddIn
How to start developing an add-in
How to debug your add-ins
How to deploy your add-ins
These are the main topics directly related to getting started in add-in development. But the most important thing that can help you with add-in development is having an understanding of the automation model and the smaller models included in it.
The last chapter of this part of the book is dedicated to macros. Like add-ins, macros are a very common extensibility... more
The last chapter of this part of the book is dedicated to macros. Like add-ins, macros are a very common extensibility option in Visual Studio and a built-in one. Macros are the best way to automate a task in the Visual Studio IDE.
Repetitive tasks are a common part of our daily lives, and programming is no exception. The growing number of these tasks yields many tools and applications to automate them. Many code-generation tools and applications for automating parts of programming have been introduced in recent years.
Visual Studio is an old development IDE that is being used by many developers around the world and can be used for various purposes and different application types. One of the main positive points about Microsoft products is their usability for end users, so Microsoft was one of the first companies that introduced tools for automating repetitive tasks in its products. One of the main automation options in such Microsoft products as Visual Studio, Microsoft Office, Microsoft Word, Microsoft Excel, and some other IDEs and tools was the macro.
The nice point about macros is that they can be generated by the macro recorder and can also be developed with programming tools, so someone without any knowledge of programming can also create a macro.
The topic of this chapter is macros in Visual Studio. You’ll read some helpful information about macros, including the following:
The anatomy of a macro
Macro Explorer windows in the Visual Studio IDE
Visual Studio Macros IDE
How to record a macro
How to develop a macro
How to run a macro
How to deploy a macro
Let’s get started with an introduction to macros by discussing the anatomy of a macro.
The Architect Edition aids in designing applications and datacenters, as well as planning for the deployment of these... more
The Architect Edition aids in designing applications and datacenters, as well as planning for the deployment of these applications. This is not another UML tool. It goes far beyond what simple diagrams could give us. Thanks to the tight integration with the platform and IDE, the artifacts used for the diagrams will translate nicely to other concepts already used. The diagrams go from simple documents to definitions that can actually be validated to see ahead from day one.
This chapter covers the different diagrams used to model Distributed Systems. To start, you look at the Application Designer and see how you can model the communication paths. Then you see how the Logical Datacenter Designer (LDD) allows you to define a view of your servers and the way you connect them through the different communication boundaries. Also, you see how an LDD can constrain servers to host only certain kinds of applications or allow for only certain communications. Finally, you see how the Deployment and System Designer will map applications and systems to servers and allow you to evaluate how the deployment meets the constraints and settings of both the applications and servers.
All designers include general tools to add comments and connections and to zoom in and out. You can add diagrams by right-clicking the solution and selecting Add New Distributed System Diagram from the Add menu. There you have three options: Application Diagram (AD), Logical Datacenter Diagram (LDD), and System Diagram (SD). There’s a fourth type, the Deployment Diagram (DD), but this is created from the AD or SD.