Introduction
Welcome to the next era in .NET development. .NET has moved from a set of developer-focused tools and a runtime environment to the core of the latest Microsoft operating system. In 2002, Microsoft released .NET and introduced developers to a new paradigm for building applications. For Visual Basic it was not only a new environment, but really a new language.
Visual Basic .NET (as it was initially called) went beyond an overhaul. .NET changed core elements of the syntax affecting every aspect of development with Visual Basic. The entire runtime model shifted to a new common language runtime (CLR) environment and the language went from object-based to object-oriented. Although most people didn't recognize it, we were moving to a new language.
Now with the introduction of Windows RT, Microsoft has again shifted the paradigm. Not so much at the language level, but as it relates to how user interfaces are developed and work. The original runtime environment, although enhanced for .NET 4.5, risks being flagged as being on the path to that fatal “legacy” designator. Windows 8 introduces the concept of Windows Store applications, which are built on a version of the CLR that has different features, and that's important. Because while client applications may view the core CLR as legacy, server-based applications have probably never been in a position to leverage it more.
This book provides details about not only the latest version of Visual Basic and the new .NET Framework 4.5. More important, it carries this coverage to a new platform, Windows RT, and a new class of Windows Store applications. As a result the contents of this book have been turned upside down. This book doesn't just indicate that there are new Windows Store applications, but focuses in directly on how to build and deploy this new class of applications. The result is a very different book from the previous edition.
If you compare this edition to an older edition you'll immediately realize that this edition is visibly smaller. Just as you saw Visual Basic evolve nearly 10 years ago, .NET is going through an evolution of its own. The result was a need to refocus on what this book covers. This has resulted in a sea change with regard to where to focus coverage for Visual Basic.
The most noticeable omission from the book is in fact the original smart client development model—Windows Forms. When Microsoft introduced WPF it informally announced that the era of Windows Forms was ending. It has taken some time, and certainly support will continue for many more years, but the reality is that the evolution of Windows Forms is complete. The information around Windows Forms provided in past editions of this book is essentially complete. While one or two of the chapters do still reference Windows Forms in their samples, by and large the book has moved beyond the use of this technology.
The result was that Billy Hollis, who has a passion for user interface design, agreed to take on the rather significant task of re-imagining how to approach user interface design in a world that includes Windows RT. The new XAML-based interface design chapters are completely redone from the ground up and focused on teaching developers how to approach XAML development from the ground up. The last version of the book approached the user interface model from Windows Forms and transitioning to XAML. However, in this version the approach takes on XAML as the primary user interface development model. As such these chapters address Windows Store application development head-on, not as an afterthought.
However, Windows Forms wasn't alone in being moved into the past. We've eliminated several appendices, Microsoft Office (both VSTO and SharePoint) integration, and references to classic COM. Some, for example, development around Microsoft Office, is facing its own set of changes as Microsoft Office prepares to evolve. Others, such as classic COM and Windows Forms, are no longer technologies that developers should be targeting. We also found ourselves needing to change out how we addressed larger topics such as ASP.NET and Silverlight. The result is that this book is much more focused on building applications using Visual Basic that target Microsoft's core next generation of technologies.
Early in the adoption cycle of .NET, Microsoft's new language, C#, got the lion's share of attention. However, as .NET adoption has increased, Visual Basic's continuing importance has also been apparent. Microsoft has publicly stated that it considers Visual Basic to be the language of choice for applications for which developer productivity is one of the highest priorities.
In the past, it was common for Microsoft and others to “target” different development styles; with Visual Studio 2010, Microsoft announced that VB and C# will follow a process of coevolution. As new language features are developed, they will be introduced to both Visual Basic and C# at the same time. This release is the first step in that process, although it's not complete at this time.
Coevolution does not mean that the languages will look the same, but rather that they will support the same capabilities. For example, Visual Basic has XML literals, but that doesn't mean C# will get exactly the same functionality, as C# has the capability to work with XML through the existing framework classes. The old process of first introducing a feature in Visual Basic and then in the next release having C# catch up, and vice versa, is over. As new capabilities and features are introduced, they are being introduced to both Visual Basic and C# at the same time.
This leads to a discussion of the “Roslyn” compiler implementation. It seems like almost five years ago that the first whispers of a new 64-bit Visual Basic compiler implemented with Visual Basic started. Considered the standard for a serious language, implementing a language compiler in the language it compiles has become something of a standard.
However, over time this project evolved. Microsoft, seeing commonalities across the C# and Visual Basic compilation projects, realized that once the core syntax had been consumed the remainder of the compilation process was common across languages. While each implementation language needed a custom solution to handle parsing and interpreting the raw “code,” once that code had been converted to Intermediate Language (IL) the remaining compiler steps were essentially the same.
Suddenly a new concept—the compiler as a service—was created. Code-named Roslyn, this is the future for both Visual Basic and C# compilation. Roslyn takes the traditional compiler as a “black-box” and provides an interface that for interacting with the creation of .NET assemblies. Introducing an API that exposes your components during the compilation process is a powerful tool. Roslyn has been in a technology preview model since well before the release of Visual Studio 2012 and .NET 4.5—however, Microsoft isn't quite ready to declare it ready for prime time. As a result it's still an optional add-on with Visual Studio 2012.
However, even though Roslyn isn't part of Visual Studio 2012, Visual Studio 2012 includes a few paradigm shifts. For starters you'll find that you can now work on projects that targeted older versions of Visual Studio without breaking backward compatibility in those projects. Visual Studio 2012 was designed so that those people who move to the latest tools are limited when working with a team that hasn't fully migrated to that new version.
More important, Visual Studio 2012 comes with a promise of updates. It'll be interesting to see how this plays out over the coming months, but the Visual Studio team has indicated that they will be releasing regular updates to Visual Studio. Update 1 has already been announced as this book goes to print, and the team has indicated that they would like to continue with updates on a quarterly basis. This goes beyond what we've seen in the past, with Power Pack style updates that occurred out of the standard release cycle. Instead we see that Microsoft is committing to keeping Visual Studio on the cutting edge of evolving technology. As the environments we developers need to support change, we can expect that Visual Studio will be adapting and incrementally improving to help us.
While these changes may not involve changes to the core of the .NET framework, we can expect .NET to remain the most productive environment for custom applications. One of the most important advantages of the .NET Framework is that it enables applications to be written with dramatically less code then other alternatives. Originally this was in comparison to older technologies, but today the comparison is as opposed to writing native solutions that support the many different platforms and operating systems you need to support. In the world of business applications, the goal is to concentrate on writing business logic and to eliminate routine coding tasks as much as possible. In other words, of greatest value in this new paradigm is writing robust, useful applications without churning out a lot of code.
Visual Basic is an excellent fit for this type of development, which makes up the bulk of software development in today's economy. Moreover, it will grow to be an even better fit as it is refined and evolves for exactly that purpose.
This book was written to help experienced developers learn Visual Basic. For those who are just starting the transition from other languages or earlier versions to those who have used Visual Basic for a while and need to gain a deeper understanding, this book provides information on the most common programming tasks and concepts you need.
Professional Visual Basic 2012 and .NET 4.5 Programming offers a wide-ranging presentation of Visual Basic concepts, but the .NET Framework is so large and comprehensive that no single book can cover it all. The focus in this book is providing a working knowledge of key technologies that are important to Visual Basic developers. It provides adequate knowledge for a developer to work across both Windows Store applications through WCF services. This book is meant to provide a breadth of knowledge about how to leverage Visual Basic when developing applications. For certain specific technologies, developers may choose to add to their knowledge by following this book with a book dedicated entirely to a single technology area.
This book covers Visual Basic from start to finish. It starts by introducing Visual Studio 2010. As the tool you'll use to work with Visual Basic, understanding Visual Studio's core capabilities is key to your success and enjoyment with building .NET applications. In these pages, you have the opportunity to learn everything from database access, Language Integrated Queries (LINQ), and the Entity Framework, to integration with other technologies such as WPF, WCF, and service-based solutions. Along with investigating new features in detail, you'll see that Visual Basic 10 has emerged as a powerful yet easy-to-use language that enables you to target the Internet just as easily as the desktop. This book covers the .NET Framework 4.
Part I, “Language Constructs and Environment”—The first six chapters of the book focus on core language elements and development tools used by Visual Basic developers. This section introduces Visual Studio 2012, objects, syntax, and debugging.
Part II, “Business Objects and Data Access”—The next five chapters, Chapter 7 through Chapter 11, look at common structures used to contain and access data. This includes framework elements such as arrays and collections, XML, database access, and Windows Communication Foundation (WCF) services. These chapters focus on gathering data for use within your applications.
Part III, “Specialized Topics and Libraries”—Chapters 12 through Chapter 14 focus on creating client applications. These chapters address Windows Store applications, which are exclusive to the Windows RT CLR. In parallel it discusses building applications for WPF that are compatible with earlier versions of Windows and which represent the majority of corporate applications. Chapter 14 moves to looking at web-based applications and interfaces. Chapters 15 through 20 then focus on topics such as localization, windows services, security, multi-threaded applications, and deployment.
Although it is possible to create Visual Basic applications using the command-line tools contained in the .NET Framework, you'll want Visual Studio 2012, which includes the .NET Framework 4.5, to get the most out of this book. In addition, note the following:
Several chapters make use of Internet Information Services (IIS). IIS is part of every operating system released by Microsoft since Windows XP, but on newer operating systems you'll need to run as administrator to develop against it. Alternatively, you can leverage the development server that ships with Visual Studio 2012.
The source code for the samples is available for download from the Wrox website at:
www.wrox.com/remtitle.cgi?isbn=9781118314456
To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.
As for styles in the text:
We use a monofont type with no highlighting for most code examples. We use bold to emphasize code that is particularly important in the present context or to show changes from a previous code snippet.
As you work through the examples in this book, you may choose either to type in all the code manually, or to use the source code files that accompany the book. All the source code used in this book is available for download at www.wrox.com. Specifically for this book, the code download is on the Download Code tab at:
www.wrox.com/remtitle.cgi?isbn=9781118314456
You can also search for the book at www.wrox.com by ISBN (the ISBN for this book is 978-1-118-31445-6) to find the code. And a complete list of code downloads for all current Wrox books is available at www.wrox.com/dynamic/books/download.aspx.
At the beginning of each chapter that contains downloadable code, we've provided a reminder of the link you can use to find the code files. Throughout the chapter, you'll also find references to the names of code files in the listing titles or the text.
Most of the code on www.wrox.com is compressed in a .ZIP, .RAR archive, or similar archive format appropriate to the platform. Once you download the code, just decompress it with an appropriate compression tool.
Once you download the code, just decompress it with your favorite compression tool. Alternately, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.
We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or a faulty piece of code, we would be very grateful for your feedback. By sending in errata, you may save another reader hours of frustration, and at the same time, you will be helping us provide even higher-quality information.
To find the errata page for this book, go to
www.wrox.com/remtitle.cgi?isbn=9781118314456
and click the Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors.
If you don't spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.
For author and peer discussion, join the P2P forums at http://p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.
At http://p2p.wrox.com, you will find a number of different forums that will help you, not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:
Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.
For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works, as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.
Visit www.safaribooksonline.com/wrox
Related Wrox Books
Beginning ASP.NET 4.5 in C# and VB
ISBN: 978-1-118-31180-6
Featuring a user-friendly, step-by-step format, the book guides you through customizing the IDE, building a Planet Wrox website example, working with files and web forms, designing web pages, displaying and updating data, creating tables, and much more. With this resource in hand, you will be completely at ease learning ASP.NET 4.5.
Beginning Microsoft Visual C# 2012 Programming
ISBN: 978-1-118-31441-8
Using this book, you will first cover the fundamentals such as variables, flow control, and object-oriented programming and gradually build your skills for web and Windows programming, Windows forms, and data access. Step-by-step directions walk you through processes and invite you to “Try it Out,” at every stage. By the end, you'll be able to write useful programming code following the steps you've learned in this thorough, practical book. If you've always wanted to master Visual C# programming, this book is the perfect one-stop resource.
Ivor Horton's Beginning Visual C++ 2012
ISBN: 978-1-118-36808-4
Offering a comprehensive introduction to both the standard C++ language and to Visual C++, Ivor Horton offers step-by-step programming exercises, examples, and solutions to deftly guide novice programmers through the ins and outs of C++ development.
Professional Visual Studio 2012
ISBN: 978-1-118-33770-7
This book is what you need to get up and running quickly on Visual Studio 2012. Written by a Microsoft Visual C# MVP, it guides you through the integrated development environment (IDE), showing you how to maximize each of the tools and features.
Visual Basic 2012 Programmer's Reference
ISBN: 978-1-118-31407-4
Visual Basic 2012 is packed with powerful features and this book will help you master them all. You'll gain a solid understanding of essential Visual Basic topics and begin applying the information to perform a host of important development tasks. The tutorials inside are filled with code examples and the best methods for using them to write your own programs.