Now that Visual Studio 2010 is released, some of you might be itching to upgrade your existing VSTO projects so that you can take advantage of the new features in the .NET Framework 4 that improve the Office development experience. Or, you might have already started using Visual Studio 2010 to develop a VSTO project targets the .NET Framework 3.5, and now you want to switch over to the .NET Framework 4. The purpose of this post is to shed some light on scenarios where retargeting a VSTO project to the .NET Framework 4 can cause compile or run time errors in your project, and how to resolve these errors.
Retargeting a VSTO project to the .NET Framework 4 is pretty straightforward. If you created your project in Visual Studio 2010, you can retarget the project in the project properties by following the instructions here. If you are upgrading an existing project to Visual Studio 2010, you can choose to have the upgraded project target the .NET Framework 4 if the .NET Framework 3.5 is not installed on the computer; otherwise, you can always retarget it in the project properties later. For more information, see the “Retargeting During Project Upgrade” section in this blog post.
After you retarget your VSTO project, in many cases your work is done and you can jump right in and start writing code. However, for some projects – including any project that uses the Ribbon designer, any Outlook project that has a form region, and Excel and Word projects that use certain features such as smart tags and the GetVstoObject/HasVstoObject methods – you will get compile errors after you retarget the project, or the add-in might no longer run. In these scenarios, you must make some additional changes to your code. For the full list of scenarios that require code changes along with examples of the required changes, see the following MSDN articles:
- Required Changes to Run Office Projects that You Migrate to the .NET Framework 4
- Updating Excel and Word Projects that You Migrate to the .NET Framework 4
- Updating Ribbon Customizations in Office Projects that You Migrate to the .NET Framework 4
- Updating Form Regions in Outlook Projects that You Migrate to the .NET Framework 4
For step-by-step tutorials and “How do I?” videos that demonstrate several specific retargeting scenarios, see the following links:
- How Do I: Retarget an Outlook Add-In from .NET Framework 3.5 to .NET Framework 4?
- How Do I: Retarget a Word 2007 Add-In from .NET Framework 3.5 to .NET Framework 4?
- Migrating an Outlook Client to .NET Framework 4 in Visual Studio 2010 (Beth Massi).
When the VSTO team implemented support for the new “embedded interop types” feature (also sometimes referred to as “no-PIA”) of the .NET Framework 4, they had to also make some changes to the programming model of certain VSTO runtime features. For example, because the embedded interop types feature works only with interfaces, most types in the portion of the VSTO runtime that supports the .NET Framework 4 are now interfaces rather than classes. These and other changes have a trickle-down effect on some of the generated code and developer-written code in VSTO projects, and therefore require some manual code changes after you retarget a project.
If you’re interested in reading more about the embedded interop types feature in the .NET Framework 4 and the changes to the design of the Visual Studio 2010 Tools for Office runtime to support this feature, the following MSDN articles and blog posts.
- Design of VSTO 2010 runtime (Misha Shneerson)
- VSTO 2010 Runtime components explained (Aaron Cathcart)
- Why Should I Upgrade from .Net Framework 3.5 to .Net Framework 4? (Navneet Gupta)
- Upgrading VSTO Projects to use with Visual Studio 2010 (Navneet Gupta)