Search code examples
visual-studio-extensionsvsixenvdtevs-extensibilityvisual-studio-sdk

Typecast fails when visual studio extension uses reference to older assembly


I'm writing a Visual Studio extension that references the Microsoft.VisualStudio.VCProjectEngine assembly.

Now I'm trying to cast from EnvDTE.Project to Microsoft.VisualStudio.VCProjectEngine.VCProject like this:

VCProject vcProject = project.Object as VCProject;

This cast works fine when building and running my extension in Visual Studio 2015 while using the version 14.0 of the VCProjectEngine assembly. However the cast fails when I'm changing the version to 12.0 so that my extension can be installed to VS2013 as well. There must be something I'm missing here.

How can I reference the VCProjectEngine assembly so that my typecast works in VS2013 and VS2015?


Solution

  • This assembly really has different versions for different VS versions,each version of VS need to reference the respective assembly.

    Reference:

    https://social.msdn.microsoft.com/Forums/en-US/d47bfe90-19bb-4c0c-9f36-74ff60eb490d/vcproject-interface-targeting-multiple-versions?forum=vsx