private void AddProjectTemplate(Project project)
        {
            DTE            dte       = (DTE)GetService(typeof(DTE));
            SolutionFolder slnFolder = null;

            if (project == null)
            {
                if (string.IsNullOrEmpty(this.Path))
                {
                    this.NewItem = dte.Solution.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName, false);
                }
                else
                {
                    Project subProject = DteHelper.FindProjectByPath(dte.Solution, this.Path);
                    slnFolder    = (SolutionFolder)subProject.Object;
                    this.NewItem = slnFolder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName);
                }
            }
            else
            {
                slnFolder    = (SolutionFolder)project.Object;
                this.NewItem = slnFolder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName);
            }

            if (this.newItem == null)
            {
                //Return the project already added if the AddFromTemplate method returns null
                ProjectItems childItems;

                if (slnFolder != null)
                {
                    childItems = slnFolder.Parent.ProjectItems;
                }
                else
                {
                    childItems = dte.Solution.Projects as ProjectItems;
                }

                if (childItems != null)
                {
                    foreach (ProjectItem item in childItems)
                    {
                        if (item.Name.Contains(this.ItemName))
                        {
                            this.NewItem = item.Object as Project;
                            break;
                        }
                    }
                }
                else
                {
                    this.NewItem = DteHelperEx.FindProjectByName(dte, this.ItemName, false);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Builds a blank theme including a project file.
        /// </summary>
        /// <param name="themesFolder">The themes folder.</param>
        /// <param name="vm">The vm.</param>
        /// <param name="templates">The templates.</param>
        /// <param name="themeType">Type of theme.</param>
        private void BuildThemeWithProject(SolutionFolder themesFolder, ThemeViewModel vm, string templates, string themeType)
        {
            var solution = GetGlobalService(typeof(SVsSolution)) as IVsSolution;
            var envsol   = dte.Solution;

            string solpath;
            string solfile;
            string soloptions;

            solution.GetSolutionInfo(out solpath, out solfile, out soloptions);

            //TODO: fix this...
            var newDir  = Path.Combine(solpath, "Orchard.Web", "Themes", vm.ThemeName);
            var newproj = themesFolder.AddFromTemplate(Path.Combine(templates, themeType, themeType + ".csproj"), newDir, vm.ThemeName);

            // this doesn't work
            EditCsProj(Path.Combine(newDir, vm.ThemeName + ".csproj"), vm.ThemeName);
            // this does work...
            newproj.Properties.Item("AssemblyName").Value = vm.ThemeName;
            // need this as well because... I have no idea
            newproj.Properties.Item("RootNamespace").Value = vm.ThemeName;
            EditThemeFile(newDir, vm);

            if (vm.IncludeHelpFile)
            {
                newproj.ProjectItems.AddFromFile(templates + "\\ThemeHelp.md");
            }

            newproj.Save();

            // for some reason this doesn't appear to work, references are manually added in the csproj file :(
            //var vsproj = newproj.Object as VSProject;
            //vsproj.References.Add("Orchard.Core");
            //vsproj.References.Add("Orchard.Framework");
        }
Exemple #3
0
        //---------------------------------------------------------------------
        // Other Methods
        //---------------------------------------------------------------------

        /// <summary>
        /// Moves a Visual Studio project to a solution folder using the
        /// specified wizard data and to an overriden physical folder on the
        /// file system.
        /// </summary>
        /// <param name="solutionRoot">Directory information for the Visual
        /// Studio solution root.</param>
        /// <param name="wizardData">A dictionary containing data for the
        /// template wizard.</param>
        /// <param name="templatePath">The path to the Visual Studio project
        /// template.</param>
        /// <param name="projectPath">The path of the Visual Studio project
        /// that was created.</param>
        /// <param name="projectName">The name of the Visual Studio project
        /// that was created.</param>
        private void MoveProject(DirectoryInfo solutionRoot,
                                 Dictionary <string, string> wizardData,
                                 string templatePath,
                                 string projectPath,
                                 string projectName)
        {
            var dte      = this.VsUtils.GetActiveInstance();
            var solution = dte.Solution;

            DirectoryInfo projectRoot = new DirectoryInfo(
                this.GetNewProjectPath(solutionRoot.FullName, wizardData[WizardDataKeyCustomProjectDir], projectName));

            if (!projectRoot.Exists)
            {
                Project project = this.VsUtils.FindProject(projectName);
                Project folder  = this.VsUtils.FindSolutionFolder(wizardData[WizardDataKeySolutionFolder]);

                solution.Remove(project);

                if (folder != null)
                {
                    SolutionFolder solutionFolder = this.VsUtils.ConvertToSolutionFolder(folder);

                    solutionFolder.AddFromTemplate(
                        templatePath,
                        projectRoot.FullName,
                        projectName);

                    this.IoUtils.DeleteDirectory(projectPath);
                }
            }
        }
        /// <summary>
        /// Builds a blank theme including a project file.
        /// </summary>
        /// <param name="themesFolder">The themes folder.</param>
        /// <param name="vm">The vm.</param>
        /// <param name="templates">The templates.</param>
        /// <param name="themeType">Type of theme.</param>
        private void BuildThemeWithProject(SolutionFolder themesFolder, ThemeViewModel vm, string templates, string themeType)
        {
            var solution = GetGlobalService(typeof(SVsSolution)) as IVsSolution;
            var envsol   = dte.Solution;

            string solpath;
            string solfile;
            string soloptions;

            solution.GetSolutionInfo(out solpath, out solfile, out soloptions);

            var newDir  = Path.Combine(solpath, "Orchard.Web", "Themes", vm.ThemeName);
            var newproj = themesFolder.AddFromTemplate(Path.Combine(templates, themeType, vm.Version, themeType + ".csproj"), newDir, vm.ThemeName);

            Insert(Path.Combine(newDir, vm.ThemeName + ".csproj"),
                   new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("$$ModuleProjectGuid$$", Guid.NewGuid().ToString()),
                new KeyValuePair <string, string>("$$ModuleName$$", vm.ThemeName)
            });
            // this does work...
            newproj.Properties.Item("AssemblyName").Value = vm.ThemeName;
            // need this as well because... I have no idea
            newproj.Properties.Item("RootNamespace").Value = vm.ThemeName;
            EditThemeFile(newDir, vm);

            // isn't added to tfs for some reason...
            if (vm.IncludeHelpFile)
            {
                newproj.ProjectItems.AddFromFile(templates + "\\ThemeHelp.md");
            }

            newproj.Save();
        }
        public static Project AddProject(this SolutionFolder solutionFolder, string destination, string projectName, string templateName)
        {
            string projectPath  = Path.Combine(destination, projectName);
            string templatePath = ((Solution4)solutionFolder.DTE.Solution).GetProjectTemplate(templateName, "CSharp");

            solutionFolder.AddFromTemplate(templatePath, projectPath, projectName);

            return(solutionFolder.DTE.Solution.GetProject(projectName));
        }
        private static void NewTemplateItemInSolutionFolder(string path, string itemTypeName, Solution2 sln,
                                                            NewItemDynamicParameters p, SolutionFolder folder)
        {
            var destinationPath = Path.Combine(
                Path.GetDirectoryName(sln.FullName),
                path
                );

            try
            {
                var n = sln.GetProjectTemplate(itemTypeName, p.Category);
                folder.AddFromTemplate(n, destinationPath, path);
            }
            catch (FileNotFoundException)
            {
                var n = sln.GetProjectItemTemplate(itemTypeName, p.Category);
                folder.AddFromTemplate(n, destinationPath, path);
            }
        }
Exemple #7
0
        private void GenerateProject(Solution2 solution, SolutionFolder platformsFolder, string projectFullName, string templateName)
        {
            if (_projectName.Contains(" "))
            {
                throw new Exception("The project name should not contain spaces");
            }

            if (_projectName != null)
            {
                var targetPath = Path.Combine(_targetPath, projectFullName);

                // Duplicate the template to add custom parameters
                var workTemplateFilePath = DuplicateTemplate(solution, templateName);
                AdjustCustomParameters(workTemplateFilePath, _projectName);

                platformsFolder.AddFromTemplate(workTemplateFilePath, targetPath, projectFullName);
            }
            else
            {
                throw new InvalidOperationException("Project name is not set");
            }
        }
        /// <summary>
        /// Adds the project to folder from template.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="templateName">Name of the template.</param>
        /// <param name="path">The path.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>True or False.</returns>
        public static bool AddProjectToFolderFromTemplate(
            this Project instance,
            string templateName,
            string path,
            string fileName)
        {
            TraceService.WriteLine("ProjectExtensions::AddItemToFolderFromTemplate project=" + instance.Name + " templateName=" + templateName + " fileName=" + fileName);

            SolutionFolder solutionFolder = (SolutionFolder)instance.Object;

            Solution2 solution = instance.DTE.Solution as Solution2;

            string templatePath = solution.GetProjectTemplate(templateName);

            if (templatePath != null)
            {
                solutionFolder.AddFromTemplate(templatePath, path, fileName);

                return(true);
            }

            return(false);
        }
        private void AddProjectTemplate(Project project)
        {
            try
            {
                IRecipeManagerService provider = (IRecipeManagerService)this.GetService(typeof(IRecipeManagerService));

                GuidancePackage p  = provider.GetPackage("SharePointSoftwareFactory.Base");
                GuidancePackage p2 = provider.EnablePackage("SharePointSoftwareFactory.Base");
            }
            catch (Exception)
            {
            }

            DTE            service = (DTE)this.GetService(typeof(DTE));
            SolutionFolder folder  = null;

            if (project == null)
            {
                if (string.IsNullOrEmpty(this.Path))
                {
                    //char[] invalidedChars = System.IO.Path.GetInvalidPathChars();
                    //foreach (char c in invalidedChars)
                    //{
                    //    if (this.Template.IndexOf(c) > 0)
                    //    {
                    //    }
                    //    if (this.DestinationFolder.IndexOf(c) > 0)
                    //    {
                    //    }
                    //}
                    this.NewItem = service.Solution.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName, false);
                }
                else
                {
                    folder       = (SolutionFolder)DteHelper.FindProjectByPath(service.Solution, this.Path).Object;
                    this.NewItem = folder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName);
                }
            }
            else
            {
                //sometimes in the solutionfolder a project already exists but is not part of the project
                //so we delete the folder if it already exists
                if (Directory.Exists(this.DestinationFolder))
                {
                    if (MessageBox.Show("Directory '" + this.DestinationFolder + "' already exists in the solution. Delete directory? If you choose 'No' the directory will be renamed to '" + this.DestinationFolder + "_Backup'", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Directory.Delete(this.DestinationFolder, true);
                    }
                    else
                    {
                        string backupDirectoryName = this.DestinationFolder + "_Backup";
                        int    count = 1;
                        while (Directory.Exists(backupDirectoryName))
                        {
                            backupDirectoryName = this.DestinationFolder + "_Backup" + count.ToString();
                            count++;
                        }
                        Directory.Move(this.DestinationFolder, backupDirectoryName);
                    }
                }

                folder       = (SolutionFolder)project.Object;
                this.NewItem = folder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName);
            }
            if (this.newItem == null)
            {
                ProjectItems projectItems;
                if (folder != null)
                {
                    projectItems = folder.Parent.ProjectItems;
                }
                else
                {
                    projectItems = service.Solution.Projects as ProjectItems;
                }
                if (projectItems != null)
                {
                    foreach (ProjectItem item in projectItems)
                    {
                        if (item.Name.Contains(this.ItemName))
                        {
                            this.NewItem = item.Object as Project;
                            break;
                        }
                    }
                }
                else
                {
                    this.NewItem = FindProjectByName(service, this.ItemName, false);
                }
            }
        }
        /// <summary>
        /// Fired when the user selects to create a new module
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void ModuleCallback(object sender, EventArgs e)
        {
            //var ssol = dte.Solution;
            //var solProjects = ssol.Projects;
            ////if we need to use codegen or can use our extended theme generator
            //bool extended = CheckFramework(solProjects);

            var vm      = new ModuleViewModel();
            var window  = new ModuleWindow(vm);
            var success = window.ShowDialog();

            if (success.GetValueOrDefault() == false)
            {
                return;
            }

            if (String.IsNullOrEmpty(vm.Name))
            {
                FireError("You need to give your module a name!");
                return;
            }

            var    name    = Regex.Replace(vm.Name, @"\s+", "");
            string version = vm.Version ?? vm.Versions[0];

            IVsUIShell uiShell   = (IVsUIShell)GetService(typeof(SVsUIShell));
            var        templates = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "OrchardTemplates");

            var solution = GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            var envsol = dte.Solution;
            var path   = envsol.FullName;

            string solpath;
            string solfile;
            string soloptions;

            solution.GetSolutionInfo(out solpath, out solfile, out soloptions);

            var projects = dte.Solution.Projects;
            // get the modules folder project
            Project modulesFolderProject = (from Project p in projects where p.Name == "Modules" select p).FirstOrDefault();

            // pointless error handling
            if (modulesFolderProject == null)
            {
                FireError("There appears to be no Modules folder");
                return;
            }

            // cast to solutionfolder object
            SolutionFolder modulesFolder = modulesFolderProject.Object as SolutionFolder;

            if (modulesFolder == null)
            {
                FireError("There appears to be no Modules folder");
                return;
            }

            var newDir = Path.Combine(solpath, "Orchard.Web", "Modules", name);

            var newproj = modulesFolder.AddFromTemplate(Path.Combine(templates, "__BlankModule", version, "BlankModule.csproj"), newDir, name);

            // it does not edit the assembly name so we will do that ourselves
            Insert(Path.Combine(newDir, name + ".csproj"),
                   new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("$$ModuleProjectGuid$$", Guid.NewGuid().ToString()),
                new KeyValuePair <string, string>("$$ModuleName$$", name)
            });

            Insert(Path.Combine(newDir, "Properties", "AssemblyInfo.cs"),
                   new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("$$ModuleTypeLibGuid$$", Guid.NewGuid().ToString()),
                new KeyValuePair <string, string>("$$ModuleName$$", name)
            });

            newproj.Properties.Item("AssemblyName").Value = name;

            // edit module.txt
            Insert(newDir + "\\Module.txt", new[]
            {
                new KeyValuePair <string, string>("$$ModuleName$$", name),
            });

            // transformer config files are created with a build action of none which will cause the build to fail after creating a module
            // delete these files as not particularly useful anyway in Orchard modules
            DeleteTransformerConfigFiles(newDir, envsol);



            // save our shiny new module
            newproj.Save();
        }
Exemple #11
0
        /// <summary>
        /// Fired when the user selects to create a new module
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void ModuleCallback(object sender, EventArgs e)
        {
            //var ssol = dte.Solution;
            //var solProjects = ssol.Projects;
            ////if we need to use codegen or can use our extended theme generator
            //bool extended = CheckFramework(solProjects);

            var vm      = new ModuleViewModel();
            var window  = new ModuleWindow(vm);
            var success = window.ShowDialog();

            if (success.GetValueOrDefault() == false)
            {
                return;
            }

            if (String.IsNullOrEmpty(vm.Name))
            {
                FireError("You need to give your module a name!");
                return;
            }

            var name = Regex.Replace(vm.Name, @"\s+", "");

            IVsUIShell uiShell   = (IVsUIShell)GetService(typeof(SVsUIShell));
            var        templates = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "OrchardTemplates");

            var solution = GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            var envsol = dte.Solution;
            var path   = envsol.FullName;

            string solpath;
            string solfile;
            string soloptions;

            solution.GetSolutionInfo(out solpath, out solfile, out soloptions);

            var projects = dte.Solution.Projects;
            // get the modules folder project
            Project modulesFolderProject = (from Project p in projects where p.Name == "Modules" select p).FirstOrDefault();

            // pointless error handling
            if (modulesFolderProject == null)
            {
                FireError("There appears to be no Modules folder");
                return;
            }

            // cast to solutionfolder object
            SolutionFolder modulesFolder = modulesFolderProject.Object as SolutionFolder;

            if (modulesFolder == null)
            {
                FireError("There appears to be no Modules folder");
                return;
            }

            var newDir = Path.Combine(solpath, "Orchard.Web", "Modules", name);

            var newproj = modulesFolder.AddFromTemplate(Path.Combine(templates, "__BlankModule", "BlankModule.csproj"), newDir, name);

            // it does not edit the assembly name so we will do that ourselves
            EditCsProj(Path.Combine(newDir, name + ".csproj"), name);

            newproj.Properties.Item("AssemblyName").Value = name;

            // edit module.txt
            Insert(newDir + "\\Module.txt", new[]
            {
                new KeyValuePair <string, string>("$name$", name),
            });

            // save our shiny new module
            newproj.Save();
        }
 private static void NewTemplateItemInSolutionFolder(string path, string itemTypeName, Solution2 sln,
                                                     NewItemDynamicParameters p, SolutionFolder folder)
 {
     var destinationPath = Path.Combine(
         Path.GetDirectoryName(sln.FullName),
         path
         );
     try
     {
         var n = sln.GetProjectTemplate(itemTypeName, p.Category);
         folder.AddFromTemplate(n, destinationPath, path);
     }
     catch (FileNotFoundException)
     {
         var n = sln.GetProjectItemTemplate(itemTypeName, p.Category);
         folder.AddFromTemplate(n, destinationPath, path);
     }
 }
        /// <summary>
        /// Builds a blank theme including a project file.
        /// </summary>
        /// <param name="themesFolder">The themes folder.</param>
        /// <param name="vm">The vm.</param>
        /// <param name="templates">The templates.</param>
        /// <param name="themeType">Type of theme.</param>
        private void BuildThemeWithProject(SolutionFolder themesFolder, ThemeViewModel vm, string templates, string themeType)
        {
            var solution = GetGlobalService(typeof(SVsSolution)) as IVsSolution;
            var envsol = dte.Solution;

            string solpath;
            string solfile;
            string soloptions;
            solution.GetSolutionInfo(out solpath, out solfile, out soloptions);

            var newDir = Path.Combine(solpath, "Orchard.Web", "Themes", vm.ThemeName);
            var newproj = themesFolder.AddFromTemplate(Path.Combine(templates, themeType, vm.Version, themeType + ".csproj"), newDir, vm.ThemeName);

            Insert(Path.Combine(newDir, vm.ThemeName + ".csproj"),
                new List<KeyValuePair<string, string>>
                {
                    new KeyValuePair<string, string>("$$ModuleProjectGuid$$", Guid.NewGuid().ToString()),
                    new KeyValuePair<string, string>("$$ModuleName$$", vm.ThemeName)
                });
            // this does work...
            newproj.Properties.Item("AssemblyName").Value = vm.ThemeName;
            // need this as well because... I have no idea
            newproj.Properties.Item("RootNamespace").Value = vm.ThemeName;
            EditThemeFile(newDir, vm);

            // isn't added to tfs for some reason...
            if (vm.IncludeHelpFile)
                newproj.ProjectItems.AddFromFile(templates + "\\ThemeHelp.md");

            newproj.Save();
        }
        public void RunFinished()
        {
            Solution2 solution2             = (Solution2)this._dte2.Solution;
            string    slClassLibProjectPath = this._slClassLibProject.FullName;
            string    classLibName          = this._replacementsDictionary["$safeprojectname$"];

            // Determine whether the SL project was created in a Solution Folder.
            // If the user explicitly asked to Add Project under a Solution Folder,
            // it will be non-null.  However if they ask to Create New Project under
            // a Solution Folder but change their mind to say "Add to Solution",
            // they will end up with the Silverlight project as a child of the SLN.
            ProjectItem    projectItem   = this._slClassLibProject.ParentProjectItem;
            ProjectItems   projectItems  = projectItem == null ? null : projectItem.Collection;
            Project        parentProject = projectItems == null ? null : projectItems.Parent as Project;
            SolutionFolder slProjectParentSolutionFolder = (parentProject != null && parentProject.Kind == ProjectKinds.vsProjectKindSolutionFolder)
                                                            ? parentProject.Object as SolutionFolder
                                                            : null;

            // If the SL project was created in a Solution Folder, it wins because we cannot move it (see below).
            // However if the SL project was created as a child of the Solution, we have a choice.  If a Solution Folder
            // was active when the user added the template, that is the one we will use.  But if there was no active
            // Solution Folder, then we unconditionally create a new Solution Folder as a child of the Solution.
            SolutionFolder libFolder = slProjectParentSolutionFolder ?? this._activeSolutionFolder;

            if (libFolder == null)
            {
                try
                {
                    // SL project was created directly under the Solution.  Create a Solution Folder
                    // to hold the pair of projects.
                    libFolder = (SolutionFolder)((Project)solution2.AddSolutionFolder(classLibName)).Object;
                }
                catch (COMException)
                {
                    libFolder = null;
                }
            }

            bool   isVb     = this._slClassLibProject.CodeModel.Language.Equals(CodeModelLanguageConstants.vsCMLanguageVB, StringComparison.OrdinalIgnoreCase);
            string language = isVb ? "VisualBasic" : "CSharp";

            // CSDMain 228876
            // Appending the FrameworkVersion to the file name when calling GetProjectTemplate is an undocumented way to request a specific $targetframeworkversion$ token
            // to become available to the child template.  Without doing this, the default target framework value is used, which for VS 11 is 4.5.
            // Reference: http://www.visualstudiodev.com/visual-studio-extensibility/using-automation-to-create-templates-using-different-framework-versions-in-vs2008-23148.shtml
            string templateName = "ClassLibrary.zip|FrameworkVersion=" + this._replacementsDictionary["$targetframeworkversion$"];
            string netClassLibProjectTemplate = solution2.GetProjectTemplate(templateName, language);
            string netClassLibProjectName     = classLibName + ".Web";
            string destination = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(slClassLibProjectPath)), netClassLibProjectName);

            // This code executes if we either created our own SolutionFolder or are using
            // the one the user chose.
            if (libFolder != null)
            {
                // Create the .NET class library in whichever SolutionFolder we decided to use above
                libFolder.AddFromTemplate(netClassLibProjectTemplate, destination, netClassLibProjectName);

                // If the SL project was created as a child of the Solution, we need to move it
                // into our new Solution Folder.  However, if it was created in a Solution Folder,
                // we leave it as is.  Dev10 bug 893488 disallows moving the SL project from one
                // Solution Folder to another, so this strategy avoids that issue.
                if (slProjectParentSolutionFolder == null)
                {
                    // Move the Silverlight library under the folder
                    solution2.Remove(this._slClassLibProject);

                    this._slClassLibProject = libFolder.AddFromFile(slClassLibProjectPath);
                }
            }
            else
            {
                solution2.AddFromTemplate(netClassLibProjectTemplate, destination, netClassLibProjectName, false);
            }


            // Link the two class libraries together

            string       extension   = Path.GetExtension(slClassLibProjectPath);
            IVsSolution  ivsSolution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
            IVsHierarchy hierarchy;

            ivsSolution.GetProjectOfUniqueName(_slClassLibProject.UniqueName, out hierarchy);
            IVsBuildPropertyStorage buildPropertyStorage = (IVsBuildPropertyStorage)hierarchy;

            buildPropertyStorage.SetPropertyValue("LinkedOpenRiaServerProject", null,
                                                  (uint)_PersistStorageType.PST_PROJECT_FILE,
                                                  Path.Combine("..", Path.Combine(netClassLibProjectName, netClassLibProjectName + extension)));
            buildPropertyStorage.SetPropertyValue("DisableFastUpToDateCheck", null,
                                                  (uint)_PersistStorageType.PST_PROJECT_FILE,
                                                  "true");
        }
Exemple #15
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            String              DestinationDirectory = replacementsDictionary["$destinationdirectory$"];
            String              SafeProjectName      = replacementsDictionary["$safeprojectname$"];
            Solution2           soln = (Solution2)((DTE)automationObject).Solution;
            List <String>       DeleteOnError = new List <string>();
            String              path, dest;
            PackageElementsForm form;
            Project             prj = null;


            form = new PackageElementsForm();
            form.ShowDialog();

            try
            {
                //
                // Create the folder for the project.
                //
                prj = soln.AddSolutionFolder(SafeProjectName);
                SolutionFolder sf = (SolutionFolder)prj.Object;

                //
                // Build the user controls project.
                //
                if (form.UserControls)
                {
                    path = soln.GetProjectTemplate("ArenaUserControlsProject.zip", "CSharp");
                    dest = String.Format("{0}\\UserControls", DestinationDirectory);
                    sf.AddFromTemplate(path, dest, SafeProjectName);
                    DeleteOnError.Add(dest);

                    //
                    // Rename the new project.
                    //
                    foreach (ProjectItem pi in prj.ProjectItems)
                    {
                        if (pi.Kind.Equals("{66A26722-8FB5-11D2-AA7E-00C04F688DDE}", StringComparison.InvariantCultureIgnoreCase))
                        {
                            Project p = (Project)pi.Object;

                            if (p.Name == SafeProjectName)
                            {
                                if (form.UseLongNames)
                                {
                                    p.Name = "ArenaWeb.UserControls.Custom." + SafeProjectName;
                                }
                                else
                                {
                                    p.Name = "UserControls";
                                }
                            }
                        }
                    }
                }

                //
                // Build the Business Logic project.
                //
                if (form.BusinessLogic)
                {
                    path = soln.GetProjectTemplate("ArenaBLLProject.zip", "CSharp");
                    dest = String.Format("{0}\\Library", DestinationDirectory);
                    sf.AddFromTemplate(path, dest, SafeProjectName);
                    DeleteOnError.Add(dest);

                    //
                    // Rename the new project.
                    //
                    foreach (ProjectItem pi in prj.ProjectItems)
                    {
                        if (pi.Kind.Equals("{66A26722-8FB5-11D2-AA7E-00C04F688DDE}", StringComparison.InvariantCultureIgnoreCase))
                        {
                            Project p = (Project)pi.Object;

                            if (p.Name == SafeProjectName)
                            {
                                if (form.UseLongNames)
                                {
                                    p.Name = "Arena.Custom." + SafeProjectName;
                                }
                                else
                                {
                                    p.Name = "Library";
                                }
                            }
                        }
                    }
                }

                //
                // Build the Setup project.
                //
                if (form.Setup)
                {
                    path = soln.GetProjectTemplate("ArenaSetupProject.zip", "CSharp");
                    dest = String.Format("{0}\\Setup", DestinationDirectory);
                    sf.AddFromTemplate(path, dest, SafeProjectName);
                    DeleteOnError.Add(dest);

                    //
                    // Rename the new project.
                    //
                    foreach (ProjectItem pi in prj.ProjectItems)
                    {
                        if (pi.Kind.Equals("{66A26722-8FB5-11D2-AA7E-00C04F688DDE}", StringComparison.InvariantCultureIgnoreCase))
                        {
                            Project p = (Project)pi.Object;

                            if (p.Name == SafeProjectName)
                            {
                                if (form.UseLongNames)
                                {
                                    p.Name = "Arena.Custom." + SafeProjectName + ".Setup";
                                }
                                else
                                {
                                    p.Name = "Setup";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                foreach (String p in DeleteOnError)
                {
                    Directory.Delete(p, true);
                }
                if (Directory.Exists(DestinationDirectory))
                {
                    try
                    {
                        Directory.Delete(DestinationDirectory, false);
                    }
                    catch { }
                }
                if (prj != null)
                {
                    prj.Delete();
                }

                throw e;
            }
        }
 public ShellProject AddFromTemplate(string FileName, string Destination, string ProjectName)
 {
     return(new ShellProject(_folder.AddFromTemplate(FileName, Destination, ProjectName)));
 }
 private void AddTemplateToSolutionFolder(
     SolutionFolder solutionFolder, string template, string destination, string name)
 {
     solutionFolder.AddFromTemplate(template, Path.Combine(destination, name), name);
 }