其他分享
首页 > 其他分享> > Add VS2012 compatibility for existing VS2010 extension packages

Add VS2012 compatibility for existing VS2010 extension packages

作者:互联网

原文链接:http://www.cnblogs.com/Cherubimlee/archive/2013/04/02/2995870.html

If you already created and are maintaining an amazing VSPackage in VS2010, and you want adapt your package to newer VS2012, meanwhile you want to keep your package works with both VS2010 and VS2012, the first idea come to my eye is to migrate all code from VS2010 to VS2012 and maintaining two versions of code, one for VS2010 and one for VS2012.

Right, it is correct and absolutely workable. However, maintaining two versions costs lot. You may ask, is there any other way to do that to make our life easier? The answer is “Yes”. In this blog, I will introduce a way to make VS2012 load the package which is designed for VS2010. And give a way to configure a debug environment which you can build your package using VS2010 (for compatible reason) and debug the package using VS2010 and VS2012 Exp Hive.

Adapt VSIX to be compatible with VS2010 and VS2012

As we know, starting with VS2010, it is recommend to use VSIX to deploy the VS Packages. VSIX is a zip based the package and it contains a XML based configuration file, vsixmanifest file. Normally we define the supported VS editions via vsixmanifest designer. If we right click on vsixmanifest file and view code, we can check all the xml configurations. For the supported VS editions, it looks like

 

    <SupportedProducts>

      <VisualStudio Version="10.0">

        <Edition>Pro</Edition>

      </VisualStudio>

    </SupportedProducts>

 

What we need to do is to add support for VS2012, which is version “11.0” as following:

    <SupportedProducts>      
       <VisualStudio Version="10.0">        
          <Edition>Pro</Edition>      
       </VisualStudio>      
       <VisualStudio Version="11.0">        
          <Edition>Pro</Edition>      
       </VisualStudio>    
    </SupportedProducts>

Now we can save and build the package. When we launch the VSIX, you we will find the VSIX will scan all installed VS (Both VS2010 and VS2012) and let you choose which version you will deploy the package.  

 

Configure a debug environment which you can build your package using VS2010 and debug the package using VS2010 and VS2012 Exp Hive.

Using above way we can deploy the package to VS2012, we can attach the debugger from VS2010 to VS2012 to debug the code for sure. However, for some reasons, we still want to debug our package on VS2012 Exp hive and make everything runs well before we deploy the package to VS2012 normal hive.

According to Dissecting VS 2010 Package Registration, the solution is given and the solution is also applied to VS2012. In addintion, we need to call devenv /rootsuffix Exp /Setup or devenv /updateConfiguration from VS2012 to make VS load our package. The steps summarized as

  1. Copy your package assembly to a subdirectory under …<user>\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions
  2. Create and copy a pkgdef and vsixmanifest to the same directory
  3. Launch VS2012’s devenv /rootsuffix Exp /Setup or  devenv /updateConfiguration
  4. Launch VS2012’s devenv with ‘/rootsuffix Exp’ command line switch
  5. Enable the package via the ‘Tools.Extension Manager’

Here devenv /updateConfiguration is an undocumented command line which is much faster than /Setup, but it will be subject to change and not guarantee to work with feature VS release. And I found enable package in one time action, we don’t need to uninstall it to update the code.

The solution is not too complex, we can create an after build script, either vbscript or msbuild to run these steps after we build the code in VS2010.

Above is all material today. Thank you for your time for my first VSX Blog. If you have any question or anything I’m wrong, please leave your comments/feedbacks or send email to me (Cherubimlee@hotmail.com)

A Chinese version will be post soon.

转载于:https://www.cnblogs.com/Cherubimlee/archive/2013/04/02/2995870.html

标签:extension,package,VS2012,VS2010,VS,Exp,your
来源: https://blog.csdn.net/weixin_30312659/article/details/99201735