This documentation is archived and is not being maintained.

Walkthrough: Creating a Deployment Project for a Visual Studio Templates and Policy Wizard 

Visual Studio 2005

Because a Visual Studio Templates and Policy Wizard requires so many various files to be installed to the correct directories, the recommended way for distributing them is to create a deployment project that generates a Microsoft Installer file. This installer can then be placed on a network share where all developers working on the project can access the template to install the files to their local machine. In this walkthrough, you will create a deployment project for your Visual Studio Templates and Policy Wizard.

To create the deployment project

  1. In Visual Studio, open the WalkthroughTemplate solution. If you have not already done so, you should complete the following walkthroughs before beginning this one:

    Walkthrough: Creating a Project Template

    Walkthrough: Creating Policy Files

    Walkthrough: Creating a Visual Studio Templates and Policy Wizard

    Walkthrough: Adding Custom Help to a Visual Studio Templates and Policy Wizard

  2. From the File menu, choose Add, and then New Project.

    The Add New Project dialog box opens.

  3. In the Project Types pane, select Other Project Types, and then Setup and Deployment.

  4. In the Templates pane, select Setup Wizard and click OK.

    The Setup Project Wizard launches.

  5. Click Next to move past the title page.

  6. In the second page, select Create a setup for a Windows application and click Next.

  7. In the third page, select Primary Output from WalkthroughTemplate and click Next.

  8. Click Next in the fourth page and Finish in the fifth page to create the Setup project.

Next you will create directories in the File System view. These directories represent directories on the client machine where files required by your wizard will be installed.

To create directories

  1. If you are not already in File System view, in Solution Explorer right-click Setup1 and choose View, then choose File System.

  2. In the left pane in File System view, right-click and select Add Special Folder, then choose Custom Folder. Name this folder Custom Help.

  3. Repeat the previous step to create the following new folders:

    Help Links 1

    Help Links 2

    Policy Files

    Solution Templates

    Temporary Project Templates

  4. Select Custom Help. In the properties window, set the DefaultLocation to the following path:

    C:\WalkthroughHelp
    
  5. Repeat the previous step for the other custom folders, setting the DefaultLocation property as follows:

    Folder DefaultLocation value

    Help Links 1

    [ProgramFilesFolder]\Microsoft Visual Studio 8\Common7\IDE\HTML\XMLLinks\1033

    Help Links 2

    [ProgramFilesFolder]\Common Files\Microsoft Shared\Help 8\HTML\XMLLinks\1033

    Policy Files

    [ProgramFilesFolder]\Microsoft Visual Studio 8\Common7\IDE\Policy\Definitions

    Solution Templates

    [ProgramFilesFolder]\Microsoft Visual Studio 8\Common7\IDE\SolutionTemplates

    Temporary Project Templates

    C:\WalkthroughTemplateTemporary

  6. Select Help Links 2. In the Properties window, set AlwaysCreate to True.

Now that you have the directories required for the client machine, you must put the correct files into the appropriate directories.

To add files to the file system

  1. In the left pane in File System view, right-click Custom Help, choose Add, and then choose File.

    The Add Files dialog box opens.

  2. Navigate to the folder that contains WalkthroughHelp.htm and select it. Click OK to add it to this directory.

  3. Repeat the previous two steps for each of the folders added in the last procedure, adding files as shown below:

    Folder Files

    Help Links 1

    CustomHelp.xml

    Help Links 2

    CustomHelp.xml

    Policy Files

    WalkthroughPolicy.vspolicy

    WalkthroughPolicy.vspolicydef

    Solution Templates

    WalkthroughTemplate.vsz

    WalkthroughTemplate.vsdir

    Temporary Project Templates

    WalkthroughTemplate.zip

    Note that the WalkthroughTemplate.zip file is the project template you created in the first walkthrough, and should be located in your Exported Templates folder.

Now that you have added all of your files to the correct folders, you must create a custom action to install the project template to the correct folder. Since Visual Studio only looks for project templates in a particular location, and this location can vary from user to user, it is impossible to know ahead of time the correct directory in which to install project templates. You must create a custom action to read the correct location from the registry, then copy the project template from the temporary folder to the location found in the registry. After the file has been copied, the temporary folder is deleted. You will also create a second custom action that removes the template from this location if the Visual Studio Templates and Policy Wizard is uninstalled through the setup project.

To create a custom action

  1. In Solution Explorer, select WalkthroughWizard.

  2. From the Project menu, choose Add New Item, select Installer Class, and then click Add.

  3. From the View menu, choose Code to open the Code Editor for Installer1.

  4. Add the following method to Installer1.

    ' Visual Basic
    Public Overrides Sub Install(ByVal statesaver As _ 
        System.Collections.IDictionary)
        MyBase.Install(statesaver)
        Dim Key As String = _
    Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0", "UserProjectTemplatesLocation", System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "\Visual Studio 2005\Templates\ProjectTemplates").ToString()
        If Not System.IO.Directory.Exists(Key) Then
            System.IO.Directory.CreateDirectory(Key)
        End If
        For Each myfile As String In _
    System.IO.Directory.GetFiles("C:\WalkthroughTemplateTemporary")
            System.IO.File.Copy(myfile, Key & "\" & _
                myfile.Substring(myfile.LastIndexOf("\")), True)
            System.IO.File.Delete(myfile)
        Next
        System.IO.Directory.Delete("C:\WalkthroughTemplateTemporary")
    End Sub
    
    // Visual C#
    public override void Install(System.Collections.IDictionary statesaver)
    {
        base.Install(statesaver);
        string Key = Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0", "UserProjectTemplatesLocation", System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "\\Visual Studio 2005\\Templates\\ProjectTemplates").ToString();
        if (!System.IO.Directory.Exists(Key))
        {
            System.IO.Directory.CreateDirectory(Key);
        }
        
        {
            foreach (string myfile in 
    System.IO.Directory.GetFiles("C:\\WalkthroughTemplateTemporary"))
            {
                System.IO.File.Copy(myfile, Key + "\\" +
                myfile.Substring(myfile.LastIndexOf('\\')),true);
                System.IO.File.Delete(myfile);
            }
        }
        System.IO.Directory.Delete("C:\\WalkthroughTemplateTemporary");
    }
    

    This is the method that will be executed upon install of your wizard. It reads the registry to find the location of the templates directory, then copies the template from the temporary directory to that directory. Finally, it deletes the temporary directory.

  5. After the method added in the previous step, add the following method:

    ' Visual Basic
    Public Overrides Sub UnInstall(ByVal savedstate As _
        System.Collections.IDictionary)
        MyBase.Uninstall(savedstate)
        Dim Key As String = _
    Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0", "UserProjectTemplatesLocation", System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "\Visual Studio 2005\Templates\ProjectTemplates").ToString()
        System.IO.File.Delete(Key & "\" & _
            "WalkthroughTemplate.zip")
    End Sub
    
    // Visual C#
    public override void Uninstall(System.Collections.IDictionary savedState)
    {
        base.Uninstall(savedState);
        string Key = Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0", "UserProjectTemplatesLocation", System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "\\Visual Studio 2005\\Templates\\ProjectTemplates").ToString();
            System.IO.File.Delete(Key + "\\" + 
                "WalkthroughTemplate.zip");
    }
    

    This method will be executed when the wizard is uninstalled through the setup project. It removes the template from the templates directory.

  6. In Solution Explorer, right-click Setup1, choose View, and then Custom Actions.

    The Custom Actions editor opens.

  7. In the Custom Actions editor, right-click the Install folder and choose Add Custom Action.

  8. In the Select Item in Project dialog box, double-click Application Folder then choose Primary Output from WalkthroughWizard.

  9. In the Custom Actions editor, right-click the Uninstall folder and choose Add Custom Action.

  10. In the Select Item in Project dialog box, double-click Application Folder then choose Primary Output from WalkthroughWizard.

  11. From the Build menu, choose Configuration Manager and ensure that the Build box is selected for all projects.

  12. From the Build menu, choose Build Solution to build the solution.

Your Visual Studio Templates and Policy Wizard has been built and packaged into the .msi file generated by the Setup project. All that remains is to test it.

To test your setup project

  1. Transfer the .msi file generated by your setup project to another machine with the same install of Visual Studio 2005. The .msi file is in the build folder of your setup project.

  2. If Visual Studio 2005 is open, close it.

  3. Double-click the .msi file and follow the instructions of the setup wizard.

  4. Open a new instance of Visual Studio 2005.

  5. From the File menu, choose New and then choose Project.

  6. In the Project Types pane, choose Other Project Types, and then choose Visual Studio Solutions.

  7. In the Templates pane, choose WalkthroughTemplate and click OK.

    A new solution is generated from your Visual Studio Templates and Policy Wizard.

Show: