Develop Office Client Applications using Visual Studio
Visual Studio 2008 allows a developer to create add-in projects that target Microsoft Office 2003 products even if Microsoft Office 2007 rather than Microsoft Office 2003 is installed. So long as you don’t close and reopen the project, everything works fine. If you close the project and attempt to reopen it, however, you’ll be asked to upgrade the project. Now, at first glance, this seems to be pretty unreasonable. Moreover, Visual Studio’s Conversion Wizard would have you believe the project you are trying to open needs to be upgraded because the project targets a prior version of Visual Studio. That's just confusing. The Conversion Wizard is actually displaying canned text that it shows for any type of project conversion, for example an old C++ console application project from VS 2005. The good news is that there is a way to fix your problem and let you continue working on your Office 2003 project. In this blog post, I’ll walk through the problem, give you the way out, and then very briefly comment on the reasoning behind the upgrade solution and some of its quirks.
Let's say you want to work on an Office 2003 solution in Visual Studio 2008. Great! Let's say that you also have Office 2007 installed. You can start creating a new Office 2003 add-in using the New Project dialog, below, an Excel 2003 Add-in is being created.
When Visual Studio finishes creating the project, you’ll see something like the following:
Notice that in this case, there are a couple of warnings regarding the lack of registered primary interop assemblies for Microsoft Office Excel 2003. In order to run and debug the project, I would need to install them on my system (and Office 2003 as well), but otherwise, creation of the project is successful and you can compile and deploy the project.
But now, if you close and reopen the project, you’ll see the Visual Studio Conversion Wizard below. That’s odd, you could create the project, compile it, deploy it, and maybe run and debug it (if the primary interop assemblies are installed and registered) but now you’re being asked to upgrade? What’s going on here?
The answer is that when Visual Studio opens a project, it asks the project’s project system what it thinks about the state of the project. If the project system thinks the project needs updating for any reason, the project system can reply to Visual Studio that an upgrade is required. In this case, the Office Tools project system has decided that the project needs to be updated because the project targets a version of Office that is different from that installed. Retargeting the Office version might be what you want, but in this case it isn’t.
So how does one stop this behavior? Well, that turns out to be pretty easy. In Visual Studio’s Options dialog (Tools|Options), there is a category expander called Office Tools. One of the items under this category is Project Upgrade. After selecting the Project Upgrade item, you’ll be greeted by the Project Migration Scheme options dialog. The very last option on this dialog is Always upgrade to installed version of Office. And here is the problem. Since it is currently checked (in the example below), the Office Tools project system will always signal to Visual Studio that an Office 2003 add-in needs to be upgraded if Office 2007 (or any other version of Office, for that matter) is installed.
Un-checking the option will solve the problem and Visual Studio will happily open the project without attempting to upgrade it first. If at some later time, you wish to upgrade the project to target a later version of Office, just re-check the option and the next time you try to open the project you’ll be greeted again by Visual Studio’s Conversion Wizard.
For the preceding discussion, we talked only about what happens when you create a new add-in using Visual Studio 2008 that targets Office 2003. What about add-ins that were created using Visual Studio 2005 and the Tools for Office Special Edition? In this case, if you open the project, it must be upgraded to Visual Studio 2008. At the same time, if the Always upgrade to installed version of Office option is checked, the Office target will be changed too. If this is not the behavior that you want, make sure the option is unchecked and allow the upgrade to complete. The project will be brought up to Visual Studio 2008, but the Office version will continue to target Office 2003.
At the point where the Conversion Wizard is polling the project system regarding whether or not an upgrade is required, we are unable to offer a dialog box to you. Otherwise, we would simply raise a Yes/No/Cancel dialog and allow you to select what behavior is appropriate for targeting the Office version. While I could give you a long technical explanation of why we’re unable to pop up a dialog at that moment, let me say instead that our team honestly spent weeks hashing through this problem trying to find a better solution. The short answer is that it would require significant architectural changes that were considered too risky. After all, Visual Studio is a huge application, and we try very hard to mitigate risk and maintain high quality. We’re still looking at this issue and possible architecture changes for the next version of Visual Studio.
-Anthony Crider, Principal Software Developer
Tony Crider blogs on how you can get Visual Studio to stop bugging you to upgrade an Office 2003 project
Stellen Sie sich vor, Sie haben ein VSTO 2005 SE Projekt mit Visual Studio 2005 und wollen auf Visual
原文作者：Anthony Crider 原文链接：http://blogs.msdn.com/vsto/archive/2008/05/23/vs-2008-makes-me-upgrade-my-office-2003-add-in-but-i-don-t-want-to-anthony-crider.aspx
Thanks a lot! This was happening for me and i couldn't figure out for the life of me why!!
Hello MSDN.com - can you restore the images please!!!!