Visual Studio 2017
by Tim Anderson
The latest version of Microsoft’s flagship development suite is here. Tim Anderson gives it the once-over.
HardCopy Issue: 71 | Published: May 10, 2017
Microsoft’s Visual Studio 2017 marks 20 years of Visual Studio, the first being Visual Studio 97 which bundled Visual C++, Visual Basic, Visual FoxPro, Visual J++ and Visual InterDev. It has become a remarkable development tool, not only for its comprehensive support for all Microsoft’s platforms, but also for its ability to target non-Windows operating systems, which goes well beyond previous releases.
Microsoft itself is in transition, with an increasing focus on cloud services such as Office 365 and cloud infrastructure in the form of Azure. Many Azure users run Virtual Machines (VMs) on Linux rather than Windows, and rather than resisting this trend, Microsoft has actively supported it, building partnerships with Linux vendors to improve integration. SQL Server is in the process of being ported to Linux, and the open source fork of .NET, called .NET Core, works on Linux as well as Windows. In the mobile area, Microsoft now has strong support for building cross-platform mobile apps with C# via its Xamarin tools. You can also use Apache Cordova or Visual C++ for iOS and Android.
Visual Studio also retains its traditional role as the primary development tool for the Windows platform. Microsoft has just completed the Windows 10 Creators Update, with new features including 3D and mixed reality support (new VR headsets from the likes of HP, Dell and Lenovo will democratise mixed reality experiences previously reserved for the high-end HoloLens devices); an improved Windows Subsystem for Linux; and better Ink support in UWP (Universal Windows Platform) apps. Visual Studio 2017 along with the updated Windows 10 SDK is the best development tool for Windows 10.
Visual Studio’s new installer
The most prominent new feature of Visual Studio is the installer. This is now a separate application and much quicker than previous versions. You can select either workloads, which bundle features together for targets such as desktop development, ASP.NET, UWP, SharePoint or Mobile; or you can select individual components such as specific versions of the .NET Framework, Git for Windows, or the Apache Cordova toolset.
You can also install different editions of Visual Studio side by side, and modify each one from the same installer. An Update button lets you bring previously installed instances up to date with the latest patch.
Businesses rolling out Visual Studio 2017 to a team of developers can create an offline installation for either the full product, or for the subset of workloads that the team needs.
Visual Studio is a highly modular developer tool. Understanding how to install the pieces you need can be confusing, since they might come from the installer, or from NuGet packages, or from Extensions and Updates which are accessed from the Visual Studio tools menu.
Worth noting is that, despite limited success to date, Microsoft is still pushing for greater adoption of UWP applications. In Windows 10 Creators Update, there is a new option to restrict application installs to Store-only. The idea is that Store applications are more trusted and better behaved, though this can now include Win32/Win64 applications that are wrapped with the Desktop Bridge (formerly known as Project Centennial). If this idea wins adoption, then it pays to develop UWP applications.
UWP applications also have a new feature in Windows 10 Creators Update, which is the ability to display a new view called CompactOverlay mode or Picture in Picture. This is an always-on-top view which is intended to pop up a small status window while your app is running, but the user is working primarily on something else. It is ideal for a chat application, for example.
This release of Visual Studio comes with the final 1.0 release of .NET Core and ASP.NET Core, the culmination of a long process to build a cross-platform version of the .NET Framework. The final release uses MSBuild for building projects, but with a simplified project format that can be edited manually, without unloading the project.
Deploying to containers
Containers are a popular choice in modern development because of their clean deployment model, easy scaling, and suitability for microservices, so it is no surprise to find Visual Studio 2017 having support for containers built in. When you create a new ASP.NET Core project, you can check the box for Docker support, although Docker for Windows does need to be installed separately from the Visual Studio installation. Visual Studio will then build a Docker image based on the YAML files in the docker-compose project that gets added to your solution. By default the Docker container (which is based on a Hyper-V VM) runs Linux rather than Windows, but everything works as you would expect and you can do line-by-line debugging. You can also set Docker to use native Windows containers.
When it comes to deployment, Visual Studio offers several choices. In preview is Azure App Service for Linux, which is an immediate deployment of a single container to Azure’s scalable app platform. Another option is to deploy to an Azure VM. You can also publish to files or to FTP servers for deployment to other platforms.
If you have a more complex solution, you can configure Azure to deploy from a Team Services repository. That way you can set up continuous integration using containers and Azure’s Container Service. At the time of writing this method only supports Linux containers and DCOS orchestration, but support for Kubernetes and for Windows containers is promised.
New editing features
The Visual Studio editor has some handy updates, such as Run to click. While debugging, it is common to want to execute a bit more code, but repeatedly stepping through with F10 or F11 can get tedious, for example if a loop is involved. In previous versions you can right-click and choose Run to cursor, to jump to some code after the loop, but now you can simply hover the mouse over a line of code and click a green arrow once to run to that point.
There is a new Go To All command (Ctrl-T) that lets you search a solution and filter the results by symbols, members, types and more. In addition, Find All References has been redesigned, and now offers grouping, filtering, sorting and searching within results.
What’s new in C# 7 and Visual Basic 15
The C# and VB languages have both been updated for Visual Studio 2017.
Value tuples let you return more than one value from a function. In order to use them, you need to add the Nuget package System.ValueTuple to your project.
You can now return values from functions by reference, a feature called ref returns.
Async methods return types are no longer restricted to Task or Task, though return types have to follow certain rules and have a [TaskLike] attribute.
Nested local functions (C# only) let you declare functions within a block. Delphi (Object Pascal) developers will recall being able to do this years back. Functions nested within other functions are private to the parent function and have access to local variables within that function. This can enable cleaner code, avoiding passing multiple arguments or declaring utility functions, especially in recursive processing.
Pattern matching expressions (C# only) extend the “is” operator to test expressions against patterns, a feature common in functional languages.
Binary literals let you define binary numbers using a prefix (0b in C#, &B in VB). You can use the underscore character as a separator for readability, with no semantic value.
A new feature called Structure Guidelines draws horizontal lines connecting each block of code. Hover your mouse over the line and it tells you what the block is, for example showing the namespace, the class and method.
The editor for F# is now based on Roslyn and has many new features, bringing it close to parity with C# and VB.
XAML editing in Visual Studio now supports Edit and Continue within UWP or WPF (Windows Presentation Foundation) applications. There is also smarter IntelliSense, and a Structure Visualizer that shows the context of each block of code without scrolling.
Visual Studio 2017 has a redesigned Exception Helper. This is the dialog that pops up during debugging if you hit an exception. In previous versions there was an Exception Assistant for managed code, and a modal Exception Dialog for unmanaged code. The new Exception Helper will break on the line of code where the exception occurred, even in unmanaged code. Null analysis will determine what is null for a NullReferenceException or Access Violation, where possible. The new dialog is resizable and can be pinned or floating. It also shows any Inner Exceptions immediately, without having to drill down. It is non-modal even for unmanaged code.
There are also a number of new refactorings for C# and Visual Basic. You can simplify object initialisation with an initialiser, which makes member assignments part of the new() statement. You can also add missing cases to a C# switch or VB Select; convert a property to a method or vice versa; make async methods synchronous where possible; convert String.Format to string interpolation (a feature new in C# 6.0); convert null checks to use the null-coalescing operator (a feature new in C# 7); and move “out” declarations inline (using another new C# 7 feature).
Targeting mobile devices
Xamarin for Visual Studio, Microsoft’s toolset for compiling for iOS and Android using C#, is now at version 4.3 and fully integrated with the new Visual Studio installer.
Since Microsoft’s acquisition of Xamarin in early 2016, the tools have continued their energetic development. Newer platforms such as Apple Watch, tvOS and Android Wear are supported, Visual Studio for Mac has been launched, and many bugs have been squashed. In February 2017, Microsoft said it had fixed 1,800 bugs in Xamarin Forms, the cross-platform version of XAML optionally used by Xamarin mobile applications. Compiled XAML is said to be five times faster than previously on iOS and Android. Xamarin Forms now supports Windows 10 UWP as well as mobile and there is also news that Xamarin Forms for the Mac will come later in 2017.
Xamarin Forms is less flexible than designing a custom user interface for each platform, but it is important to note that native platform widgets are still used, so it does retain the correct look and feel.
Most mobile applications are part of a larger project involving cloud-hosted services. In Visual Studio 2017, a new template called Cross-Platform App creates an end-to-end application with a backend service hosted in Azure and clients for Android, iOS and Windows 10 (UWP). The wizard prompts you to select an Azure subscription as well as giving options for additional services such as a SQL Server database. Once created, you can add further services including Application Insights for monitoring, Azure Storage, Office 365 and Azure Active Directory authentication.
The resulting solution has separate projects for iOS, Android and Windows, so you can decide whether code is shared by all the projects, or specific to a particular platform. The backend service is an ASP.NET MVC application, and the project supports two special controller types, Azure Mobile Apps Custom Controller and Azure Mobile Apps Table Controller, for connecting to data via the Entity Framework, or connecting to your custom Web API.
Microsoft has invested in cloud services for machine learning and artificial intelligence, in the belief that this will be increasingly important.
Cognitive Services is a set of currently 24 APIs divided into five categories:
- Vision: APIs for image recognition and content moderation. For example, you can upload an image and parse its content, and even recognise people in your organisation.
- Speech: convert text to speech or speech to text, and recognise who is speaking.
- Language: includes services for checking spelling, translating and analysing text.
- Knowledge: make personalised product recommendations, analyse academic papers, search structured data.
- Search: use Bing to search the internet for news, images, video or general web content.
Although these APIs are relatively new, and in some cases still in preview, they do a good job of democratising features that would previously have been out of reach for most developers.
Live Unit Testing
A powerful feature in Visual Studio 2017, though reserved for the Enterprise edition, is Live Unit Testing. Note that there are several additional requirements for this to work. Your project must use C# or Visual Basic and target the .NET Framework, not .NET Core. You must also use a supported Test Framework. In the case of Microsoft Test, you have to remove the default Microsoft.VisualStudio.QualityTools.UnitTestFramework and install the latest version of MSTest.TestFramework using NuGet. Finally, you have to ensure that the MSTest.TestAdapter package is added to the project.
When this is all done, and you Start Live Unit Testing from the Test menu, some magic happens. As you edit your code, a tick shows for code that passes tests, a cross for failures, and a blue horizontal bar for code not covered by any test. The tests do not execute immediately, but in the interim a small wait icon shows that re-test is pending.
A ‘bot’ is an application for which the user interface is language interaction. This could be in the form of text messaging, a widget on a website, or via a messaging service such as Skype or Facebook Messenger. Although the mechanics of a bot may seem simple, making them work involves at a minimum language parsing, and if speech input is required, speech recognition and text to speech services. Bot-style applications are likely to be increasingly important.
Microsoft has released a Bot Framework which, when combined with Cognitive Services, makes developing a bot relatively easy, though as ever there can be a lot of work involved in perfecting your bot or enabling more sophisticated interactions.
Microsoft has templates for bot applications and a NuGet package called Microsoft.Bot.Builder which you can add to your application. The essence of the Bot Framework is the ability to code dialogs, with the Framework providing a Context object for your dialog methods so you can review an earlier conversation and respond appropriately. You can use the Framework with an ASP.NET Web API application, so it should be familiar if you have worked at all with ASP.NET MVC.
Before firing up Visual Studio though, you probably want to create a LUIS (Language Understanding Intelligent Services) application so that your bot can interpret messages. A LUIS application is a cloud service customised to your needs. You create them by logging in at http://luis.ai. Once created, LUIS applications are composed of Intents, which represent actions or verbs, and Entities, which represent subjects and objects.
Imagine that you are creating an application that allows employees to check the price and stock of products while on the road. The Bot Framework supports SMS, so this could work hands-free while the employee is driving, assuming the phone has the ability to send texts via speech.
In the LUIS application therefore you might create Intents called CheckStock and CheckPrice, and an Entity called Product. Next you would add example statements, called Utterances, and show LUIS how to parse them. For example, the utterance “How many widgets are in stock?” is an example of the CheckStock intent and contains a Product entity.
A LUIS application has to be deployed, and there is a built-in process for deploying to Azure. A limited number of interactions are free, making it easy to build demos and prototypes.
Once you have set up LUIS, you can return to Visual Studio. Microsoft has templates for sending input to LUIS and creating dialogs based on its results. For example, you can create a CheckStock dialog that will be called whenever LUIS identifies a statement that looks like an attempt to check stock. If LUIS has already found a product entity, you might be able to respond immediately. Otherwise, you might need to ask a further question, such as “What is the product?” or “What is the product code?” Once the correct product is established, the application can look up stock levels in a database and return the results.
To publish your bot it has to be hosted somewhere that supports ASP.NET MVC, and again you have the option to use Azure. You also have to register the bot with Microsoft’s cloud service, giving the URL of the deployed service. Then you can set up a variety of channels, including Skype, web chat, email, SMS, Slack or, for integration with Office 365, Microsoft Teams.
Some of these channels are outside Microsoft’s control, so while the cloud service will handle the mechanics, you also need to register with the relevant third party and pass their approval procedures.
Although the Bot Framework simplifies bot development, it does require a different way of thinking as a developer. Instead of the security of input constrained to buttons, fields and checkboxes, you have language input that might be incorrectly parsed, especially if speech to text is added into the mix. If accuracy is critical, your application will probably need to verify actions with the user, using phrases such as, “I am going to order 500 of the widget product for customer X, is that correct?”
It is early days for bot development, but there is plenty of potential here for exploring new ways of interacting with applications.
Licensing Visual Studio 2017
This is a complex subject and it’s worth speaking to a reseller such as Grey Matter to find out which is best for you. Visual Studio comes in a number of different editions.
- Visual Studio Professional is fully licensed for commercial use and includes Team Foundation Server (TFS) and Team Services support, though the standalone licence does not include a TFS CAL (Client Access Licence).
- Visual Studio Professional with MSDN includes a full commercial IDE licence, as well as access to Windows Desktop, Windows Server, SQL Server, Azure credits for testing and development, and a TFS CAL.
- Visual Studio Enterprise with MSDN adds comprehensive test support. You also get the Redgate Data Tools, architecture diagrams and lab management support, together with Xamarin Profiling and Test Recorder. Each Enterprise licence comes with a Concurrent Pipeline licence for TFS, enabling multiple simultaneous builds and parallel build agents, together with access to over 11 terabytes of Microsoft software.
- Visual Studio Test Professional with MSDN is not designed for development, but gives full support for test case management, lab management and TFS testing and reporting.
- Visual Studio Community is free and relatively full featured, though there are some features missing including TFS integration and built-in version control. There are limitations to using this edition in a production environment.
Most Visual Studio licences come as subscriptions, though you can purchase Visual Studio Professional as a standalone licence.
- Standalone Licence: Visual Studio Professional only, no TFS CAL included.
- Standard Subscription (formerly MSDN subscription): The Visual Studio Professional version includes a TFS CAL, Azure credits, and access to products such as Windows Server, SQL Server and Windows. The Enterprise version adds Office and more options for testing and development. Your Visual Studio licence does not expire with the subscription.
- MSDN Platforms: Available exclusively through volume licensing, this does not include the Visual Studio IDE. Rather, it offers a full range of Microsoft products such as Windows Server, SQL Server, Windows and Office for development and testing, $100 of Azure credits per month, use of Visual Studio Team Services, and a licence for Team Foundation Server with one CAL.
- Cloud Subscription: For either Visual Studio Professional or Enterprise, including a TFS CAL. Available on a monthly or yearly basis, although access to Microsoft platform software and Azure credits only applies to annual subscriptions. Your Visual Studio licence does expire with the subscription.