/// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            EnvDTE.DTE             dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
            IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService));
            object item = DteHelper.GetTarget(dte);



            if (item == null)
            {
                MessageBox.Show("There is no valid target to reference the template");
                return;
            }
            templateFilename = new Uri(templateFilename).LocalPath;

            VsBoundReference vsTarget = null;

            if (item is Project)
            {
                vsTarget = new ProjectReference(templateFilename, (Project)item);
            }
            else if (item is Solution)
            {
                vsTarget = new SolutionReference(templateFilename, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                vsTarget = new ProjectItemReference(templateFilename, (ProjectItem)item);
            }
            else if (item is EnvDTE80.SolutionFolder)
            {
                vsTarget = new ProjectReference(templateFilename, ((EnvDTE80.SolutionFolder)item).Parent);
            }
            if (item == null || vsTarget == null)
            {
                MessageBox.Show(string.Format(
                                    CultureInfo.CurrentCulture,
                                    "Target {0} specified for reference to asset {1} doesn't exist.",
                                    "target", templateFilename));
                return;
            }
            if (!File.Exists(templateFilename) || !templateFilename.EndsWith(".vstemplate", StringComparison.InvariantCultureIgnoreCase))
            {
                MessageBox.Show(string.Format(
                                    CultureInfo.CurrentCulture,
                                    "The filename specified for the template \"{0}\" does not exist.",
                                    templateFilename));
                return;
            }
            newReference = new BoundTemplateReference(templateFilename, vsTarget);
            referenceService.Add(newReference);
            MessageBox.Show("The new reference was successfully added", "New Reference",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private VsBoundReference GetReferenceTarget(string target, string recipeName)
        {
            VsBoundReference vsTarget = null;
            DTE dte = GetService <DTE>(true);

            target = DteHelper.ReplaceParameters(target, this.ReplacementDictionary);
            // Special case for "/" value.
            if (target.Equals("/") || target.Equals("\\"))
            {
                // "/" is the solution if we're in a solution template, the
                // project it this is a project template or the item if it's an item template.
                if (this.Project != null)
                {
                    vsTarget = new ProjectReference(recipeName, this.Project);
                }
                else if (this.Item != null)
                {
                    vsTarget = new ProjectItemReference(recipeName, this.Item);
                }
                else
                {
                    vsTarget = new SolutionReference(recipeName, dte.Solution);
                }
            }
            else if (template.VSKind == WizardRunKind.AsMultiProject)
            {
                string pathToTarget = target.Substring(1);
                if (root != null && root.Object is SolutionFolder)
                {
                    pathToTarget = DteHelper.BuildPath(root) + target;
                }
                ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, pathToTarget);
                if (prItem != null)
                {
                    vsTarget = new ProjectItemReference(recipeName, prItem);
                }
                else
                {
                    // Try finding a project.
                    Project prj = DteHelper.FindProjectByPath(dte.Solution, pathToTarget);
                    if (prj != null)
                    {
                        vsTarget = new ProjectReference(recipeName, prj);
                    }
                }
            }
            else if (template.VSKind == WizardRunKind.AsNewProject && this.Project != null)
            {
                ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution,
                                                              DteHelper.BuildPath(this.Project) + target);
                // Can only refer to items.
                if (prItem != null)
                {
                    vsTarget = new ProjectItemReference(recipeName, prItem);
                }
            }
            else
            {
                // We got here because there's an Item template that contains an assetname other than "\".
                throw new ArgumentException(String.Format(
                                                CultureInfo.CurrentCulture,
                                                Properties.Resources.Templates_ItemTargetInvalid,
                                                Path.GetFileName(template.FileName), target), "Target");
            }
            return(vsTarget);
        }
        /// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
            IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService));
            object item = DteHelper.GetTarget(dte);



            if (item == null)
            {
                MessageBox.Show("There is no valid target to reference the template");
                return;
            }
            templateFilename = new Uri(templateFilename).LocalPath;

            VsBoundReference vsTarget = null;
            if (item is Project)
            {
                vsTarget = new ProjectReference(templateFilename, (Project)item);
            }
            else if (item is Solution)
            {
                vsTarget = new SolutionReference(templateFilename, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                vsTarget = new ProjectItemReference(templateFilename, (ProjectItem)item);
            }
            else if (item is EnvDTE80.SolutionFolder)
            {
                vsTarget = new ProjectReference(templateFilename, ((EnvDTE80.SolutionFolder)item).Parent);
            }
            if (item == null || vsTarget == null)
            {
                MessageBox.Show(string.Format(
                    CultureInfo.CurrentCulture,
                    "Target {0} specified for reference to asset {1} doesn't exist.",
                    "target", templateFilename));
                return;
            }
            if (!File.Exists(templateFilename) || !templateFilename.EndsWith(".vstemplate", StringComparison.InvariantCultureIgnoreCase))
            {
                MessageBox.Show(string.Format(
                    CultureInfo.CurrentCulture,
                    "The filename specified for the template \"{0}\" does not exist.",
                    templateFilename));
                return;
            }
            newReference = new BoundTemplateReference(templateFilename, vsTarget);
            referenceService.Add(newReference);
            MessageBox.Show("The new reference was successfully added", "New Reference",
                MessageBoxButtons.OK, MessageBoxIcon.Information);

        }