VS2012 template wizard - GUI not showing
Asked Answered
L

2

6

I'm having problems having my visual studio template wizard's gui showing up. I followed these steps: 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:

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

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

4) Release-generated the dll

5) registered it with gacutil /i mydllname.dll, no errors

6) Created a C++ console project template with just one file:

#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". Modified inside the zip file the .vstemplate file like this:

<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. The project is just opened and there's no substitution of the $custommessage$ parameter.

Why can't I show my wizard's GUI?

Additionally: is there any way to debug why the assembly isn't being loaded??

Locarno answered 15/6, 2013 at 9:8 Comment(0)
T
1

I had the same problem as the OP, following the same tutorial.

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. Then modify the vstemplate.

Finally try the wizard in a new instance of VS.

I don't know if this is the proper solution, but this is what worked for me.

Trochophore answered 28/6, 2013 at 9:2 Comment(2)
I had to do a lot of trickeries and machineries but I finally got it to work. Thanks Paresh, although you just gave me a hint, I finally got it working.Locarno
I don't understand this answer. I'm having the same problem following the same tutorial on that link but there is no "Modifying The Template" section, and there is no mention of a zip file on the entire page.Granicus
E
1

Probably the assembly with the wizard implementation is not found.

In the WizardExtension section you should write exact your assembly and class name.

Of course, this assembly should be in the extension directory or registered in GAC.

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

Thanks, Serge

Egad answered 17/6, 2013 at 12:58 Comment(3)
I registered it with gacutil.exe as described above and got no errors "assembly successfully registered". Regarding the wizardextension I'm not 100% sure about the Culture (the assembly says "none") but I think Neutral is the same thing. The token is up-to-date, assembly name is the same as the main namespace name, fullclassname is assembly name . IWizardImplementation (my UI class)Locarno
You can catch some exceptions, if any: 1) open new project dialog in the first instance of VS2012, 2) open the second instance of VS2012 3) attach debugger from the second instance of VS2012 to the first instance, 4) enable exceptions in the second instance of VS2012, 5) try to create new project in the first instance of VS2012 If there are some exceptions, you will see them in the second instance of VS2012Egad
Tried this but got nothing but this exception: "Value does not fall within expected range". Unfortunately I don't understand what range/value it is referring to. If you can create a simple wizard for vs2012 with a template project and zip it to me I would be grateful so I can check where I'm getting wrong. This should be a 5-min task following the above steps and making sure that I didn't get something wrongLocarno
T
1

I had the same problem as the OP, following the same tutorial.

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. Then modify the vstemplate.

Finally try the wizard in a new instance of VS.

I don't know if this is the proper solution, but this is what worked for me.

Trochophore answered 28/6, 2013 at 9:2 Comment(2)
I had to do a lot of trickeries and machineries but I finally got it to work. Thanks Paresh, although you just gave me a hint, I finally got it working.Locarno
I don't understand this answer. I'm having the same problem following the same tutorial on that link but there is no "Modifying The Template" section, and there is no mention of a zip file on the entire page.Granicus

© 2022 - 2024 — McMap. All rights reserved.