Пример #1
0
        internal static void CreateSolutionSettings()
        {
            string path = GetSolutionFilePath();

            if (!File.Exists(path))
            {
                lock (_syncFileRoot)
                {
                    File.WriteAllText(path, string.Empty);
                }

                Save(path);

                Solution2 solution = EditorExtensionsPackage.DTE.Solution as Solution2;
                Project   project  = solution.Projects
                                     .OfType <Project>()
                                     .FirstOrDefault(p => p.Name.Equals(_solutionFolder, StringComparison.OrdinalIgnoreCase));

                if (project == null)
                {
                    project = solution.AddSolutionFolder(_solutionFolder);
                }

                project.ProjectItems.AddFromFile(path);
                //EditorExtensionsPackage.DTE.ItemOperations.OpenFile(path);
                UpdateStatusBar("applied");
            }
        }
Пример #2
0
        public static List <string> ListClasses(string projectName)
        {
            if (applicationObject == null)
            {
                return(null);
            }
            List <string> classes  = new List <string>();
            Solution2     solution = (Solution2)applicationObject.Solution;

            foreach (Project project in solution.Projects)
            {
                if (project.Name == projectName)
                {
                    foreach (ProjectItem projectItem in project.ProjectItems)
                    {
                        if (projectItem.Kind == EnvDTEConstants.vsProjectItemKindPhysicalFile && projectItem.Name.Contains(".cs"))
                        {
                            classes.Add(projectItem.Name.Substring(0, projectItem.Name.Length - 3));
                        }
                    }
                    break;
                }
            }
            return(classes);
        }
Пример #3
0
        private static void GenerateSolution(SolutionData solutionData)
        {
            try
            {
                MessageFilter.Register();
                System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE");
                Object      obj  = System.Activator.CreateInstance(type, true);
                EnvDTE.DTE  dte  = (EnvDTE.DTE)obj;
                dte.MainWindow.Visible = false;

                // create a new solution
                dte.Solution.Create(solutionData.directoryPath + "\\", solutionData.solutionName);
                dte.ExecuteCommand("File.SaveAll");

                Solution2 solution = (Solution2)dte.Solution;
                createProject(solutionData, solution, dte);

                EnvDTE.Project project = solution.Projects.Item(1);
                DTE2           dte2    = (DTE2)dte;

                addContentToProject(solutionData, project, dte2);

                // save and quit
                dte.ExecuteCommand("File.SaveAll");
                dte.Quit();
                MessageFilter.Revoke();
            }
            catch
            {
                ErrorHandling.handleWrongUsage();
            }
        }
        /// <summary>
        /// Adds the view model and views.
        /// </summary>
        public void AddViewModelAndViews()
        {
            this.AddTraceHeader("AddViewModelAndViews");

            if (this.visualStudioService.IsMvvmCrossSolution)
            {
                List <ItemTemplateInfo> templateInfos = this.visualStudioService.AllowedItemTemplates;
                ViewModelOptionsView    form          = new ViewModelOptionsView(templateInfos);

                form.ShowDialog();

                if (form.Continue)
                {
                    this.visualStudioService.DTE2.WriteStatusBarMessage("Ninja Coder is running....");

                    Solution2 solution = this.visualStudioService.DTE2.GetSolution() as Solution2;

                    solution.AddItemTemplateToProjects(form.Presenter.GetRequiredItemTemplates());

                    //// now collapse the solution!
                    this.visualStudioService.DTE2.CollapseSolution();

                    this.visualStudioService.DTE2.WriteStatusBarMessage("Ninja Coder has completed the adding of the viewmodel and views.");
                }
            }
            else
            {
                MessageBox.Show("This solution is not a MvvmCross solution.", Settings.ApplicationName);
            }
        }
Пример #5
0
        public static void SaveBrowsers(IEnumerable <string> browsers)
        {
            Solution2 solution = EditorExtensionsPackage.DTE.Solution as Solution2;

            EnvDTE.Project project = solution.Projects
                                     .OfType <EnvDTE.Project>()
                                     .FirstOrDefault(p => p.Name.Equals(Settings._solutionFolder, StringComparison.OrdinalIgnoreCase));

            if (project == null)
            {
                project = solution.AddSolutionFolder(Settings._solutionFolder);
            }

            string path = GetSolutionFilePath();

            using (XmlWriter writer = XmlWriter.Create(path, new XmlWriterSettings()
            {
                Indent = true
            }))
            {
                writer.WriteStartElement("browsers");

                foreach (string browser in browsers)
                {
                    writer.WriteElementString("browser", browser);
                }

                writer.WriteEndElement();
            }

            project.ProjectItems.AddFromFile(path);
            CssSchemaManager.SchemaManager.ReloadSchemas();
        }
Пример #6
0
        private void validateSolutionStructure()
        {
            Solution2 solution           = (Solution2)applicationObject.Solution;
            string    solutionDir        = Path.GetDirectoryName(solution.FullName);
            bool      isFlatSingleModule = (solution.Projects.Count == 1 &&
                                            Path.GetExtension(solution.Projects.Item(1).FullName).EndsWith("proj") &&
                                            solutionDir == Path.GetDirectoryName(solution.Projects.Item(1).FullName));

            foreach (Project project in solution.Projects)
            {
                string projPath = string.Empty;
                try { projPath = project.FullName; }
                catch { } //missing project, do nothing

                if (Path.GetExtension(projPath).EndsWith("proj"))
                {
                    string projDir = Path.GetDirectoryName(projPath);
                    if (isFlatSingleModule)
                    {
                        if (solutionDir != projDir)
                        {
                            throw new Exception("Project Importer failed with project " + project.Name + ". Project directory structure not supported: in a single module project, the solution and project must be in the same directory");
                        }
                    }
                    else
                    {
                        // This check seems too arbitrary - removed for now
                        //                        if (solutionDir != Path.GetDirectoryName(projDir))
                        //                        {
                        //                            throw new Exception("Project Importer failed with project " + project.Name + ". Project directory structure may not be supported: in a multi-module project, the project must be in a direct subdirectory of the solution");
                        //                        }
                    }
                }
            }
        }
Пример #7
0
 /// <summary>
 /// 创建ADO.NET实体数据模型
 /// </summary>
 /// <param name="project"></param>
 /// <param name="itemNameWithoutExtion">edmx的名称(不带后缀)</param>
 /// <returns>创建完成的项目项</returns>
 public static ProjectItem AddAdoNetEntityDataModel(this Project project, string itemNameWithoutExtion)
 {
     try
     {
         ProjectItem projectItem = project.ProjectItems.FindItem(itemNameWithoutExtion + ".edmx");
         //项存在删除
         if (null != projectItem)
         {
             projectItem.Delete();
         }
         ProjectItem appItem = project.ProjectItems.FindItem("app.config");
         if (null != appItem)
         {
             appItem.Delete();
         }
         Solution2 sln          = project.DTE.Solution as Solution2;
         string    templatePath = sln.GetProjectItemTemplate("AdoNetEntityDataModelCSharp.zip", "CSharp");
         projectItem = project.ProjectItems.AddFromTemplate(templatePath, itemNameWithoutExtion + ".edmx");
         if (null == projectItem)
         {
             projectItem = project.ProjectItems.Item(itemNameWithoutExtion + ".edmx");
         }
         return(projectItem);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #8
0
        private void AddSkinnedModelAndPipeLineProject()
        {
            if (currentProject == null)
            {
                return;
            }

            Solution2 solution = (Solution2)applicationObject.Solution;

            string dirPath = Path.GetDirectoryName(solution.FullName) + "\\SkinnedModel";

            FileHelper.DirectoryCopy(AssemblyDirectory + "\\templates\\SkinnedModel", dirPath, true);
            skinnedModelProject = solution.AddFromFile(dirPath + "\\SkinnedModel.csproj");

            VSLangProj.VSProject project;

            project = (VSLangProj.VSProject)currentProject.Object;
            project.References.AddProject(skinnedModelProject);


            dirPath = Path.GetDirectoryName(solution.FullName) + "\\SkinnedModelPipeline";
            FileHelper.DirectoryCopy(AssemblyDirectory + "\\templates\\SkinnedModelPipeline", dirPath, true);
            skinnedModelPipelineProject = solution.AddFromFile(dirPath + "\\SkinnedModelPipeline.csproj");

            project = (VSLangProj.VSProject)skinnedModelPipelineProject.Object;
            project.References.AddProject(skinnedModelProject);

            project = (VSLangProj.VSProject)contentProject.Object;
            project.References.AddProject(skinnedModelPipelineProject);
        }
Пример #9
0
        /// <summary>
        /// Gets the projects.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>The projects.</returns>
        public static IEnumerable <Project> GetProjects(this Solution2 instance)
        {
            List <Project> projects = instance.Projects.Cast <Project>().ToList();

            List <Project> allProjects = new List <Project>(projects);

            foreach (Project project in projects)
            {
                IEnumerable <ProjectItem> projectItems = project.GetProjectItems();

                if (projectItems != null)
                {
                    foreach (ProjectItem projectItem in projectItems)
                    {
                        ////if (projectItem.Kind == ProjectKinds.vsProjectKindSolutionFolder)
                        if (projectItem.Kind == "{66A26722-8FB5-11D2-AA7E-00C04F688DDE}")
                        {
                            if (projectItem.SubProject != null)
                            {
                                allProjects.Add(projectItem.SubProject);
                            }
                        }
                    }
                }
            }

            return(allProjects);
        }
Пример #10
0
        private static int Solve2(string s)
        {
            var solution = new Solution2();
            var result   = solution.LengthOfLongestSubstring(s);

            return(result);
        }
Пример #11
0
        private const string ProjectKindsVsProjectKindSolutionFolder = "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}"; //ProjectKinds.vsProjectKindSolutionFolder

        public static IList <Project> GetAllProjects(this Solution2 solution)
        {
            Projects       projects = solution.Projects;
            List <Project> list     = new List <Project>();
            var            item     = projects.GetEnumerator();

            while (item.MoveNext())
            {
                var project = item.Current as Project;
                if (project == null)
                {
                    continue;
                }

                if (project.Kind == ProjectKindsVsProjectKindSolutionFolder)
                {
                    list.AddRange(GetSolutionFolderProjects(project));
                }
                else
                {
                    list.Add(project);
                }
            }

            return(list);
        }
        public void AddTemplateReference(EnvDTE.Project currentProject, EnvDTE.Project selectedProject)
        {
            // we need to compute a relative path for the template project
            Uri    currentProjUri  = new Uri(currentProject.FullName);
            Uri    selectedProjUri = new Uri(selectedProject.FullName);
            string relativePath    = currentProjUri.MakeRelativeUri(selectedProjUri).ToString();

            FileInfo selectedProjFile = new FileInfo(selectedProject.FullName);

            var curProjObj = ProjectRootElement.Open(currentProject.FullName);
            var item       = curProjObj.AddItem("TemplateReference", selectedProjFile.Name, GetTemplateReferenceMetadata(relativePath));

            // Install the TemplateBuilder NuGet pkg into the target project

            InstallTemplateBuilderPackage(currentProject);

            // Add the SideWaffle Project Template files into the target project
            var       dte2     = Package.GetGlobalService(typeof(DTE)) as DTE2;
            Solution2 solution = (Solution2)dte2.Solution;
            string    itemPath = solution.GetProjectItemTemplate("SW-ProjectVSTemplateFile.csharp.zip", "CSharp");

            selectedProject.ProjectItems.AddFromTemplate(itemPath, "_project1.vstemplate");

            curProjObj.Save();

            // Reload the project
            ReloadProject(dte2, currentProject);
        }
Пример #13
0
        /// <summary>
        /// Creates the solution and calls the functions to create the projects
        /// </summary>
        /// <param name="IDEObject"></param>
        /// <param name="ContextParams"></param>
        public void CreateSolution(_DTE IDEObject, object[] ContextParams)
        {
            TraceAllValues(ContextParams);

            //Get the "official" wizard results
            _ProjectDirectory = ContextParams[(int)ContextOptions.LocalDirectory].ToString();
            _ProjectName      = ContextParams[(int)ContextOptions.ProjectName].ToString();
            _SolutionName     = ContextParams[(int)ContextOptions.SolutionName].ToString();
            _FExclusive       = bool.Parse(ContextParams[(int)ContextOptions.FExclusive].ToString());

            //Get the custom wizard results
            _ClassName            = (string)_WizardResults[WizardValues.ClassName];
            _NewProjectNamespace  = (string)_WizardResults[WizardValues.NewProjectNamespace];
            _Namespace            = (string)_WizardResults[WizardValues.Namespace];
            _ComponentDescription = (string)_WizardResults[WizardValues.ComponentDescription];

            if (!_FExclusive)            //New solution or existing?
            {
                // Get a reference to the solution from the IDE Object
                _PipelineComponentSolution = (Solution2)IDEObject.Solution;
            }
            else
            {
                // Use the solution class to create a new solution
                _PipelineComponentSolution = (Solution2)IDEObject.Solution;
                _PipelineComponentSolution.Create(_ProjectDirectory, _ProjectName);
            }

            SaveSolution();

            //Create the projects
            CreateProject(_PipelineComponentSolution);

            SaveSolution();
        }
Пример #14
0
        private static async Task <string> GetProjectTemplateFilePathAsync(
            Solution2 solution2,
            string templateName,
            string templatePath)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            string projectTemplatePath     = null;
            string projectTemplateFilePath = null;

            if (templateName.Equals("DNXClassLibrary", StringComparison.Ordinal) ||
                templateName.Equals("DNXConsoleApp", StringComparison.Ordinal))
            {
                projectTemplatePath = templateName + ".vstemplate|FrameworkVersion=4.5";
                var lang = "CSharp/Web";

                projectTemplateFilePath = solution2.GetProjectItemTemplate(projectTemplatePath, lang);
            }
            else
            {
                projectTemplatePath = Path.Combine(templatePath, templateName + ".zip");

                var projectTemplateFiles = Directory.GetFiles(projectTemplatePath, "*.vstemplate");
                Debug.Assert(projectTemplateFiles.Length > 0);
                projectTemplateFilePath = projectTemplateFiles[0];
            }

            return(projectTemplateFilePath);
        }
Пример #15
0
        public static List<string> GetTextEditorProperties() {
            System.Type t = Connect.settingsObject.VisualStudioVersion;
            object obj = Activator.CreateInstance(t, true);
            dte2 = (DTE2)obj;
            sln2 = (Solution2)dte2.Solution;

            // http://msdn.microsoft.com/en-us/library/ms165641(v=vs.90).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
            // Nested node doesn't work in C# as done in article with VB. 
            // Tried different separators but have not found the right C# syntax.
            // Other links:
            // http://msdn.microsoft.com/en-us/library/ms165644.aspx
            // http://www.mztools.com/articles/2005/mz2005008.aspx
            // http://dotnet.dzone.com/articles/structure-visual-studio?page=0,1

            EnvDTE.Properties txtEdCS = dte2.get_Properties("TextEditor", "CSharp - Formatting");

            EnvDTE.Property prop = null;
            string msg = null;

            List<string> propList = new List<string>();
            foreach (EnvDTE.Property temp in txtEdCS) {
                prop = temp;
                msg = ("Prop Name: " + prop.Name + "  VALUE: " + prop.Value) + "\n";
                propList.Add(msg);
            }

            return propList;

        }
Пример #16
0
 public static Project[] GetAllProjects(this Solution2 sln)
 {
     return(sln.Projects
            .Cast <Project>()
            .SelectMany(GetProjects)
            .ToArray());
 }
Пример #17
0
        private void TraverseProjects(string projectName)
        {
            Solution2 solution = (Solution2)applicationObject.Solution;

            foreach (Project project in solution.Projects)
            {
                if (project.Name == projectName)
                {
                    currentProject = project;
                }
                if (project.Name == xleModelProjectName)
                {
                    xleModelProject = project;
                }
                if (project.FullName.Contains(".contentproj"))
                {
                    contentProject = project;
                }
            }

            if (xleModelProject == null)
            {
                AddXleModelProject();
            }
        }
        public static bool TryGetExistingSolutionItemsFolder(Solution2 solution, string filePath, out EnvDTE.Project?solutionItemsFolder, out bool hasExistingSolutionItem)
        {
            solutionItemsFolder     = null;
            hasExistingSolutionItem = false;

            var fileName = PathUtilities.GetFileName(filePath);

            foreach (Project project in solution.Projects)
            {
                if (project.Kind == EnvDTE.Constants.vsProjectKindSolutionItems &&
                    project.Name == SolutionItemsFolderName)
                {
                    solutionItemsFolder = project;

                    foreach (ProjectItem projectItem in solutionItemsFolder.ProjectItems)
                    {
                        if (fileName == projectItem.Name)
                        {
                            hasExistingSolutionItem = true;
                            break;
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
        private string GetDestReadMeFilePath(Solution2 solution, string templateName)
        {
            string retVal       = null;
            var    solutionPath = solution.Properties.Item("Path").Value as string;

            if (string.IsNullOrWhiteSpace(solutionPath))
            {
                return(null);
            }

            var solutionDir = new FileInfo(solutionPath).DirectoryName;

            if (string.IsNullOrWhiteSpace(solutionDir))
            {
                return(null);
            }

            var readMeFileName = GetReadMeFileName(templateName);

            if (!string.IsNullOrWhiteSpace(readMeFileName))
            {
                retVal = Path.Combine(solutionDir, readMeFileName);
            }

            return(retVal);
        }
Пример #20
0
        private void AddFileToProject(ProjectItem item, bool isSolution, string configPath)
        {
            if (_dte.Solution.FindProjectItem(configPath) != null)
            {
                return;
            }

            Project currentProject = null;

            if (isSolution && item.Kind != EnvDTE.Constants.vsProjectItemKindSolutionItems)
            {
                Solution2 solution = (Solution2)_dte.Solution;

                foreach (Project project in solution.Projects)
                {
                    if (project.Kind == EnvDTE.Constants.vsProjectKindSolutionItems && project.Name == "Solution Items")
                    {
                        currentProject = project;
                        break;
                    }
                }

                if (currentProject == null)
                {
                    currentProject = solution.AddSolutionFolder("Solution Items");
                }
            }

            currentProject = currentProject ?? item.ContainingProject;

            ProjectHelpers.AddFileToProject(currentProject, configPath, "None");
        }
Пример #21
0
        private Project MoveProjectTo(string targetSubFolder, EnvDTE.Project project, string solutionFolderName)
        {
            string projectName      = project.Name;
            string originalLocation = GetSolutionRootPath() + GetSolutionName() + "\\" + projectName;

            if (Directory.Exists(originalLocation))
            {
                Solution2 solution = dte.Solution as Solution2;
                Log("MoveProjectTo: Removing " + projectName + " from solution");
                solution.Remove(project);
                // Give the solution time to release the lock on the project file
                System.Threading.Thread.Sleep(MIN_TIME_FOR_PROJECT_TO_RELEASE_FILE_LOCK);
                PerformManualProjectReplacementsTo(originalLocation + "\\" + projectName + ".csproj");
                string targetLocation = GetSolutionRootPath() + GetSolutionName() + targetSubFolder + projectName;
                Log("MoveProjectTo: Moving " + projectName + " from " + originalLocation + " to target location at " + targetLocation);
                Directory.Move(originalLocation, targetLocation);
                if (!string.IsNullOrEmpty(solutionFolderName))
                {
                    SolutionFolder solutionFolder = (SolutionFolder)solution.AddSolutionFolder(solutionFolderName).Object;
                    Log("MoveProjectTo: Adding " + projectName + " to solution folder " + targetLocation);
                    return(solutionFolder.AddFromFile(targetLocation + "\\" + projectName + ".csproj"));
                }
                else
                {
                    Log("MoveProjectTo: Adding " + projectName + " to solution");
                    return(solution.AddFromFile(targetLocation + "\\" + projectName + ".csproj", false));
                }
            }
            else
            {
                throw new ApplicationException("Couldn't find " + originalLocation + " to move");
            }
        }
 public void RebuildDependencies(Solution2 oSolution, IDictionary<String, List<String>> OutputData, IDictionary<String, List<String>> InputData)
 {
     // rebuild project dependencies
     foreach (BuildDependency Dependency in oSolution.SolutionBuild.BuildDependencies)
     {
         List<String> Libs = new List<string>();
         if (InputData.TryGetValue(Dependency.Project.UniqueName, out Libs))
         {
             foreach (String Lib in Libs)
             {
                 foreach (KeyValuePair<String, List<String>> OutputFiles in OutputData)
                 {
                     if (OutputFiles.Value.Contains(Lib))
                     {
                         try
                         {
                             Dependency.AddProject(OutputFiles.Key);
                             break;
                         }
                         catch (Exception)
                         {
                             // most likely we are trying to create circular dependency
                         }
                     }
                 }
             }
         }
         Utilities.Sleep(10);
     }
 }
Пример #23
0
        public static List <string> GetTextEditorProperties()
        {
            System.Type t   = Connect.settingsObject.VisualStudioVersion;
            object      obj = Activator.CreateInstance(t, true);

            dte2 = (DTE2)obj;
            sln2 = (Solution2)dte2.Solution;

            // http://msdn.microsoft.com/en-us/library/ms165641(v=vs.90).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
            // Nested node doesn't work in C# as done in article with VB.
            // Tried different separators but have not found the right C# syntax.
            // Other links:
            // http://msdn.microsoft.com/en-us/library/ms165644.aspx
            // http://www.mztools.com/articles/2005/mz2005008.aspx
            // http://dotnet.dzone.com/articles/structure-visual-studio?page=0,1

            EnvDTE.Properties txtEdCS = dte2.get_Properties("TextEditor", "CSharp - Formatting");

            EnvDTE.Property prop = null;
            string          msg  = null;

            List <string> propList = new List <string>();

            foreach (EnvDTE.Property temp in txtEdCS)
            {
                prop = temp;
                msg  = ("Prop Name: " + prop.Name + "  VALUE: " + prop.Value) + "\n";
                propList.Add(msg);
            }

            return(propList);
        }
Пример #24
0
        private static async Task <Project> CreateProjectFromTemplateAsync(
            Solution2 solution2,
            string solutionFolderName,
            string projectTemplateFilePath,
            string destPath,
            string projectName)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (string.IsNullOrEmpty(solutionFolderName))
            {
                solution2.AddFromTemplate(projectTemplateFilePath, destPath, projectName, Exclusive: false);
                return(null);
            }
            else
            {
                var solutionFolderProject
                    = await VSSolutionHelper.GetSolutionFolderProjectAsync(solution2, solutionFolderName);

                var solutionFolder = (SolutionFolder)solutionFolderProject.Object;
                solutionFolder.AddFromTemplate(projectTemplateFilePath, destPath, projectName);

                return(solutionFolderProject);
            }
        }
Пример #25
0
        /// <summary>
        /// Removes the folder.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="folderName">Name of the folder.</param>
        public static void RemoveFolders(
            this Solution2 instance,
            string folderName)
        {
            List <Project> projects = instance.Projects.Cast <Project>().ToList();

            foreach (Project project in projects)
            {
                IEnumerable <ProjectItem> projectItems = project.GetProjectItems();

                if (projectItems != null)
                {
                    foreach (ProjectItem projectItem in projectItems)
                    {
                        ////if (projectItem.Kind == ProjectKinds.vsProjectKindPhysicalFolder)
                        if (projectItem.Kind == "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}")
                        {
                            if (projectItem.Name.ToLower() == folderName.ToLower())
                            {
                                projectItem.Remove();
                                break;
                            }
                        }
                    }
                }
            }
        }
Пример #26
0
      public static Project CreateAndAddUnitTestProject(Solution2 sol, string csProjectName, string csProjectPath, UnitTestCodeType codeType)
      {
         //System.Windows.Forms.MessageBox.Show("You must have at least 1 project in your current solution with a project name that ends with UnitTest");
         Project proj = null;

         try
         {
            String csItemTemplatePath;

            switch (codeType)
            {
               case UnitTestCodeType.CSharp:
                  csItemTemplatePath = sol.GetProjectTemplate(UTGHelper.CommonStrings.DEFAULT_PROJECT_TEMPLATE, UTGHelper.CommonStrings.DEFAULT_LANGUAGE);
                  break;
               case UnitTestCodeType.VB:
                  csItemTemplatePath = sol.GetProjectTemplate(UTGHelper.CommonStrings.DEFAULT_PROJECT_TEMPLATE, UTGHelper.CommonStrings.DEFAULT_VB_LANGUAGE);
                  break;
               default:
                  throw new Exception(string.Format(UTGHelper.CommonErrors.ERR_LANUAGE_TYPE_NOT_SUPPORTED, codeType.ToString()));
            }

            proj = sol.AddFromTemplate(csItemTemplatePath, csProjectPath, csProjectName, false);
         }
         catch (Exception ex)
         {
            Logger.LogException(ex);

            throw;
         }

         return proj;
      }
Пример #27
0
        public static bool GetProjectOrSolution(out Project project, out Solution2 solution)
        {
            var items = (Array)DTE.ToolWindows.SolutionExplorer.SelectedItems;

            project  = null;
            solution = null;

            foreach (UIHierarchyItem selItem in items)
            {
                var projItem = selItem.Object as Project;

                if (projItem != null)
                {
                    project = projItem;
                }

                var solItem = selItem.Object as Solution2;

                if (solItem != null)
                {
                    solution = solItem;
                }
            }

            return(project != null || solution != null);
        }
        public Project GetSolutionFolderProject(string solutionFolderName, bool createOnNull)
        {
            Solution2 solution = this.GetCurrentActiveSolution();

            Project solutionItemsProject = null;

            // Enumerating instead of using OfType<Project> due to a bug in
            // install shield projects that will throw an exception
            foreach (Project project in solution.Projects)
            {
                // Check if SonarQube solution folder already exists
                if (project.Name == solutionFolderName &&
                    project.Kind == ProjectSystemHelper.VsProjectItemKindSolutionFolder)
                {
                    solutionItemsProject = project;
                    break;
                }
            }

            // Create Solution Items folder if it does not exist
            if (solutionItemsProject == null && createOnNull)
            {
                solutionItemsProject = solution.AddSolutionFolder(solutionFolderName);
            }

            return(solutionItemsProject);
        }
        /// <summary>
        /// Runs this instance.
        /// </summary>
        public void Run()
        {
            this.AddTraceHeader("ViewModelAndViewsController", "Run");

            if (this.VisualStudioService.IsMvvmCrossSolution)
            {
                List <ItemTemplateInfo> templateInfos = this.VisualStudioService.AllowedItemTemplates;

                ViewModelOptionsView form = new ViewModelOptionsView(templateInfos);

                form.ShowDialog();

                if (form.Continue)
                {
                    this.VisualStudioService.DTE2.WriteStatusBarMessage("Ninja Coder is running....");

                    Solution2 solution = this.VisualStudioService.DTE2.GetSolution() as Solution2;

                    List <string> messages = solution.AddItemTemplateToProjects(form.Presenter.GetRequiredItemTemplates(), true);

                    //// we now need to amend code in the unit test file that references FirstViewModel to this ViewModel
                    this.UpdateUnitTestFile(form.ViewModelName);

                    //// show the readme.
                    this.ShowReadMe("Add ViewModel and Views", messages);

                    this.WriteStatusBarMessage("Ninja Coder has completed the adding of the viewmodel and views.");
                }
            }
            else
            {
                this.ShowNotMvvmCrossSolutionMessage();
            }
        }
Пример #30
0
 /// Runs custom wizard logic at the beginning of a template wizard run.
 /// <param name="automationObject">The automation object being used by the template wizard.</param>
 /// <param name="replacementsDictionary">The list of standard parameters to be replaced.</param>
 /// <param name="runKind">A <see cref="T:Microsoft.VisualStudio.TemplateWizard.WizardRunKind" /> indicating the type of wizard run.</param>
 /// <param name="customParams">The custom parameters with which to perform parameter replacement in the project.</param>
 public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
 {
     _dte                   = automationObject as DTE;
     _solution              = _dte.Solution as Solution2;
     _projectName           = replacementsDictionary["$safeprojectname$"];
     _replacementDictionary = replacementsDictionary;
 }
        public static string GetSolutionPath(Solution2 solution)
        {
            if (solution != null && solution.IsOpen)
            {
                var solutionPathFromSln = Path.GetDirectoryName(solution.FullName);

                var solutionPathInfo = new DirectoryInfo(solutionPathFromSln);
                Debug.WriteLine("Solution path is: " + solutionPathInfo.FullName);

                // find parent folder that holds the .git folder
                while (!Directory.Exists(Path.Combine(solutionPathInfo.FullName, ".git")))
                {
                    Debug.WriteLine("No .git folder found in solution path.");
                    if (solutionPathInfo.Parent == null)
                    {
                        Debug.WriteLine("No parent folder found. Using original path: " + solutionPathFromSln);
                        return(solutionPathFromSln);
                    }

                    solutionPathInfo = solutionPathInfo.Parent;
                }

                Debug.WriteLine("Using solution path: " + solutionPathInfo.FullName);
                return(solutionPathInfo.FullName);
            }

            return(null);
        }
Пример #32
0
        /// <summary>
        /// Adds the item template to project.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="templateInfos">The template infos.</param>
        public static void AddItemTemplateToProjects(
            this Solution2 instance,
            IEnumerable <ItemTemplateInfo> templateInfos)
        {
            IEnumerable <Project> projects = instance.GetProjects();

            TraceService.WriteError("AddItemTemplateToProjects project count=" + projects.Count());

            foreach (ItemTemplateInfo info in templateInfos)
            {
                Project project = projects.FirstOrDefault(x => x.Name.EndsWith(info.ProjectSuffix));

                if (project != null)
                {
                    project.AddToFolderFromTemplate(info.FolderName, info.TemplateName, info.FileName);
                }

                else
                {
                    TraceService.WriteError("AddItemTemplateToProjects cannot find project " + info.ProjectSuffix);

                    foreach (Project projectItem in projects)
                    {
                        string projectName = projectItem.Name;

                        TraceService.WriteError("AddItemTemplateToProjects project " + projectName);
                    }
                }
            }
        }
        /// <summary>
        /// Gets the projects.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <returns>The projects.</returns>
        public static IEnumerable <Project> GetProjects(this Solution2 instance)
        {
            ////TraceService.WriteLine("SolutionExtensions::GetProjects");

            List <Project> projects = instance.Projects.Cast <Project>().ToList();

            List <Project> list = new List <Project>();

            List <Project> .Enumerator item = projects.GetEnumerator();

            while (item.MoveNext())
            {
                Project project = item.Current;

                if (project == null)
                {
                    continue;
                }

                if (project.Kind == VSConstants.VsProjectKindSolutionItems)
                {
                    list.AddRange(project.GetSolutionFolderProjects());
                }
                else
                {
                    list.Add(project);
                }
            }

            return(list);
        }
Пример #34
0
        public Project AddProjectFromFileTo(Solution2 solution, string path)
        {
            if (!File.Exists(path) && solution == null)
                return null;

            Logger.WriteLine("Adding project from " + path + " to solution");
            return solution.AddFromFile(path, false);
        }
 public void RebuildDependecies(Solution2 oSolution)
 {
     IDictionary<String, List<String>> OutputData = new Dictionary<String, List<String>>();
     IDictionary<String, List<String>> InputData = new Dictionary<String, List<String>>();
     GatherBuildData(oSolution, ref OutputData, ref InputData);
     CleanDependencies(oSolution);
     RebuildDependencies(oSolution, OutputData, InputData);
 }
Пример #36
0
 public TemplatedItemCreator(Solution2 solution,
         TemplateMapping template,
         string[] relativePath)
 {
     this._solution = solution;
     this._template = template;
     this._relativePath = relativePath;
 }
        public CodeGenerator(DTE2 dte) {
            dte2 = dte;
            sln2 = (Solution2)dte2.Solution;

            removeT4Templates = new RemoveT4Templates(sln2);
            renameGeneratedCode = new RenameGeneratedCode(sln2);

            SetFindReplaceList();
        }
Пример #38
0
 private SolutionFolder FindSolutionFolderByName(Solution2 solution, string solutionFolderName)
 {
     foreach (Project project in solution.Projects)
     {
         if (project.Name == solutionFolderName)
             return project.Object as SolutionFolder;
     }
     return null;
 }
        public static Project FindProjectByName(Solution2 solution, string name)
        {
            foreach (Project project in solution.Projects) {
                if (project.Name == name)
                    return project;
            }

            return null;
        }
 public void CleanDependencies(Solution2 oSolution)
 {
     //just clean everything
     foreach (BuildDependency Dependency in oSolution.SolutionBuild.BuildDependencies)
     {
         if (Dependency.Project.Kind == "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}")
         {
             Dependency.RemoveAllProjects();
         }
     }
 }
Пример #41
0
    public WebConfigDlg()
    {
      InitializeComponent();

      dte = MySqlDataProviderPackage.GetGlobalService(
          typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;
      solution = (Solution2)dte.Solution;
      FindCurrentWebProject();
      EnsureWebConfig();
      LoadInitialState();
      PageChanged();
    }
Пример #42
0
        public Project AddProjectFromFileTo(Solution2 solution, string solutionFolderName, string path)
        {
            if (!File.Exists(path) && solution == null)
                return null;

            var solutionFolder = FindSolutionFolderByName(solution, solutionFolderName) ??
                                 solution.AddSolutionFolder(solutionFolderName).Object as SolutionFolder;

            if (solutionFolder == null)
                return null;

            Logger.WriteLine("Adding project from " + path + " to solution folder " + solutionFolderName);
            return solutionFolder.AddFromFile(path);
        }
        public XunitSolutionManager(IServiceProvider serviceProvider,
                                    INaming naming,
                                    IDirectory directory,
                                    string xunitPackageVersion,
                                    string visualStudioRunnerPackageVersion)
            : base(serviceProvider, naming, directory)
        {
            this.serviceProvider = serviceProvider;
            this.xunitPackageVersion = xunitPackageVersion;
            this.visualStudioRunnerPackageVersion = visualStudioRunnerPackageVersion;

            var dte = (DTE)this.serviceProvider.GetService(typeof(SDTE));
            solution = (Solution2)dte.Solution;
        }
        public void GatherBuildData(Solution2 oSolution, ref IDictionary<String, List<String>> OutputData, ref IDictionary<String, List<String>> InputData)
        {
            Projects SolutionProjects = oSolution.Projects;

            foreach (Project Proj in SolutionProjects)
            {
                List<VCProject> Projects = Utilities.GetProjects(Proj);
                foreach (VCProject VCProj in Projects)
                {
                    if (VCProj.Kind == "VCProject")
                    {
                        GatherBuildOutputData(VCProj, ref OutputData, ref InputData);
                    }
                }
            }
        }
Пример #45
0
 public static List<string> FindAllClientProject(Solution2 sln)
 {
     List<string> projList = new List<string>();
     string webPath = GetWebClientPath();
     foreach (Project proj in sln.Projects)
     {
         if (proj.Name != "AjaxTools" && proj.Name != "ChartTools" && proj.Name != "EEPNetClient"
             && proj.Name != "EEPNetAutoRun" && proj.Name != "EEPNetAutoRunForWeb" && proj.Name != webPath
             && proj.Name != "EEPManager" && proj.Name != "EEPMessgenger" && proj.Name != "InfoRemoteModule"
             && proj.Name != "EEPNetFLClient" && proj.Name != "EEPNetRunStep" && proj.Name != "EEPNetServer"
             && proj.Name != "FLCore" && proj.Name != "FLDesigner" && proj.Name != "FLDesignerCore"
             && proj.Name != "FLRuntime" && proj.Name != "FLTools" && proj.Name != "GLModule"
             && proj.Name != "InitEEP" && proj.Name != "MWizard" && proj.Name != "Srvtools")
         {
             projList.Add(proj.Name);
         }
     }
     return projList;
 }
Пример #46
0
 public static Project AddProjectToSolution(string projectName, string projectTemplateFile, string projectTemplateLanguage, string[] filesToRemove, Solution2 currentSolution)
 {
     if (!currentSolution.IsOpen || projectName == string.Empty) return null;
     string destinationPath = GetSolutionPath((Solution)currentSolution);
     destinationPath += "\\" + projectName;
     string csTemplatePath = currentSolution.GetProjectTemplate(projectTemplateFile, projectTemplateLanguage);
     Project newProject = currentSolution.AddFromTemplate(csTemplatePath, destinationPath, projectName, false);
     if (newProject == null)
     {
         if (projectTemplateLanguage == "Web" || projectTemplateLanguage == "Web\\CSharp")
         {
             projectName = destinationPath + "\\";
         }
         foreach (Project p in currentSolution.Projects)
         {
             if (p.Name == projectName)
             {
                 newProject = p;
             }
         }
     }
     if (newProject != null)
     {
         foreach (ProjectItem item in newProject.ProjectItems)
         {
             foreach (string filename in filesToRemove)
             {
                 if (item.Name == filename)
                 {
                     item.Delete();
                     break;
                 }
             }
         }
     }
     else
     {
         throw new Exception("Unable to locate project in solution after it was created (" + projectName + ")");
     }
     return newProject;
 }
Пример #47
0
      /// <summary>
      /// Adds a Class to the specified project in the solution.
      /// </summary>
      /// <param name="soln">The solution</param>
      /// <param name="proj">The project</param>
      /// <param name="className">The name of class you wish to create</param>
      /// <param name="postFix">String postfix</param>
      /// <param name="preFix">String prefix</param>
      /// <param name="extension">Extension like .cs or .vb</param>
      /// <returns>ProjectItem on success. Null otherwise</returns>
      static public ProjectItem AddClassToProject(Solution2 soln, Project proj, string className, string postFix, string preFix, string extension)
      {
         if (soln == null)
            throw new Exception("Invalid  DTE2 parameter");

         if (proj == null)
            throw new Exception("Invalid  Project parameter");

         if (className.Equals(string.Empty) || className.Equals(""))
            throw new Exception("Invalid  className parameter");

         if (extension.Equals(string.Empty) || extension.Equals(""))
            throw new Exception("Invalid  extension parameter");

         ProjectItem projectItem = null;

         try
         {
            String csItemTemplatePath = soln.GetProjectItemTemplate("CodeFile",
             "CSharp");

            proj.ProjectItems.AddFromTemplate(csItemTemplatePath, className + preFix + "." + extension);

            projectItem = proj.ProjectItems.Item(className + preFix + "." + extension);
         }
         catch (Exception ex)
         {
            Logger.LogException(ex);

            ErrorHandler.HandleException(ex);
         }

         return projectItem;
      }
Пример #48
0
      /// <summary>
      /// Adds a Class to the specified project in the solution.
      /// </summary>
      /// <param name="soln">The solution</param>
      /// <param name="proj">The project</param>
      /// <param name="className">The name of class you wish to create</param>
      /// <param name="extension">Extension like .cs or .vb</param>
      /// <returns>ProjectItem on success. Null otherwise</returns>
      static public ProjectItem AddClassToProject(Solution2 soln, Project proj, string className, string extension)
      {
         if (soln == null)
            throw new Exception("Invalid  DTE2 parameter");

         if (proj == null)
            throw new Exception("Invalid  Project parameter");

         if (className.Equals(string.Empty) || className.Equals(""))
            throw new Exception("Invalid  className parameter");

         if (extension.Equals(string.Empty) || extension.Equals(""))
            throw new Exception("Invalid  extension parameter");

         return AddClassToProject(soln, proj, className, "", "", extension);
      }
Пример #49
0
 public static Project AddClassLibraryProjectToSolution(string projectName, Solution2 currentSolution)
 {
     return AddProjectToSolution(projectName, "ClassLibrary.zip", "CSharp", new string[] { "Class1.cs" }, currentSolution);
 }
Пример #50
0
 public static Project AddConsoleAppProjectToSolution(string projectName, Solution2 currentSolution)
 {
     return AddProjectToSolution(projectName, "ConsoleApplication.zip", "CSharp", new string[] { "Program.cs" }, currentSolution);
 }
 public void InitTargetDTE()
 {
     System.Type t = Connect.settingsObject.VisualStudioVersion;
     object obj = Activator.CreateInstance(t, true);
     targetDTE2 = (DTE2)obj;
     targetSolution2 = (Solution2)targetDTE2.Solution;
 }
 public RenameGeneratedCode(Solution2 sln2)
 {
     base.sln2 = sln2;
 }
        public void RunStarted(object automationObject,
            Dictionary<string, string> replacementsDictionary,
            WizardRunKind runKind, object[] customParams)
        {
            this._dte2 = (DTE2)automationObject;
            this._solution2 = (Solution2)this._dte2.Solution;
            this._replacementsDictionary = replacementsDictionary;
            this._replacementsDictionary["$targetsilverlightversion$"] = TemplateUtilities.GetSilverlightVersion(automationObject);
            this._dte2.Globals["safeclientprojectname"] = replacementsDictionary["$safeprojectname$"];
            this._webProjectName = this._replacementsDictionary["$safeprojectname$"] + ".Web";
            this._customParams = customParams;

            // Determine whether the user has asked to add this to an existing Solution Folder.
            // We do this at startup because the active project will be changed during the creation
            // of the template.  If _selectedSolutionFolder is null, it means the user did not ask
            // to create the business application under a SolutionFolder.
            Array projects = null;
            try
            {
                projects = (Array)this._dte2.ActiveSolutionProjects;
            }
            catch (COMException)
            {
            }
            Project activeProject = projects == null ? null : projects.OfType<Project>().FirstOrDefault();
            if (activeProject != null && activeProject.Kind == ProjectKinds.vsProjectKindSolutionFolder)
            {
                this._selectedSolutionFolder = activeProject;
            }
        }
 public TraverseProjectTree(Solution2 sln2)
 {
     this.sln2 = sln2;
 }
 public RemoveT4TemplatesFromSolution(Solution2 sln2)
 {
     base.sln2 = sln2;
 }
 public RenameT4Templates(Solution2 sln2)
 {
     base.sln2 = sln2;
 }
Пример #57
0
        public static void AddFileToSolutionFolder(string file, Solution2 solution)
        {
            Project currentProject = null;

            foreach (Project project in solution.Projects)
            {
                if (project.Kind == EnvDTE.Constants.vsProjectKindSolutionItems && project.Name == "Solution Items")
                {
                    currentProject = project;
                    break;
                }
            }

            if (currentProject == null)
                currentProject = solution.AddSolutionFolder("Solution Items");

            currentProject.ProjectItems.AddFromFile(file);
        }
Пример #58
0
 public static Project AddWebProjectToSolution(string projectName, Solution2 currentSolution)
 {
     return AddProjectToSolution(projectName, "WebApplication.zip", "Web\\CSharp", new string[] { "Default.aspx" }, currentSolution);
 }
Пример #59
0
 private string GetDestReadMePath(Solution2 solution, string templateName)
 {
     var solutionPath = solution.Properties.Item("Path").Value as string;
     if (string.IsNullOrWhiteSpace(solutionPath)) return null;
     string solutionDir = new FileInfo(solutionPath).DirectoryName;
     if (string.IsNullOrWhiteSpace(solutionDir)) return null;
     string readMeFileName = GetReadMeFileName(templateName);
     return Path.Combine(solutionDir, readMeFileName);
 }
Пример #60
0
      static public ProjectItem AddClassToProject(Solution2 soln, Project proj, string classFullPath)
      {
         if (soln == null)
            throw new Exception("Invalid  DTE2 parameter");

         if (proj == null)
            throw new Exception("Invalid  Project parameter");

         ProjectItem projectItem = null;

         try
         {
            projectItem = proj.ProjectItems.AddFromFile(classFullPath);

         }
         catch (Exception ex)
         {
            Logger.LogException(ex);

            ErrorHandler.HandleException(ex);
         }

         return projectItem;
      }