Click here to Skip to main content
15,901,122 members
Articles / Programming Languages / C#

Lessons Learned Migrating to Visual Studio 2012 and .NET 4.5

Rate me:
Please Sign up or sign in to vote.
4.94/5 (36 votes)
15 Mar 2013CPOL8 min read 194.3K   87   29
A collection of problems and solutions for migrating projects to Visual Studio 2012 and .NET 4.5.


This article is a collection of tips and tricks for migrating projects from Visual Studio 2008 to Visual Studio 2012. Migrating a large application (around 120 projects, 4MLO) written with C++, C#, C++/CLI and involving different technologies and frameworks, I have stumbled on different problems that I want to share, hopefully to make the transition easier for others. This article is not about new features in Visual Studio 2012 and .NET 4.5, it is about problems you might encounter when you migrate. Of course, these are not all the problems, but some that I can share from experience.

Some of the issues mentioned in this article are not specific to Visual Studio 2012 or .NET 4.5, but were actually introduced in Visual Studio 2010 and .NET 4.0. Therefore, if you are already familiar with this version, you probably know at least some of them.


Project Files

The first most important issue for VC++ projects is that the format of the project files has changed. In Visual Studio 2010, VC++ moved away from VCBuild and started using MSBuild. With this switched, the project files also changed to an MSBuild format. The new files have the extension .vcxproj, but there is an automatic conversion from the old .vcproj files to the new format. This can however lead to some warnings or even errors in the build.

One of the issues that I encountered was caused by the fact that I used to explicitly specify the Output File in the Linker settings. I used to do settings like $(OutDir)\MyAppD.exe in a Debug configuration and $(OutDir)\MyApp.exe in a Release configuration. That triggers some warnings:

1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(1137,5): warning MSB8012: TargetPath(D:\Marius\VC++\MFCApplication1\Debug\MFCApplication1.exe) does not match the Linker's OutputFile property value (D:\Marius\VC++\MFCApplication1\Debug\MyAppD.exe). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile). 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(1139,5): warning MSB8012: TargetName(MFCApplication1) does not match the Linker's OutputFile property value (MyAppD). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).

To fix this, the most appropriate solution is to use $(OutDir)$(TargetName)$(TargetExt) as the Output file and make the appropriate settings of these properties under the General page.

Image 1

Windows XP Support

The RTM release of Visual Studio 2012 has dropped support for targeting Windows XP and Windows Server 2003 for VC++ projects, requiring minimum Windows Vista and Windows Server 2008. After great demand, Microsoft has brought back the support for those operating systems in Update 1. By default, the toolset for VC++ projects is set to Visual Studio 2012 (v110), but after installing Update 1, a new toolset called Visual Studio 2012 - Windows XP (v110_xp) is available (installed side-by-side). Change to this toolset if you want to still target Windows XP/Windows Server 2003.

Image 2

However, you should notice that if your application is mixed and also using .NET, the 4.5 version also no longer supports these older operating systems. In this case, you either drop support for them, or do not migrate your managed projects to .NET 4.5. .NET 4.0 is the last framework version that supports those operating systems.


To my surprise, some important routines that were using CDatabase for SQL server access no longer worked and even crashed the application. Investigating the problems, I have discovered a couple of bugs in MFC:

Until fixes will be available, it is possible to work-around these problems by deriving your own class from CDatabase and:

  • provide another method for returning the connection string that is first decrypting an encrypted version of the connection string (CDatabase keeps one internally, but it's available for derived classes); I have proposed an implementation here.
  • override OpenEx() and make sure to have null pointers to released memory. I have proposed an implementation here.


For C++/CLI projects, it is not possible to specify the version of the .NET Framework you want to target from the IDE. The only available option is to manually set the desired value in the .vcxproj file. What you have to do is add a <TargetFrameworkVersion> element under <PropertyGroup Label="Globals">.

<PropertyGroup Label="Globals">

Regardless of whether you use .NET 4.0 or .NET 4.5 (which share the same 4.0 CLR), you may run into a runtime error like this:

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and 
cannot be loaded in the 4.0 runtime without additional configuration information.

That occurs when your application targeting CRL 4.0 tries to load a mixed-mode assembly (directly, or indirectly through one of the loaded modules) that is built with a previous version of the .NET framework that targets CLR 2.0 (or even 1.x). The problem occurs because .NET 4.0 has changed the way it binds to older mixed-mode assemblies. There are two possible fixes:

  • Make sure all the modules you load are targeting CLR 4.0; however, this might not be always possible, in which case
  • Add a fallback option in the application configuration file; the key here is the useLegacyV2RuntimeActivationPolicy attribute that must be set to true.
    <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0"/>

You can read more about this problem here.


Interop Assemblies

You may have projects that have references to COM servers, and therefore using interop assemblies, and code that may look like this:

using SomeLib;

namespace ClientApp
   class Program
      static void Main(string[] args)
         var o = new SomeLib.DummyClass();

When you migrate this to .NET 4.0/4.5, you get the following error:

1>[…]: error CS1752: Interop type 'SomeLib.TestClass' cannot be embedded. 
       Use the applicable interface instead.
1>[…]: error CS0143: The type 'SomeLib.TestClass' has no constructors defined

.NET 4.0 (and of course 4.5) allow embedding type information for COM types directly into managed assemblies instead of using an interop assembly (basically statically linking everything that is needed, instead of requiring an additional interop assembly) (see MSDN for details). However, this has some limitations, and one of them is that classes cannot be embedded. Detailed information about the problem can be found here.

There are basically two solutions:

  • Disable the embedding of interop assemblies; you can go to the properties page of a reference and set the Embed Interop Types to false;
  • Simply remove the Class suffix from the instantiated COM coclass.
    var o = new SomeLib.Dummy();

I would prefer the later, since it still leverages the benefit of embedding the interop types and making unnecessary the interop assemblies. (Notice that if you build COM components, primary interop assemblies for COM components are still necessary if you want your COM component to be consumed from applications using a previous version of the .NET Framework).


Applications using WPF need to add a new reference (in addition to PresentationCore, PresentationFramework and WindowsBase): System.Xaml.dll.


Visual Studio Setup Project is no longer available in Visual Studio 2012. If you have such projects, then you have several alternatives:

  • Continue to develop and build these projects with a previous version of Visual Studio;
  • Use InstallShield; a free, limited edition is available from Visual Studio and you can convert (with some tools) existing .vdproj files;
  • Use WIX (Windows Installer XML) toolset, but you need at least version 3.7, because this is the first one that supports Visual Studio 2012;
  • Use any other (free or commercial) tools for developing setup projects.

Which one should be the best option probably depends on various factors. I would personally prefer switching to WIX. The only feature that WIX is missing is handling pre-requisites, but you can use dotNetInstaller for that. A comparison of various deployment tools is available here.

Text Templates

Template assembly directives used to be resolved using project references. So if you had to reference an assembly called something.dll in a .tt file, you first had to add a reference to it and then use it in the assembly directive:

<#@ assembly name="something.dll" #>

In Visual Studio 2010, the way assembly directives are resolved has changed (the complete list of changes for T4 in Visual Studio 2010 can be found here). The T4 engine is now sandboxed to keep the T4 assemblies separate from the project assemblies. Therefore migrating T4 projects to VS2010/VS2012 may result in compiler errors. The possible solutions for this problem are:

  • Put the assembly in GAC and use namespace reference or fully qualified type name
  • Put the assembly in Visual Studio Public Assembly Folder and use namespace reference or fully qualified type name
  • Use fully qualified paths
  • Use a Windows Environment Variable to build fully qualified paths
  • Use Visual Studio macros to build fully qualified paths

You can learn more about the problem and the solutions here and here.


A first important aspect is even though you can still target Windows XP for native projects, remote debugging only works for Windows 7/Server 2008 R2 and newer operating systems. For all the previous versions (Windows XP, Windows Vista, Windows Server 2003 and Windows Server 2008), this feature is no longer available. You can check the platform compatibility and system requirements. If this is still important to you, then you must use the debugger from a previous version of Visual Studio (together with the remote tools).

Another feature that affects the debugging experience is that Visual Studio 2012 by default will try to load symbols for all modules from Microsoft symbol servers. The result is when the debugger attaches to a process, it takes a long time to load everything. That can vary from several seconds, to several minutes, depending how many symbol files it must download (the bigger the application and more modules it loads, the longer it takes).

Image 3

I recommend changing the default "All modules, unless excluded" to "Only specified modules". You can leave the list of specified modules empty, or you can specify the modules you want.


As mentioned in the beginning, this article is a collection of lessons learned migrating various projects from Visual Studio 2008 and .NET 3.5 to Visual Studio 2012 and .NET 4.5. You will probably encounter other problems too, but I hope this article can guide you in solving some of them.


  • 15th March, 2013: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Architect Visma Software
Romania Romania
Marius Bancila is the author of Modern C++ Programming Cookbook and The Modern C++ Challenge. He has been a Microsoft MVP since 2006, initially for VC++ and nowadays for Development technologies. He works as a system architect for Visma, a Norwegian-based company. He works with various technologies, both managed and unmanaged, for desktop, cloud, and mobile, mainly developing with VC++ and VC#. He keeps a blog at, focused on Windows programming. You can follow Marius on Twitter at @mariusbancila.

Comments and Discussions

QuestionUpgrade from VS6 to VS2010 - MFC C++ - CSocket with CSocketFile and CArchive Pin
razvandynalog3-Nov-15 7:03
razvandynalog3-Nov-15 7:03 
AnswerRe: Upgrade from VS6 to VS2010 - MFC C++ - CSocket with CSocketFile and CArchive Pin
razvandynalog5-Nov-15 8:36
razvandynalog5-Nov-15 8:36 
Question.Net Framework Initialization error Pin
Prakash12062-Nov-15 16:45
Prakash12062-Nov-15 16:45 
QuestionWarning C4407 after upgrade from MFC VC6.0 to MFC VS2012 Pin
DustinLe6-Sep-15 18:44
DustinLe6-Sep-15 18:44 
Questionapplication crashing after migrated to 2012 on windows 2012 server. Pin
Rajkumar Selvaraj11-Nov-14 17:11
Rajkumar Selvaraj11-Nov-14 17:11 
Questionneed help Pin
venkat.yva24-Oct-14 21:27
venkat.yva24-Oct-14 21:27 
AnswerRe: need help Pin
Garth J Lancaster25-Oct-14 0:05
professionalGarth J Lancaster25-Oct-14 0:05 
GeneralRe: need help Pin
venkat.yva26-Oct-14 2:41
venkat.yva26-Oct-14 2:41 
QuestionThanks.. more questions Pin
Amar S. Kumbhar14-May-14 20:42
Amar S. Kumbhar14-May-14 20:42 
AnswerRe: Thanks.. more questions Pin
Amar S. Kumbhar14-May-14 21:34
Amar S. Kumbhar14-May-14 21:34 
SuggestionAddition Pin
L Viljoen1-Apr-14 1:20
professionalL Viljoen1-Apr-14 1:20 
Questiongeneral settings for .lib targets Pin
Columbia280522-Jul-13 13:54
Columbia280522-Jul-13 13:54 
AnswerRe: general settings for .lib targets Pin
Marius Bancila22-Jul-13 19:33
professionalMarius Bancila22-Jul-13 19:33 
GeneralMy vote of 5 Pin
DevMarcus4-Jul-13 3:03
DevMarcus4-Jul-13 3:03 
QuestionNice experience Pin
Abhishek Sur24-May-13 12:03
professionalAbhishek Sur24-May-13 12:03 
GeneralMy vote of 5 Pin
rm82223-May-13 8:01
rm82223-May-13 8:01 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA12-Apr-13 19:00
professionalȘtefan-Mihai MOGA12-Apr-13 19:00 
QuestionUpgrading to VS 2012 Pin
geoyar29-Mar-13 9:57
professionalgeoyar29-Mar-13 9:57 
AnswerRe: Upgrading to VS 2012 Pin
Marius Bancila31-Mar-13 9:14
professionalMarius Bancila31-Mar-13 9:14 
GeneralRe: Upgrading to VS 2012 Pin
kabdolla20-Jun-13 5:21
professionalkabdolla20-Jun-13 5:21 
SuggestionDon't skip versions when updating projects Pin
jeffb4215-Mar-13 6:46
jeffb4215-Mar-13 6:46 
GeneralRe: Don't skip versions when updating projects Pin
kabdolla15-Mar-13 10:02
professionalkabdolla15-Mar-13 10:02 
GeneralRe: Don't skip versions when updating projects Pin
Marius Bancila15-Mar-13 11:14
professionalMarius Bancila15-Mar-13 11:14 
GeneralRe: Don't skip versions when updating projects Pin
jeffb4215-Mar-13 14:14
jeffb4215-Mar-13 14:14 
GeneralRe: Don't skip versions when updating projects Pin
Marius Bancila17-Mar-13 8:42
professionalMarius Bancila17-Mar-13 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.