简体   繁体   English

VS2012模板向导-GUI不显示

[英]VS2012 template wizard - GUI not showing

I'm having problems having my visual studio template wizard's gui showing up. 我在显示我的Visual Studio模板向导的GUI时遇到问题。 I followed these steps: http://msdn.microsoft.com/en-us/library/ms185301.aspx 我按照以下步骤操作: http : //msdn.microsoft.com/en-us/library/ms185301.aspx

Here's what I did: 这是我所做的:

1) Generated a C# class library (.dll) with the following files: 1)生成具有以下文件的C#类库(.dll):

UserInputForm.cs UserInputForm.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace myprojectvstemplate
{
    public partial class UserInputForm : Form
    {
        private string customMessage;

        public UserInputForm()
        {

            InitializeComponent();
            MessageBox.Show("here, calling ui");
        }

        public string get_CustomMessage()
        {
            return customMessage;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            customMessage = textBox1.Text;

            this.Dispose();
        }
    }
}

2) Added a user input form with a editbox and a combobox with code UserInputForm.cs 2)添加了一个带有编辑框的用户输入表单和一个带有代码UserInputForm.cs的组合框

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TemplateWizard;
using System.Windows.Forms;
using EnvDTE;

namespace myprojectvstemplate
{
    public class IWizardImplementation : IWizard
    {
        private UserInputForm inputForm;
        private string customMessage;

        // This method is called before opening any item that 
        // has the OpenInEditor attribute.
        public void BeforeOpeningFile(ProjectItem projectItem)
        {

        }

        public void ProjectFinishedGenerating(Project project)
        {

        }

        // This method is only called for item templates,
        // not for project templates.
        public void ProjectItemFinishedGenerating(ProjectItem
            projectItem)
        {

        }

        // This method is called after the project is created.
        public void RunFinished()
        {

        }

        public void RunStarted(object automationObject,
            Dictionary<string, string> replacementsDictionary,
            WizardRunKind runKind, object[] customParams)
        {


            try
            {
                // Display a form to the user. The form collects 
                // input for the custom message.
                inputForm = new UserInputForm();
                inputForm.ShowDialog();

                customMessage = inputForm.get_CustomMessage();

                // Add custom parameters.
                replacementsDictionary.Add("$custommessage$",
                    customMessage);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        // This method is only called for item templates,
        // not for project templates.
        public bool ShouldAddProjectItem(string filePath)
        {

            return true;
        }
    }
}

3) generated a public/private strong key and registered the assembly from the "signing" tab in the property page 3)生成了一个公共/私有强键,并从属性页的“签名”选项卡中注册了程序集

4) Release-generated the dll 4)发布生成的dll

5) registered it with gacutil /i mydllname.dll, no errors 5)使用gacutil / i mydllname.dll注册了它,没有错误

6) Created a C++ console project template with just one file: 6)使用一个文件创建了一个C ++控制台项目模板:

#include <iostream>
using namespace std;


int main(int argc, char** argv)
{

    cout << "Hi hello world:" << "$custommessage$";

    return 0;
}

7) Exported as a template project (not item) with checkbox on "import automatically into vs". 7)导出为模板项目(而非项目),并带有“自动导入vs”中的复选框。 Modified inside the zip file the .vstemplate file like this: 在zip文件中修改.vstemplate文件,如下所示:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
  <TemplateData>
    <Name>myproject_project</Name>
    <Description>&lt;No description available&gt;</Description>
    <ProjectType>VC</ProjectType>
    <ProjectSubType>
    </ProjectSubType>
    <SortOrder>1000</SortOrder>
    <CreateNewFolder>true</CreateNewFolder>
    <DefaultName>myproject_project</DefaultName>
    <ProvideDefaultName>true</ProvideDefaultName>
    <LocationField>Enabled</LocationField>
    <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
    <Icon>__TemplateIcon.ico</Icon>
  </TemplateData>
  <TemplateContent>
    <Project TargetFileName="myproject_project.vcxproj" File="myproject_project.vcxproj" ReplaceParameters="true">
      <ProjectItem ReplaceParameters="false" TargetFileName="$projectname$.vcxproj.filters">myproject_project.vcxproj.filters</ProjectItem>
      <ProjectItem ReplaceParameters="true" TargetFileName="myproject_project.cpp">myproject_project.cpp</ProjectItem>
      <ProjectItem ReplaceParameters="false" TargetFileName="ReadMe.txt">ReadMe.txt</ProjectItem>
    </Project>
  </TemplateContent>
  <WizardExtension>
    <Assembly>myprojectvstemplate, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=a0a3d031ed112d61</Assembly>
    <FullClassName>myprojectvstemplate.IWizardImplementation</FullClassName>
  </WizardExtension>
</VSTemplate>

Unfortunately when I try to create a new template project the UI is not displayed at all. 不幸的是,当我尝试创建一个新的模板项目时,UI根本没有显示。 The project is just opened and there's no substitution of the $custommessage$ parameter. 该项目刚刚打开,没有任何替代$ custommessage $参数。

Why can't I show my wizard's GUI? 为什么我不能显示向导的GUI?

Additionally: is there any way to debug why the assembly isn't being loaded?? 另外:有什么方法可以调试为什么不加载程序集?

Probably the assembly with the wizard implementation is not found. 可能找不到带有向导实现的程序集。

In the WizardExtension section you should write exact your assembly and class name. 在WizardExtension部分中,您应该确切地输入程序集和类名。

Of course, this assembly should be in the extension directory or registered in GAC. 当然,该程序集应该在扩展目录中或在GAC中注册。

<WizardExtension>
    <Assembly>myprojectvstemplate, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=a0a3d031ed112d61</Assembly>
    <FullClassName>myprojectvstemplate.IWizardImplementation</FullClassName>
</WizardExtension>

Thanks, Serge 谢谢,谢尔

I had the same problem as the OP, following the same tutorial. 按照同一教程,我遇到了与OP相同的问题。

The solution I found was this: 我发现的解决方案是这样的:

In the Modifying The Template section, 在“ 修改模板”部分中,

Step 2 extract the zip file into a folder and delete the zip file . 步骤2将zip文件解压缩到文件夹中,然后删除该zip文件 Then modify the vstemplate. 然后修改vstemplate。

Finally try the wizard in a new instance of VS. 最后,在新的VS实例中尝试使用向导。

I don't know if this is the proper solution, but this is what worked for me. 我不知道这是否是正确的解决方案,但这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM