locked
Multi Project Template RRS feed

  • Question

  • Lost.... is there a walkthrough on what attributes and templates are required in order to create the simplest of Multi-Project Template?

    What I'm trying to do and failing is create my own Project Type with one multi-project template.
    I'm using the multi-project template to create one or more projects.

    What I'm getting is the multi-project template appearing under the IronPython projects!!!!


    Here's what I have:
    I create a VSPackage, GalaxyDevenv, using the Visual Studio Integration Package Wizard.
    I then added a multi-project template and project template to the VSPackage project. I've added msbuild code to the project to zip the  multi-project template, the project template .vstemplate file and the contents of the project template.
    The project's msbuild also copies the resultant .zip to the VS2005 sdk installation under it's own folder:
    C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\GalaxyDevenv.zip.
    Hit F5 on my project and the debugger resets the Experimental hive and does the registry stuff and launchs the experimental hive.
    I attempt to create a new project GalaxyDevenv, yy multi-project template GalaxyDevenv does not appear under it's own folder in the new project dialog, it appears under the IronPython folder!!!

    My VSPackage implementation is the default:
    // VsPkg.cs : Implementation of GalaxyDevEnv
    //

    using System;
    using System.Diagnostics;
    using System.Globalization;
    using System.Runtime.InteropServices;
    using System.ComponentModel.Design;
    using Microsoft.Win32;
    using Microsoft.VisualStudio.Shell.Interop;
    using Microsoft.VisualStudio.OLE.Interop;
    using Microsoft.VisualStudio.Shell;

    namespace AvaeonSolutions.GalaxyDevEnv
    {
        /// <summary>
        /// This is the class that implements the package exposed by this assembly.
        ///
        /// The minimum requirement for a class to be considered a valid package for Visual Studio
        /// is to implement the IVsPackage interface and register itself with the shell.
        /// This package uses the helper classes defined inside the Managed Package Framework (MPF)
        /// to do it: it derives from the Package class that provides the implementation of the
        /// IVsPackage interface and uses the registration attributes defined in the framework to
        /// register itself and its components with the shell.
        /// </summary>
        // This attribute tells the registration utility (regpkg.exe) that this class needs
        // to be registered as package.
        [PackageRegistration(UseManagedResourcesOnly = true)]
        // A Visual Studio component can be registered under different regitry roots; for instance
        // when you debug your package you want to register it in the experimental hive. This
        // attribute specifies the registry root to use if no one is provided to regpkg.exe with
        // the /root switch.
        [DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\8.0Exp")]
        // This attribute is used to register the informations needed to show the this package
        // in the Help/About dialog of Visual Studio.
        [InstalledProductRegistration(false, "#110", "#112", "1.0", IconResourceID = 400)]
        // In order be loaded inside Visual Studio in a machine that has not the VS SDK installed,
        // package needs to have a valid load key (it can be requested at
        // http://msdn.microsoft.com/vstudio/extend/). This attributes tells the shell that this
        // package has a load key embedded in its resources.
        [ProvideLoadKey("Standard", "1.0", "GalaxyDevenv", "Avaeon Solutions", 1)]
        // This attribute is needed to let the shell know that this package exposes some menus.
        [ProvideMenuResource(1000, 1)]
        [ProvideEditorExtension(typeof(EditorFactory), ".gl", 50,
                  ProjectGuid = "{A2FE74E1-B743-11d0-AE1A-00A0C90FFFC3}",
                  TemplateDir = "..\\..\\Templates",
                  NameResourceID = 105,
                  DefaultName = "GalaxyDevenv")]
        [ProvideKeyBindingTable(GuidList.guidGalaxyDevEnvEditorFactoryString, 102)]
        [ProvideEditorLogicalView(typeof(EditorFactory), "{7651a703-06e5-11d1-8ebd-00a0c90f26ea}")]


        //Set the projectsTemplatesDirectory to a non-existant path to prevent VS from including the working directory as a valid template path
       //[ProvideProjectFactory(typeof(PythonProjectFactory), "IronPython", "IronPython Project Files (*.pyproj);*.pyproj", "pyproj", "pyproj", ".\\NullPath", LanguageVsTemplate = "IronPython")]
        //[ProvideObject(typeof(GeneralPropertyPage))]
        //[ProvideObject(typeof(IronPythonBuildPropertyPage))]
       
       

       
        [Guid(GuidList.guidGalaxyDevEnvPkgString)]
        public sealed class GalaxyDevEnv : Package
        {

            private EditorFactory editorFactory;

            /// <summary>
            /// Default constructor of the package.
            /// Inside this method you can place any initialization code that does not require
            /// any Visual Studio service because at this point the package object is created but
            /// not sited yet inside Visual Studio environment. The place to do all the other
            /// initialization is the Initialize method.
            /// </summary>
            public GalaxyDevEnv()
            {
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
            }



            /////////////////////////////////////////////////////////////////////////////
            // Overriden Package Implementation
            #region Package Members

            /// <summary>
            /// Initialization of the package; this method is called right after the package is sited, so this is the place
            /// where you can put all the initilaization code that rely on services provided by VisualStudio.
            /// </summary>
            protected override void Initialize()
            {
                Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
                base.Initialize();

                //Create Editor Factory
                editorFactory = new EditorFactory(this);
                base.RegisterEditorFactory(editorFactory);

            }
            protected override void Dispose(bool disposing)
            {
                Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Dispose() of: {0}", this.ToString()));

                try
                {
                    if (editorFactory != null)
                    {
                        editorFactory.Dispose();
                    }
                }
                finally
                {
                    base.Dispose(disposing);
                }
            }
            #endregion

        }
    }


    My multi-project template is:

    <VSTemplate Version="2.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
      <TemplateData>
        <Name>GalaxyDevenv Solution</Name>
        <Description>The Galaxy Development Environment Solution, contains all Project templates required.</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>GalaxyDevenv</ProjectType>
      </TemplateData>
      <TemplateContent>
        <ProjectCollection>
          <ProjectTemplateLink>
            Metadata_Project_Template\Metadata_Project_Template.vstemplate
          </ProjectTemplateLink>
          <!--<ProjectTemplateLink>
            Runtime_Project_Template\Runtime_Project_Template.vstemplate
          </ProjectTemplateLink>-->
        </ProjectCollection>
      </TemplateContent>
    </VSTemplate>


    My project template is:

    <VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
      <TemplateData>
        <Name>MetadataProject</Name>
        <Description>Visual Studio Project Template to create Metadata Application</Description>
        <ProjectType>GalaxyDevenv</ProjectType>
        <ProjectSubType>
        </ProjectSubType>
        <SortOrder>1000</SortOrder>
        <CreateNewFolder>true</CreateNewFolder>
        <DefaultName>MetadataProject</DefaultName>
        <ProvideDefaultName>true</ProvideDefaultName>
        <LocationField>Enabled</LocationField>
        <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
        <Icon>__TemplateIcon.ico</Icon>
      </TemplateData>
      <TemplateContent>
        <Project TargetFileName="Metadata_Project_Template1.csproj" File="Metadata_Project_Template1.csproj" ReplaceParameters="true">
          <ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$.settings">$safeprojectname$.settings</ProjectItem>
        </Project>
       
      </TemplateContent>
    </VSTemplate>
    Wednesday, March 7, 2007 1:10 PM

Answers

  • A project factory is necessary if you are trying to create a template for your own, custom project type. When a template is opened by VS, the name of the programming language is read from the ProjectType tag. We then map this to a project guid. When you select a project template in the new project template, we copy the templates to a temporary location then call the automation method Solution::AddFromTemplate. Internally to VS, this is mapped to the IVsProjectFactory::CreateProject, passing in the CPF_CLONEFILE flag. This is where the project factory copies the files of the project into the destination location and opens the project. If you do not have a project factory, then there is no way for a project to be created nor loaded.

    Craig

    Wednesday, March 14, 2007 6:14 PM

All replies

  • Hi Niall,

    Some ideas which maybe will help you to figure out the cause of your problem:

    1. The path for your project template missed one directory which is obviously named with language name. So it should look like: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\LanguageName\GalaxyDevenv.zip.

    2. Check that you are not using any GUIDs from IP sample.

    3. Also try to run devenv /installVStemplates command which will refresh project and item templates.

    Thursday, March 8, 2007 4:16 PM
  • Thanks Dimitry, no the path and Guids are good..
    I got it working.
    I implemened the PackageFactory with the default overrides and rebuilt, it works now. Is the PackageFactory implementation required in order to get your Project Type to appear in the dialog? or is it just the .vstemplate files that are required?

    Friday, March 9, 2007 11:50 AM
  • If memory serves (it's been a while), you don't need a project factory implementation. It's just the registry keys that count in this instance. At one point, I had a set of .vstemplates I wanted to appear in their own directory, and in their own category, and I had to create a registry entry under the Projects key to make this work.

    I'l see if I can dig that info up and post back on this thread tomorrow.

    Sincerely,

    Monday, March 12, 2007 2:17 AM
  • A project factory is necessary if you are trying to create a template for your own, custom project type. When a template is opened by VS, the name of the programming language is read from the ProjectType tag. We then map this to a project guid. When you select a project template in the new project template, we copy the templates to a temporary location then call the automation method Solution::AddFromTemplate. Internally to VS, this is mapped to the IVsProjectFactory::CreateProject, passing in the CPF_CLONEFILE flag. This is where the project factory copies the files of the project into the destination location and opens the project. If you do not have a project factory, then there is no way for a project to be created nor loaded.

    Craig

    Wednesday, March 14, 2007 6:14 PM