Changes to VC++ in Microsoft Visual Studio 2010

Visual Studio 2010 which is due to release soon comes with a series of changes when it comes to Visual C++. In this article I will talk about some of them, arguably the most important ones: the build system and IntelliSense.

In order to show the changes I will create two simple projects, one in Visual Studio 2008, called Wordpad 2008, and one in Visual Studio 2010, called Wordpad 2010. These would be simple MFC single document applications. The image bellow shows the two solutions opened in Solution Explorer.

As you can see both versions contain the same solutions file (only the suffix in the name differs). The next image shows the files on disk, in comparison for the two solutions.

MS-Build System

The first thing to notice (though it might not be the obvious) is that the project file extension was modified. In Visual Studio 2008 it is called .vcproj, but in Visual Studio 2010 is called .vcxproj. Not only the extension changed, but also the content of the file. This is because in Visual Studio 2010, Visual C++ build system was changed from VCBuild to MSBuild. This build engine was already used for the languages targeting the .NET framework.

MSBuild uses XML project files, and the most important elements of a project are:

  • Items: units of input into the build system, grouped into item collections, which can be used as parameters to the tasks, using the syntax @(ItemCollectionName). Examples of items from the Wordpad2010 project:
      <ItemGroup>
        <None Include="ReadMe.txt" />
        <None Include="res\Wordpad2010.ico" />
        <None Include="res\Wordpad2010.rc2" />
        <None Include="res\Wordpad2010Doc.ico" />
      </ItemGroup>
      <ItemGroup>
        <ClInclude Include="MainFrm.h" />
        <ClInclude Include="Resource.h" />
        <ClInclude Include="stdafx.h" />
        <ClInclude Include="targetver.h" />
        <ClInclude Include="Wordpad2010.h" />
        <ClInclude Include="Wordpad2010Doc.h" />
        <ClInclude Include="Wordpad2010View.h" />
      </ItemGroup>
      <ItemGroup>
        <ClCompile Include="MainFrm.cpp" />
        <ClCompile Include="stdafx.cpp">
          <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
          <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
        </ClCompile>
        <ClCompile Include="Wordpad2010.cpp" />
        <ClCompile Include="Wordpad2010Doc.cpp" />
        <ClCompile Include="Wordpad2010View.cpp" />
      </ItemGroup>
      <ItemGroup>
        <ResourceCompile Include="Wordpad2010.rc" />
      </ItemGroup>
    
  • Properties: pairs of key/value used to configure the builds. The value of a property can be changed after it was defined. They can be referred in the project file using the syntax $(PropertyName). Examples of properties from the Wordpad2010 project.
      <PropertyGroup Label="Globals">
        <ProjectGuid>{1E7DC2AA-8CAC-44A8-98F6-DE69249AD30C}</ProjectGuid>
        <RootNamespace>Wordpad2010</RootNamespace>
        <Keyword>MFCProj</Keyword>
      </PropertyGroup>
    
  • Tasks: reusable units of executable code used to perform builds. Example of tasks can be compiling input files, linking, running external tools. Tasks can be reused in different projects.
  • Targets: represent groupings of tasks in a particular order and expose parts of the project file as entry points into the build system.

You can get a deeper overview on the MSBuild engine here.

Another thing to notice is the presence of a file called Wordpad2010.vcxproj.filters. This file defines the solution explorer tree with the files contained in the project. This used to be a part of the file project, but in Visual Studio 2010 it was moved into a separate file. The reason is to keep the project file only for the build, not for the organization of the project.

The user specific settings used to be stored in a file called ProjectName.vcproj.fullyqualifiedusername.user. Now there is a new file called ProjectName.vcxproj.user.

To summarize on the most important changes to the project files:

  • .vcxproj has replaced .vcproj as the project file and only contains information about the build.
  • .vcxproj.user has replaced .vcproj.user and contains the user specific settings.
  • .vcxproj.filters was added to store the definition of the Solution Explorer tree of project items.
  • .props (not seen in my example) has replaced .vsprops, an XML file called project property sheet, allowing to specify switches for the build tools and create user-defined macros.

You can read more about these changes in MSDN.

Multi-targeting

The previous version of Visual Studio has introduced a the possibility to target different versions of the .NET framework. Using Visual Studio 2008 one could build the same project with .NET 2.0, 3.0 or 3.5. As a result of the changes to the build system and project system, the new version introduces a similar feature for Visual C++. There are two types of multi-targeting: native and managed.

The managed multi-targeting allows to target different versions of the .NET framework for mixed-mode applications. This is actually not new, it was introduced in Visual Studio 2008 with the support for .NET multi-targeting. By default the target version is the latest, 4.0. Unfortunately, by design, this can only be changed manually in the project file. The support for changing this from the IDE was not included in this version. Actually it was dropped, because in Visual Studio 2008 this was possible.

  <PropertyGroup Label="Globals">
    <ProjectGuid>{AB3D9231-F8B6-4EAD-A15B-C792977AB26E}</ProjectGuid>
    <RootNamespace>MixedModeDemo</RootNamespace>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <Keyword>MFCDLLProj</Keyword>
  </PropertyGroup>

The native multi-targeting allows to use different versions of the tools and libraries to build (native) C++ projects. Of course, you must have the targeted toolset installed on your machine, in order to do that. You can define different configurations that target different versions of the toolsets. The targeted toolset can be changed from project's properties page, General, Platform Toolset. The following image shows the available options on a machine with Visual Studio 2008 SP1 and Visual Studio 2010 installed side by side.

It is possible to target the previous version, 2008, 2005, 2003 and 2002. In theory it's possible to target even VC6, but there is no support from Microsoft for that.

You can read more about native multi-targeting here, and about managed multi-targeting, for mixed-mode applications, here.

IntelliSense and Browsing

A second important thing to notice in the comparison of the two solution is that the infamous .NCB file is no longer present in Visual Studio 2010 solution. Instead there is a new file with extension .SDF. This is not just a renaming of the extension, the entire Intellisense for Visual C++ was redesigned in Visual Studio 2010. This is a SQL Server Database file, possible to be opened even in Visual Studio (if one wants to check its content).

In the previous versions of Visual C++, each time you modified a header, the entire solution was reparsed, in which time it was very hard to use the environment. Moreover, the IntelliSense database file (the .NCB file) never seem to shrink, only increased in size, and it could get corrupted from time to time. In the new version, files are parsed on the background, and the IDE does not read all the files, only the current translation unit (which is a source file and all the headers it includes directly and indirectly). As a result, the operation is much swifter and less error prone.

There is also a new disk folder called iPCH in the new solution. This is the storing location for IntelliSense support files and browsing database files (SDF).

#include auto completion

Part of the new IntelliSense and Browsing experience, the #include keyword supports auto-completion for the header files. That means that after typing #include, the IDE displays a list of available headers, filter by their name as you type. The following image shows this.

Call Hierarchy

This features enables navigation through the code, showing the calls to and from a selected method, constructor or property. When selecting a call in the hierarchy window it shows the code where the call is made.

Red Squiggles

This is a feature that enables highlighting syntactic and semantic errors with a red squiggle line. Hovering the mouse over the line will show a balloon with the error message. The same error is also listed in the Error List window.

Find All References

In the previous versions, this features displayed only the compiler verified results for a search. If you searched for a function M member of a class C it only returned the references where function M was used in the context of C. The new version allows two types of search: one that is focus on speed, and returns all the matches for a symbol regardless the context (but it's a narrowed search than the one performed with Find in Files), and one that is focused on accuracy and returns only the compiler verified results (i.e. the ones that match the search context).

Class Wizard

The famous and acclaimed class wizard from VC6, that was dropped in Visual Studio 2002 was brought back in Visual Studio 2010.

For those familiar with VC6, you know what to expect. It's basically the same functionality, improved with search functionality. For those not familiar with VC6 this is a single point to add or remove commands, message handlers, virtual functions, member variables and methods. This was a favorite feature in VC6 for a lot of people and there was a constant pressure on Microsoft to bring it back, so here it is.

Conclusions

This article touches some of the new features or changes to Visual Studio 2010 in regard to Visual C++, especially the new build system and the IntelliSense and browsing experience. There is more to talk about changes to C++, MFC or deployment, but that will make the topic of other articles.

References

For more information on these topics see also:



About the Author

Marius Bancila

Marius Bancila is a Microsoft MVP for VC++. He works as a software developer for a Norwegian-based company. He is mainly focused on building desktop applications with MFC and VC#. He keeps a blog at www.mariusbancila.ro/blog, focused on Windows programming. He is the co-founder of codexpert.ro, a community for Romanian C++/VC++ programmers.

Downloads

Comments

  • VS2010 Bugggy to the point of beignb usless

    Posted by brianm101 on 10/12/2010 06:07am

    Pity VS2010 is just so buggy - even an MFC program created using the wizard crashes VS2010.
    
    Main problem with VS series is they keep re-inventing the wheel, and each time it take a while for the wheel to be made round again (so  you get a smooth ride)! 
    
    Took a while for VS 6 to be become usable, same for VS2008.  Allow to mature for 2 years before using!

    Reply
  • What about CLR ?

    Posted by jimocz on 09/27/2010 03:36pm

    As far as I am concerned the Intellisense of VS 2010 is broken. When using the clr flag (mixing managed and native code) in C++ the intellisense is not designed to work. This is a feature not a bug. So I use VS2008. Also intellisense does not work when using relative paths in the include directories. This makes things harder when moving code between systems. All in all I am disillusioned about 2010.

    • Re: What about CLR ?

      Posted by cilu on 09/28/2010 02:17am

      Yes, Intellisense for C++/CLI is not supported in VS2010, and yes, this is a feature. Hopefully this will change in the next version. In the meanwhile you'll have to use a 3rd party solution for that.

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds