Book Image

Visual Studio 2013 Cookbook

Book Image

Visual Studio 2013 Cookbook

Overview of this book

Table of Contents (17 chapters)
Visual Studio 2013 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Project round-tripping


If you would like your .NET-based projects to be compatible with the previous versions of Visual Studio, be sure to choose a version of the .NET Framework that they support. For example, if you would like your project to support VS2010, be sure to target .NET 4.0, as .NET 4.5 is not compatible. Round-tripping is useful for situations where not all members of a development team have VS2013, as well as for situations when you wish to tread lightly on older projects.

Tip

As a friendly reminder, be sure that both versions of Visual Studio are up-to-date while sharing projects between VS2012 and VS2013. As noted in the While you were gone section of the Preface, this means Update 4 should be applied to VS2012.

In this recipe, we will discuss how projects can be shared across Visual Studio versions and a few details about how projects are handled.

Getting ready

The default .NET Framework in VS2013 is 4.5, so it is very easy to create a project that cannot open in VS2010. If you are not using any features specific to 4.5+, it is merely a matter of changing the project's properties to target 4.0. Keep in mind that some features will not be supported outright, but will be gracefully ignored.

Round-tripping is useful for a number of reasons. While supporting legacy projects, it is usually preferred to alter the existing code as little as possible. The support for older projects means that you can use VS2013 to edit them without keeping a copy of VS2012 installed. It also provides a way for users of VS2013 to work with fellow developers who are yet to upgrade from VS2012.

How to do it…

The best practice is to test upgrading on a backup of your legacy project. This way, you have an easy way to return to the status quo in the event of a failure or complication. Most projects will simply open without any complaint, especially those from VS2012 and, to a lesser extent, VS2010. If Visual Studio doesn't object, it is simply a manner of opening your old project in VS2013 and getting to work. Upon making edits and checking your code (if necessary), fellow developers running VS2010/VS2012 will have no difficulty making their own contributions.

How it works…

Visual Studio uses solution files to store details about the projects and solutions you create. Ending with the .sln extension, these files help Visual Studio manage your project. For example, a solution created in VS2012 has the following header at the beginning of its SLN file:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012 

By comparison, a solution created in VS2013 has this header as follows:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.20623.1 VSUPREVIEW
MinimumVisualStudioVersion = 10.0.40219.1

Note

The initial blank line is intentional for both examples.

The third line (prefaced with #) indicates the "human-readable" version of Visual Studio used to create the project. VS2013 projects add two additional lines to this header as shown in the preceding code snippet. The fourth line shows VisualStudioVersion, which specifies the full build version of Visual Studio used, while the fifth line lists the value MinimumVisualStudioVersion, which indicates the minimum version of Visual Studio that can be used to open the project.

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

There's more…

Not every project type supports round-tripping, as some require specific changes to be made in order to run under VS2013. Some notable project types and their exceptions are as follows.

Windows Store applications

Windows Store apps have some special requirements. Apps targeting Windows 8.1 require VS2013 and the underlying OS to be Windows 8.1. VS2013 can work with existing Windows 8 store apps if they were created by VS2012. As previously noted, Windows 8.1 will quickly replace Windows 8, so all new apps should target that platform.

The Model-View-Controller (MVC) framework

Visual Studio 2013 brings support for MVC 5 in addition to supporting MVC 4, while Visual Studio 2012 only supports MVC 3 and MVC 4. Visual Studio 2010 SP1 only supports MVC 2 and MVC 3. These limitations dictate whether or not your project will upgrade. However, there are tools and guidance on how to migrate your application to a newer version of MVC. Upgrading an MVC 2-based application to MVC 3 can be done with the standalone upgrade from CodePlex at http://aspnet.codeplex.com/releases/view/59008. Once this is completed, Microsoft provides guidance on upgrading the application from MVC 3 to MVC 4 at http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806. Unfortunately, the upgrade from MVC 3 to MVC 4 is a manual process.

MSI setup (.vdproj)

This project type refers to Visual Studio Installer projects, which are not supported in VS2013.

Upgrading an existing project

Depending on the nature of the solution or project you are working on, Visual Studio may require you to convert your project. You will be prompted to make a conversion decision, as shown in the following screenshot:

Tip

If you decide not to upgrade the project, you may do so later via Project | Upgrade Solution. As you may expect, the best practice is to perform a trial conversion on a copy of your solution in the event of something going wrong.

Creating a new project

Starting a new project in VS2013 remains unchanged from previous versions, but some of the available choices have changed. If you have not previously updated VS2012, one of the changes to notice is that VS2013 offers .NET Framework 4.5.1 as a framework that can be targeted. Some other new choices include templates to create apps for SharePoint and Office, as well as Python-based projects. See the Project round-tripping recipe for important considerations while creating projects that are destined to be edited in different editions of Visual Studio.