Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
852 views
in Technique[技术] by (71.8m points)

visual studio 2010 - Using IWizard in an item template without installing assembly in GAC?

I would like to create a custom item template that includes a wizard (IWizard interface).

On http://msdn.microsoft.com/en-us/library/vstudio/ms171411%28v=vs.100%29.aspx and some other places it is always described that the assembly containing the wizard has to be installed in GAC. I would like to distribute my template in my organisation, and not everybody has right to install anything into GAC.

So I'm wondering, is there no way to have the assembly containing the wizard code inside the template zip, or vsix file?

It seems to me that this should be a common problem?

Any help how to distribute a custom wizard and item template without any GAC installations?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  1. the vsix project (we call it MyExtension)
  2. an item template project (we call it MyTemplate)
  3. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...