Search code examples
c#mefvsix

C# VSIX Project template with MEF editor extension


I am trying to create a VSIX extension using VS 2013 that contains two projects (and the package project itself, all three projects belong to the same solution). One of the projects is a usual Project Template, and the other is a MEF editor extension (custom code highlighter, can be compiled as separate vsix). Now I want to combine these projects in one extension, and make my code highlighter work only in scope of Project Template (when it used as a new project later, when installed), but not in global scope (for any new project type). Is it possible?

Vsix manifest code:

<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
  <Metadata>
    <Identity Id="27a359e4-cefd-47c0-a02b-3454284a7a46" Version="1.0" Language="en-US" Publisher="ladybug" />
    <DisplayName>TestPackage</DisplayName>
    <Description>TestInformation</Description>
    <Icon>Resources\Package.ico</Icon>
  </Metadata>
  <Installation InstalledByMsi="false">
    <InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[12.0,]" />
    <InstallationTarget Version="[12.0,]" Id="Microsoft.VisualStudio.Ultimate" />
  </Installation>
  <Dependencies>
    <Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[3.5,)" />
    <Dependency Id="Microsoft.VisualStudio.MPF.12.0" DisplayName="Visual Studio MPF 12.0" d:Source="Installed" Version="[12.0,]" />
  </Dependencies>
  <Assets>
    <Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
    <Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" Path="|CodeHighligherClassifier|" />
  </Assets>
</PackageManifest>

This combined package compiles without errors, but I'm unable to install it:

Install Error : System.NullReferenceException: Object reference not set to an instance of an object
   in Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForValidDotNetFramework(IExtension extension)
   in Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForInstallBlockers(InstallableExtensionImpl extension, IInstalledExtensionList modifiedInstalledExtensionsList, Boolean isNestedExtension, Boolean& olderVersionInstalled)
   in Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallInternal(InstallableExtensionImpl extension, Boolean perMachine, Boolean isNestedExtension, IDictionary`2 extensionsInstalledSoFar, List`1 extensionsUninstalledSoFar, IInstalledExtensionList modifiedInstalledExtensionsList, AsyncOperation asyncOp, UInt64 totalBytesToWrite, UInt64& totalBytesWritten)
   in Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.BeginInstall(IInstallableExtension installableExtension, Boolean perMachine, AsyncOperation asyncOp)
   in Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallWorker(IInstallableExtension extension, Boolean perMachine, AsyncOperation asyncOp)

What may cause this error (removing Dependency Id="Microsoft.Framework.NDP" solves it, but I'd like to leave it)?


Solution

  • I had an error with the same stack trace. It was caused by this line in extension.vsixmanifest:

    <SupportedFrameworkRuntimeEdition MinVersion="2.0" />
    

    The problem is that I didn't specify a MaxVersion, and there is bad code in Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForValidDotNetFramework that attempts to check the maximum version without first testing to see if it is null. The solution was to change that line to:

    <SupportedFrameworkRuntimeEdition MinVersion="2.0" MaxVersion="99.99" />
    

    Another team also had a similar problem:

    http://www.grasshopper3d.com/forum/topics/error-installing-gh-visual-studio-package