VS2010对基于VS2008开发的VSIP可以说是完全兼容的,除了有些细节需要注意以外,只要做少量简单的修改就可以升级为新的VSIX,下面一一说明。

 

1.VSIP工程的Target framework改为.NET Framework 4.0。

使用4.0的Build引用,包括:Microsoft.Build、Microsoft.Build.Engine、Microsoft.Build.Framework、Microsoft.Build.Tasks.v4.0、Microsoft.Build.Utilities.v4.0。

 

2.安装VS2010 SDK。

VSIP工程添加部分VS2010必要的引用,包括:EnvDTE100、Microsoft.VisualStudio.Shell.10.0、Microsoft.VisualStudio.Shell.Immutable.10.0、Microsoft.VisualStudio.Shell.Interop.10.0。

 

3.VSIP工程的Package子类,只需对极少Attribute进行修改即可。

 移除DefaultRegistryRoot,ProvideLoadKey,比如:

[DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\9.0Exp")]
[ProvideLoadKey("Standard", "4.0", "Bingosoft Workflow Designer", "Bingosoft", 200)]

VS2010不再使用PLK了。

修改InstalledProductRegistration,VS2010废弃了其中两个构造函数。

如果VSIP工程实现了Editor,则需要注意一下ProvideEditorExtension,其构造函数的第三个参数priority的设置很可能导致Editor不能使用。比如我们品高工作流设计器之前在VS2008中设置的是32,升级VS2010后其他方面都进行了正确的设置,但却总是不能正确打开设计器,经过一一排查,终于将罪魁祸首锁定到这个Attribute上,修改priority值为50,问题解决。

 

4.VSIP工程添加Source.extension.vsixmanifest文件,内容形如:

<?xml version="1.0" encoding="utf-8"?>
<Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
  <Identifier Id="Bingosoft.Workflow.E72051F5-159C-4504-B7CE-49A4F55B89DB">
    <Name>Bingosoft Workflow Designer</Name>
    <Author>Bingosoft</Author>
    <Version>4.0</Version>
    <Description xml:space="preserve">Bingosoft Workflow Designer
Copyright (c) 2010 GuangZhou Microsoft Technology Center</Description>
    <Locale>1033</Locale>
    <Icon>Image_small.png</Icon>
    <PreviewImage>Image_large.png</PreviewImage>
    <SupportedProducts>
      <VisualStudio Version="10.0">
        <Edition>Pro</Edition>
        <Edition>IntegratedShell</Edition>
      </VisualStudio>
    </SupportedProducts>
    <SupportedFrameworkRuntimeEdition MinVersion="4.0" MaxVersion="4.0" />
  </Identifier>
  <References />
  <Content>
    <VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage>
    <ProjectTemplate>ProjectTemplates</ProjectTemplate>
    <ItemTemplate>ItemTemplates</ItemTemplate>
  </Content>
</Vsix>

其中Name、Author、Version设置的值将作为安装后的目录名,置于VS2010的Extensions目录下,形如:…Extensions\Author\Name\Version\…

 

5.如果VSIP工程使用了MPF,则需要将其升级到MPF10,参见http://mpfproj10.codeplex.com/

需要注意的地方是:

BuildItem的Include改为4.0的UnevaluatedInclude,FinalItemSpec改为4.0的EvaluatedInclude。

MPF10的ProjectNode默认使用的Async方式的Build,如果旧版的VSIP在Build时做了一些工作,则这部分代码需要修改。如果不需要支持Async方式的Build,则非常简单,直接override函数DoMSBuildSubmission,在其中调用以前的代码即可。

 

至此,VSIP升级到VS2010的工作基本完成,安装生成的VSIX,看看VS2010的Extension Manager中有没有出现您的插件吧!