Table of Contents
Introduction
1 A Quick Tour of Visual Studio 2015
The Visual Studio Product Line
Community Edition
Professional Edition
Enterprise
MSDN
TFS and Related Tools
Languages and Frameworks
Programming Language Choices
The .NET Framework
The Many Faces of a .NET Application
Windows
Web
Mobile
Developing Windows 8/10 Clients
Windows (WinForms)
Windows Presentation Foundation (WPF)
Office/SharePoint Solutions
Creating Web Applications with ASP.NET 5
Building Websites with Web Forms
Developing with MVC/Razor
Creating a Single Page Application (SPA)
Coding Web Services with Web API
Coding for Azure
Creating a Cloud Application
Publishing to Azure
Working with Data
Model as Code (Code First)
Writing Mobile Apps
Create an Apache Cordova App
Summary
Installing Visual Studio
Installing Optional Features
Signing In to Visual Studio
Managing Your IDE
Settings Specify Stored and Synchronized
Settings Change Color Theme
Manually Import/Export and Change Default IDE Settings
Switch IDE User
Getting Started
Startup Options
Creating Your First Project
Targeting Your Environment
Navigating the IDE
The Menus
The Many Toolbars
Customizing Toolbars
The Solution Explorer
The Text Editors
The Visual Designers
The Toolbox
The Properties Window
Managing the Many Windows of the IDE
Pinning
Docking
Custom Window Layouts
Navigating IDE Windows
Touch Support
Customize Your IDE Font
Providing Feedback on Visual Studio
The Customer Experience Program
Summary
What’s New in C# 6.0 and VB 14
Null-Conditional Operators
ReadOnly Auto Properties
NameOf Expression
Using (Imports) Statics
String Interpolation
Lambda Expressions as Methods (C# Only)
Index Initializers (C# Only)
Language Primer
Programming Objects
Types, Variables, and Constants
Understanding Operators
Making Decisions and Branching Code
Looping
Working with Groups of Items
Programming with Attributes
Creating and Raising Events
Language Features
Infer a Variable’s Data Type Based on Assignment
Create an Object and Initialize Its Values (Object Initializers)
Define a Collection and Initialize Its Values
Creating an Instance of a Nonexistent Class
Add Methods to Existing Classes (Extension Methods)
Add Business Logic to Generated Code (Partial Methods)
Access and Query Data Using the .NET Languages
Write Simple Unnamed Functions Within Your Code (Lambda Expressions)
Splitting an Assembly Across Multiple Files
Working with XML Directly Within Your Code (VB Only)
Removing Unused Arguments from Event Handlers (VB Only)
Creating an Automatically Implemented Property
Dropping the Underscore in VB for Line Continuation
Working with Dynamic Languages/Objects
Covariance and Contravariance
Asynchronous Programming
The .NET Framework
A Map to the .NET Framework
Summary
Understanding Solutions
Creating a Solution
Working with Solutions
Getting Comfortable with Projects
Creating a Project
Working with Project Definition Files
Working with Projects
Summary
Leveraging the Solution Explorer
Visual Cues and Item Types
Interacting with Items
Inspecting Objects
Class View
Toolbar
Search Bar
Objects Pane
Members Pane
Server Explorer
Data Connections
Server Components
Azure
Object Browser
Changing the Scope
Browsing Objects
Document Outline
Editing Elements
Summary
Getting Started with the Basics
The Text Editor
Visual Studio Designers
Coding with the Code Editor
Opening an Editor
Writing Code in the Code Editor
Anatomy of the Code Editor Window
Code Navigation Tools
Searching Documents
Debugging in the Text Editor
Printing Code
Using the Code Definition Window
Creating and Editing XML Documents and Schema Inferring Schema
Designing XML Schemas
Editing XSLT Style Sheets
Working with Cascading Style Sheets
Adding Style Rules
Defining Style Sheet Attributes
Developing Windows Client Applications
Creating a Windows Forms Project
Creating a Windows Presentation Foundation Project
Developing Web Forms
Designing a Web Form Application
Authoring WinForms Components and Controls
Creating a New Component or Control Further Notes on Writing Component Code
Creating Classes with the Class Designer
Creating a Class Diagram Adding Items to the Diagram
Defining Relationships Between Classes Defining Methods, Properties, Fields, and Events
Summary
Basic Aids in the Text Editor
Change Tracking
Coding Problem Indicators
Active Hyperlinking
Syntax Coloring
Outlining and Navigation
Code Outlining
Tag Navigation
Smart Tasks and Light Bulbs
HTML Designer
Windows Forms Designer
Code Editor
IntelliSense
Complete Word
Quick Info
List Members
Parameter Info
Organize Usings
Code Snippets and Template Code
Brace Matching
Customizing IntelliSense
The Task List
Shortcut Tasks
Comment Tasks
Summary
Unit Testing Basics
Creating a Test Project
Writing a Unit Test
Running Your Tests
Controlling Test Settings
The Unit Testing Framework
The TestContext Class
The Test Attribute Classes
Unit Test Setup and Teardown
The Assert Classes
Testing Your Exceptions
Creating Data-Driven Unit Tests
Testing Web Applications
Unit Testing MVC and Web API Projects
Unit Testing ASP.NET Pages
Creating Ordered Tests
Summary
Visual Studio Refactoring Basics
Invoking the Refactoring Tools
Making (and Previewing) Changes
Using the Class Designer to Refactor
Renaming Code
Accessing the Rename Operation
Working with the Rename Dialog Box
Refactoring Variable Assignments
Introduce Constant
Introduce Local
Inline Temporary Variable
Extract Method
Accessing the Extract Method Refactor
Extracting Methods
Extracting a Single Line of Code
Generate Method Stub
Extract Interface
Accessing the Extract Interface Refactor
Extracting Interfaces
Change Signature
Removing a Parameter
Reorder Parameters
Encapsulate Field
Accessing Encapsulate Field
Summary
Debugging Basics
The Scenario
The Many Phases of Debugging
Debugging the Application (Self-Checking)
Debugging Basics Summary
The Visual Studio Debugger
The Debug Menu and Toolbar
Debug Options
Stepping In, Out, and Over Code
Indicating When to Break into Code
Working with Tracepoints (When Hit Option)
Viewing Data in the Debugger
Using the Edit and Continue Feature
Advanced Debugging Scenarios
Remote Debugging
Debugging WCF Services
Debugging Multithreaded Applications
Debugging Parallel Applications
Debugging a Client-Side Script
Debugging Crash Information (Dump Files)
Debugging Windows Store Apps
Summary
An Overview of Client Deployment Options
Introducing ClickOnce Deployments
Introducing Windows Installer and InstallShield Deployments
Publishing a Project with ClickOnce
Publishing a Project with InstallShield Limited Edition
Publishing an ASP.NET Web Application
Selecting a Target
Configuring a Connection
Configuring Deployment Settings
Previewing the Publication
Summary
Create Your Azure Account
Azure Account Sign-Up
Link Your Account to Visual Studio
Manage Azure Subscriptions
Create and Deploy an Azure Web Apps in Visual Studio
The Azure Hosting Platform
Create the ASP.NET Application and Azure Hosting
Deploy/Publish an Application to Azure
Set Up an Existing Application to Publish to an Azure web app
Website Management with Azure Server Explorer
Debug an Azure web app
Create Your Web App from the Azure Portal
Create the Application Hosting Environment
Configuring Your New Azure web app
The Website Toolbar
Creating a Database
Deploying to the New Environment from Visual Studio
Monitor and Manage Applications in Azure
Monitor and Manage a Website
Monitor and Manage a SQL Database
The Azure SDK for Visual Studio 2015
Download, Install, and Sign In
QuickStart Templates
Azure Resource Group Deployment Projects
Azure Cloud Services (PaaS)
Creating a Cloud Service Project
Running Your Cloud Service Project Locally
Deploy the Cloud Service Project
Summary
Creating Tables and Relationships
Creating a New SQL Server Database
Defining Tables
Working with SQL Statements
Writing a Query
Creating Views
Developing Stored Procedures
Creating Triggers
Creating User-Defined Functions
Using Database Projects
Creating a Database Project
Changing the Database
Building and Deploying
Creating Database Objects in Managed Code
Creating a Stored Procedure in C#
Binding Controls to Data
An Introduction to Data Binding
Autogenerating Bound Windows Forms Controls
Editing Typed Data Sets
Manually Binding Windows Forms Controls
Data Binding in WPF Applications
Data Binding with Web Controls
Object Relational Mapping
An Overview of LINQ
Mapping Using the O/R Designer
LINQ Code
Working with the Entity Framework
Querying Against the Entity Data Model
Summary
An Overview of the Automation
Object Model Object Model Versions
Automation Categories
The DTE/DTE2 Root Object
Solution and Project Objects
Controlling Projects in a Solution
Accessing Code Within a Project
Working with Windows
Referencing Windows
Interacting with Windows
Text Windows and Window Panes
The Tool Window Types Linked Windows
Command Bars
Documents
Text Documents
Command Objects
Executing a Command
Mapping Key Bindings
Debugger Objects
Summary
Creating Your First Extension
Setting Package Parameters
Adding Project Items
The Structure of an Extension Defining and Reacting to Commands
A Sample Extension: Color Selector
Getting Started
Creating the User Control
Finishing the Package
Summary
The Extensibility Problem
Creating Dynamic Applications
MEF Architecture
MEF Principles
Working with MEF
The Visual Studio Editor and MEF Editor Extension Points
Using the Visual Studio SDK
Managing Extensions and Updates
Creating Your Own MEF-Based Editor Extension
Summary
ASP.NET Website Fundamentals
Introducing ASP.NET 5
The .NET Core Framework and Execution Environment
Choosing an ASP.NET Project Template
Understanding the ASP.NET 5 Project Template and Related Files
ASP.NET 5 Dependencies and Package Managers
Creating a Web Application with ASP.NET 5/MVC 6
Understanding the MVC Pattern
Creating a New ASP.NET 5 MVC 6 Project
Writing ASP.NET Server Code (Models and Controllers)
Defining a Model (Using Entity Framework 7)
Developing Controllers
Coding for the UI (Views and Related Web UI Elements)
The HTML Tags
The Razor Syntax
HTML Helpers
Page Layout with Razor
Strongly Typed Views
User Input Validation
Creating the Customer Example Pages
View Components, View Models, and Partial Views
Using Scaffolding to Generate a Controller and Views
Summary
JavaScript Fundamentals
Storing and Using Scripts
Writing JavaScript
Functions
Objects
Built-In Objects
Working with the Browser Object Model (BOM)
Document Object Model (DOM)
Events
Developing with jQuery
jQuery in Your Visual Studio Project
Selecting Elements
Acting on Your Selection
Traversing Your Selections
Accessing Selection Content
Changing Elements/Attributes
Handling Events
Animations and Effects
jQuery and AJAX
Building Single-Page Applications (SPAs) with Client-Side JavaScript Frameworks
Selecting a Client Framework
Responsive Web Layout with Bootstrap 3
Minify Your JavaScript with Gulp
Using Knockout
Creating a Site with AngularJS
Summary
Service Fundamentals
Why ASP.NET Web API and WCF
Key Web Service Terms
Use ASP.NET Web API to Build HTTP Services
Creating an ASP.NET Web API Project
Defining a Model
Creating the Services (Controller)
Understanding Service Routing
Consuming an ASP.NET Web API Service
WCF Service Applications
The WCF Project Template
Creating a WCF Service
Running and Testing Your WCF Service
Consuming a WCF Service
Creating/Calling REST-Based WCF Services
Hosting and Deploying a WCF Service
Summary
The Basics of Form Design
Considering the End User
Understanding the Role of UI Standards
Planning the User Interface
Creating a Form
The Windows
Forms Application Project Type Form Properties and Events
Adding Controls and Components
Control Layout and Positioning
Using Containers
Control Appearance and Behavior
Working with ToolStrip Controls
Displaying Data
Creating Your Own Controls
Subclassing an Existing Control
Designing a User Control
Creating a Custom Control
Summary
The Windows Presentation Foundation Platform
Programming Model
Introducing the WPF Designer XAML and Design Panes
Programming with WPF
Layout
Styles and Templates
Data Binding
Routed Events
Building a Simple Image Viewer Application
Starting the Layout
Storing the Images
Binding to the Images
Button Event Handlers and Image Effects
Path Selection with a Common Dialog Box
Summary
An Overview of Office Extension Features
Office Features
Visual Studio Office Project Types
Creating an Office Add-In
Customizing the Ribbon
Customizing the Task Pane
Creating Outlook Form Regions
Creating an Office Document Extension
Hosting Controls
Creating an Actions Pane
Storing Data in the Data Cache
Extending Office with Webpages
Starting with the App for Office Project Template
Summary
Introducing the Modern UI
Modern UI Attributes
The Windows Runtime Library
Language Choices
The Application Model
Building a Windows Store Application
Selecting the Project Type
Designing the Layout
Reacting to Lifecycle Events
Publishing to the Windows Store
Summary
Windows Phone Fundamentals
The UI Basics
The Programming Model
Moving from Silverlight to WinRT
Porting a Simple Silverlight Phone App to WinRT
Building a Universal App
The Universal Project Types
Creating the Data Model and View Model
Creating the Windows Phone UI
Creating the Windows UI
Summary
Fundamentals of Cordova Development
How Cordova Works
Cordova Dependencies
The Cordova Project Template
Creating a Basic Cordova App
Running and Debugging Your App
Using Cordova Frameworks and Plug-Ins
Choosing Cordova Client Frameworks
Cordova Plug-Ins (for Accessing Native Device Capabilities)
Developing a Cordova App with Ionic and Angular
Set Up Your Project
Anatomy of the Ionic-Angular-Cordova App
Rebuild the Sample App
Support Storage
Running on Windows Phone
Additional Items to Consider
Summary
Index
Introduction
Visual Studio 2015 is Microsoft’s first, big release since moving to a more open-source approach for .NET and related technologies. This includes the new Roslyn compiler for C# and Visual Basic, the .NET Core Framework, ASP.NET itself, and more. The result is enabling a wider reach for .NET applications, including both building and deploying on Mac, Linux, and Windows.
Microsoft has also worked to integrate Visual Studio with community-driven, open source JavaScript frameworks, package managers, and UI kits. The ASP.NET 5 model simplifies modern web development using frameworks such as Bootstrap, AngularJS, Knockout, Gulp, and many more.
Visual Studio 2015 supports the new, Universal App model for building on Windows. These applications can be written once and adapted to desktop, tablet, and phone. This includes upcoming support for Windows 10 development.
Cross-platform mobile development is also supported. Microsoft has provided project templates for the open-source Apache Cordova. This enables developers to build a mobile application that runs on iOS, Android, and Windows Phone using familiar web technologies of Hypertext Markup Language (HTML), Cascading Style Sheets (CSS), and JavaScript.
This latest version of Visual Studio unlocks productivity across platforms and application types. And this book is meant to help you unlock the power behind Visual Studio so that you can realize productivity gains and greater reach for your applications.
Who Should Read This Book?
Developers looking to use Visual Studio (Community, Professional, or Enterprise) to build great apps for users will want to read this book. Of course, established .NET developers who rely on Visual Studio to get work done will also want to read this book to ensure they are getting the most out of their chosen toolset. This book covers both using the IDE and building most of the many types of applications Visual Studio supports. It covers all of the following key topics:
- Writing code using Visual Basic and C#
- Understanding the basics of solutions, projects, editors, and designers
- Writing IDE extensions and add-ins
- Writing unit tests to verify your code works as designed
- Debugging code with the IDE
- Refactoring your code
- Building websites using the new ASP.NET 5 (and MVC 6) model, which includes support for Bower client-side package management and the new .NET Core 5 for running ASP.NET applications on Windows, Mac, and Linux
- Using JavaScript and the many client-side frameworks such as Knockout, AngularJS, and Bootstrap to create great web experiences
- Developing service-based solutions for web and mobile clients using ASP.NET Web API and Windows Communication Foundation (WCF)
- Creating Windows desktop and Store applications using Windows Presentation Foundation (WPF)
- Working with data and databases and leveraging LINQ and Entity Framework to build data-centric applications
- Using Microsoft Office and Visual Studio to create enterprise solutions based on common office tools (Word, Excel, and so on)
- Creating Windows Azure applications that live in the cloud
- Developing applications for Windows Phone
- Building cross-platform mobile applications that run on iOS, Android, and Windows Phone using Apache Cordova and related tools
This book has one primary focus: detailing and explaining the intricacies of the Visual Studio 2015 IDE to enable developers to be work faster and, ultimately, work smarter. Although we do provide a language primer, those just starting out with Visual Basic or C# may want a companion book that focuses solely on their language of choice. If you can write C# or Visual Basic code, this book will radically help you optimize your productivity with Visual Studio. This book focuses primarily on Visual Studio 2015 Professional edition (which also covers the Community edition). There are additional features in Visual Studio Enterprise. However, those are mostly not covered by this book. Instead, we dedicate space to the version of the product used by the majority of .NET developers all over the world.
How Is This Book Organized?
You can read this book cover to cover, or you can pick the chapters that apply most to your current need. We sometimes reference content across chapters, but for the most part, each chapter can stand by itself. This organization allows you to jump around and read as time (and interest) permits. There are seven parts to the book; each part is described next.
Part I: Introducing Visual Studio 2015
The chapters in this part provide an overview of what to expect from Visual Studio 2015. This includes a tour of using the IDE to build various types of applications. In addition, we cover the new C# and Visual Basic language enhancement for the 2016 and the .NET Framework 4.6. Finally, we conclude this part with a language primer for those just getting started with .NET development. Readers who are familiar with prior versions of Visual Studio will want to review these chapters for the new additions in 2015.
Part II: An In-Depth Look at the IDE
This part covers the core development experience relative to Visual Studio. It provides developers with a base understanding of the rich features of their primary tool. The chapters walk through the many menus and windows that define each tool. We cover the base concepts of projects and solutions, and we explore in detail the explorers, editors, and designers.
Part III: Working with the Visual Studio Tools
Part III is the largest section of the book; it unlocks many of the powerful productivity features of Visual Studio 2015. These chapters investigate the developer productivity aids that are present in the IDE and discuss how to best use Visual Studio for testing, refactoring, debugging, and deploying your code. This part also covers building applications in Azure. The section concludes with a chapter dedicated to using Visual Studio to work with databases.
Part IV: Extending Visual Studio
For those developers interested in customizing, automating, or extending the Visual Studio IDE, these chapters are for you. We explain the automation model and then document how to use that application programming interface (API) to automate the IDE through macros. We also cover how you can extend the IDE’s capabilities by writing your own add-ins.
Part V: Building Web Applications
Part V is for web developers. We cover building applications with the new ASP.NET 5 (and MVC 6) model. This section also covers JavaScript and related client-side frameworks for building responsive, highly interactive client-side solutions. The section concludes with coverage on writing and consuming services using Web API and Windows Communication Foundation (WCF).
Part VI: Building Windows Client Apps
This section is targeted at developers looking to build applications for Windows. This includes the class Windows Forms. We also cover the powerful WPF and building Universal Application. Finally, this part includes a chapter dedicated to building custom solutions on Microsoft Office.
Part VII: Creating Mobile Apps
Here we cover creating mobile application for Windows Store, Windows Phone, and cross-platform (iOS, Android, and Windows Phone). This part is targeted at the mobile developer looking to either build on Windows or use the hybrid mobile technology, Apache Cordova.
Conventions Used in This Book
The following typographic conventions are used in this book:
Code lines, commands, statements, variables, and text you see onscreen appears in a monospace typeface. Placeholders in syntax descriptions appear in an italic monospace typeface. You replace the placeholder with the actual filename, parameter, or whatever element it represents.
Italics highlight technical terms when they’re being defined. A code-continuation icon is used before a line of code that is really a continuation of the preceding line. Sometimes a line of code is too long to fit as a single line on the page. If you see before a line of code, remember that it’s part of the line immediately above it. The book also contains Notes, Tips, and Cautions to help you spot important or useful information more quickly.