After a lot of research, I found a way to do that. With this method it is possible to include the assembly with the IWizard implementation into the VSIX file, even without signing it, and having it available at runtime. No need to fiddle with the GAC.
You need 3 projects in your solution
- the vsix project (we call it MyExtension)
- an item template project (we call it MyTemplate)
- a regular class library project for the wizard code (we call it MyWizardImpl)
Inside MyWizardImpl you need to implement the IWizard interface, in an arbitray class. (we call it MyWizardImpl.ItemTemplateWizard1). When compiling this, you get as output
<solutiondir>MyWizardImplinDebugMyWizardImpl.dll
Now, in MyTemplateMyTemplate.vstemplate, you need to reference it
<WizardExtension>
<Assembly>MyWizardImpl</Assembly>
<FullClassName>MyWizardImpl.ItemTemplateWizard1</FullClassName>
</WizardExtension>
The tricky part comes last: Including the assembly inside the vsix in a way that it can be loaded when the ItemTemplate is applied.
- Create a folder MyExtensionAssemblies
- In solution explorer, Right-click that folder and choose Add -> Existing Item...
- In the "Add existing Item" dialog, navigate to the created MyWizardImpl.dll. On the Add button, click on the little arrow and choose "Add As Link" (to prevent that VS makes a copy of the dll)
- In the properties for this link, choose BuildAction=Content, IncludeInVSIX=True
- Open the vsixmanifest in a XML editor (or notepad), and add an Assembly line to the section
Example:
<Content>
<Assembly AssemblyName="MyWizardImpl">AssembliesMyWizardImpl.dll</Assembly>
</Content>
Build and test the solution, the wizard code should run now when using the template.
If you need more than one template in your vsix, you simply need to add additional ItemTemplate projects. All the wizards can go into the same MyWizardImpl assembly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…