public void TestMoreAutomationOnProjectItems() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode projectNode = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); EnvDTE.Project project = projectNode.GetAutomationObject() as EnvDTE.Project; EnvDTE80.Solution2 solution = project.DTE.Solution as EnvDTE80.Solution2; string templateName = solution.GetProjectItemTemplate("CodeFile.zip", "CSharp"); ProjectItem item = project.ProjectItems.AddFromTemplate(templateName, "TestFile.cs"); this.CheckForItem(projectNode, item); // Now add a folder and add an item to the folder. ProjectItem folder = project.ProjectItems.AddFolder("Directory", null); item = folder.ProjectItems.AddFromTemplate(templateName, "TestFile1.cs"); this.CheckForItem(projectNode, item); }); }
private void AddToProject(string edmxPath) { ProjectItem pi = _vsProj.Project.ProjectItems.AddFromFile(edmxPath); // this little magic replaces having to use System.Data.Entity.Design.EntityCodeGenerator pi.Properties.Item("ItemType").Value = "EntityDeploy"; pi.Properties.Item("CustomTool").Value = "EntityModelCodeGenerator"; if (efVersion == BaseWizard <BaseWizardForm, BaseCodeGeneratorStrategy> .ENTITY_FRAMEWORK_VERSION_6) { // For EF6 we use DbContext instead of ObjectContext based context. _vsProj.DTE.SuppressUI = true; EnvDTE80.Solution2 sol = (EnvDTE80.Solution2)_vsProj.DTE.Solution; string itemPath = ""; if (this.Language == LanguageGenerator.CSharp) { itemPath = sol.GetProjectItemTemplate("DbCtxCSEF6", "CSharp"); } else { itemPath = sol.GetProjectItemTemplate("DbCtxVBEF6", "VisualBasic"); } pi.ProjectItems.AddFromTemplate(itemPath, this._modelName); // update $edmxInputFile$ string path = Path.GetDirectoryName(edmxPath); string templateName = Path.Combine(path, _modelName + ".tt"); string contents = File.ReadAllText(templateName); File.WriteAllText(templateName, contents.Replace("$edmxInputFile$", _modelName + ".edmx")); templateName = Path.Combine(path, _modelName + ".Context.tt"); contents = File.ReadAllText(templateName); File.WriteAllText(templateName, contents.Replace("$edmxInputFile$", _modelName + ".edmx")); } }
public static List <EnvDTE.Project> GetProjects(this EnvDTE80.Solution2 solution) { var projects = new List <EnvDTE.Project>(); for (var ii = 1; ii <= solution.Count; ii++) { var project = solution.Item(ii); if (project.Kind == "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") { projects.Add(project); } } var folders = solution.GetFolders(); foreach (var f in folders) { for (var ii = 1; ii <= f.ProjectItems.Count; ii++) { var project = f.ProjectItems.Item(ii); var p = project.Object as EnvDTE.Project; if (p != null) { projects.Add(p); } } //((EnvDTE.ProjectItem)(CurrentSolution.GetFolders()[0].ProjectItems.Item(1))).Name } return(projects); }
/// <summary> /// If the project support VsTemplates, returns the path to /// the vstemplate file corresponding to the requested template /// /// You can pass in a string such as: "Windows\Console Application" /// </summary> /*internal, but public for FSharp.Project.dll*/ public string GetVsTemplateFile(string templateFile) { // First see if this use the vstemplate model if (!String.IsNullOrEmpty(DefaultProjectExtensionValue)) { EnvDTE80.DTE2 dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; if (dte != null) { EnvDTE80.Solution2 solution = dte.Solution as EnvDTE80.Solution2; if (solution != null) { string fullPath = solution.GetProjectTemplate(templateFile, DefaultProjectExtensionValue); // The path returned by GetProjectTemplate can be in the format "path|FrameworkVersion=x.y|Language=xxx" // where the framework version and language sections are optional. // Here we are interested only in the full path, so we have to remove all the other sections. int pipePos = fullPath.IndexOf('|'); if (0 == pipePos) { return(null); } if (pipePos > 0) { fullPath = fullPath.Substring(0, pipePos); } return(fullPath); } } } return(null); }
private Project AddProjectToSolutionFolder(Project project1, string folderName) { ThreadHelper.ThrowIfNotOnUIThread(); try { EnvDTE80.Solution2 solution = (EnvDTE80.Solution2)_dte.Solution; if (solution == null) { return(null); } string projFullname = project1.FullName; Project project = GetSolutionSubFolder(solution, folderName); if (project != null) { EnvDTE80.SolutionFolder folder = (EnvDTE80.SolutionFolder)project.Object; solution.Remove(project1); project1 = folder.AddFromFile(projFullname); } } catch (Exception) { return(null); } return(project1); }
public static async Task <EnvDTE.Project> GetProjectAsync(EnvDTE80.Solution2 solution2, string projectName) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(solution2 .Projects .Cast <EnvDTE.Project>() .FirstOrDefault(project => project.Name.Equals(projectName, StringComparison.OrdinalIgnoreCase))); }
/// <summary> /// Delete an item from a project /// </summary> public override void Execute() { DTE vs = GetService <DTE>(true); EnvDTE80.Solution2 sln = (EnvDTE80.Solution2)vs.Solution; if (DteHelper.FindSolutionFolderByPath(vs.Solution, solutionFolderName) == null) { sln.AddSolutionFolder(solutionFolderName); } }
/// <summary> /// Called at load time when solution has finished opening. /// </summary> /// <param name="pUnkReserved">reserved</param> /// <param name="fNewSolution">true if this is a new solution</param> /// <returns></returns> public override int OnAfterOpenSolution(object pUnkReserved, int fNewSolution) { // Restart scanning. Was suspended on opening of project system // or closing of previous solution EnvDTE80.DTE2 dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; EnvDTE80.Solution2 solution = dte.Solution as EnvDTE80.Solution2; var solutionFile = solution.FullName; if (string.IsNullOrEmpty(solutionFile)) { if (projectfiles.Count > 0) { // open a project without solution. // assume solution name is the same as project name with different extension solutionFile = System.IO.Path.ChangeExtension(projectfiles[0], ".sln"); } } if (!string.IsNullOrEmpty(solutionFile)) { XSharpModel.XSolution.Open(solutionFile); XSharpProjectPackage.Instance.SetCommentTokens(); } projectfiles.Clear(); /* * Code below to detect items in solution folders * var projects = solution.Projects; * var folder1 = new Guid("{66A26720-8FB5-11D2-AA7E-00C04F688DDE}"); // = Project Folder * var folder2 = new Guid("{2150E333-8FDC-42A3-9474-1A3956D46DE8}"); // Solution Folder * foreach (var prj in projects) * { * var project = (EnvDTE.Project)prj; * var kind = new Guid(project.Kind); * var name = project.FullName; * if (kind == folder1 || kind == folder2) * { * foreach (var item in project.ProjectItems) * { * var prjItem = (EnvDTE.ProjectItem)item; * if (prjItem.Object == null) * { * for (short i = 1; i <= prjItem.FileCount; i++) * { * var file = prjItem.FileNames[i]; * Debug.WriteLine(file); * } * } * } * } * * } */ return(VSConstants.S_OK); }
private static EnvDTE.ProjectItem FindSolutionItemByFileExtension(EnvDTE80.Solution2 soln, string extension) { foreach (EnvDTE.Project project in soln.Projects) { foreach (EnvDTE.ProjectItem item in project.ProjectItems) { if (Path.GetExtension(item.Name) == extension) { return(item); } } } return(null); }
public void OpenSolution(string path, bool saveExistingSolutionIfExists = false) { var dte = GetDTE(); if (dte.Solution.IsOpen) { CloseSolution(saveExistingSolutionIfExists); } dte.Solution.Open(path); _solution = (EnvDTE80.Solution2)dte.Solution; _fileName = path; }
public static List <EnvDTE.Project> GetFolders(this EnvDTE80.Solution2 solution) { var folders = new List <EnvDTE.Project>(); for (var ii = 1; ii <= solution.Count; ii++) { var project = solution.Item(ii); if ((project.Kind == "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}") || (project.Kind == "{66A26722-8FB5-11D2-AA7E-00C04F688DDE}")) { folders.Add(project); } } return(folders); }
/// <summary> /// If the project support VsTemplates, returns the path to /// the vstemplate file corresponding to the requested template /// /// You can pass in a string such as: "Windows\Console Application" /// </summary> internal string GetVsTemplateFile(string templateFile) { // First see if this use the vstemplate model if (!String.IsNullOrEmpty(DefaultProjectExtensionValue)) { EnvDTE80.DTE2 dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; if (dte != null) { EnvDTE80.Solution2 solution = dte.Solution as EnvDTE80.Solution2; if (solution != null) { return(solution.GetProjectTemplate(templateFile, DefaultProjectExtensionValue)); } } } return(null); }
/// <summary> /// Creates and loads a new solution in the host process, optionally saving the existing solution if one exists. /// </summary> public void CreateSolution(string solutionName, bool saveExistingSolutionIfExists = false) { var dte = GetDTE(); if (dte.Solution.IsOpen) { CloseSolution(saveExistingSolutionIfExists); } var solutionPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); IntegrationHelper.DeleteDirectoryRecursively(solutionPath); dte.Solution.Create(solutionPath, solutionName); _solution = (EnvDTE80.Solution2)dte.Solution; _fileName = Path.Combine(solutionPath, $"{solutionName}.sln"); }
private void TemplateGeneratePreview() { if (DTE.SelectedItems.Count == 0) { return; } EnvDTE80.Solution2 solution2 = (EnvDTE80.Solution2)DTE.Solution; var projectItemTemplate = solution2.GetProjectItemTemplate("KalView", "CSharp"); try { if (DTE.SelectedItems.Item(1).ProjectItem != null) { DTE.SelectedItems.Item(1).ProjectItem.ProjectItems.AddFromTemplate(projectItemTemplate, "Kiszka.cs"); } else { DTE.SelectedItems.Item(1).Project.ProjectItems.AddFromTemplate(projectItemTemplate, "Kiszka.cs"); } var lst = new ObservableCollection <NameValue>(); var eList = WizardInfoWrapper.EvaluatedReplacementDictionary ?? new Dictionary <string, string>(); InputParameterListRefreshCommand.ExecuteIfCan(); foreach (var item in eList) { var inputParameter = InputParameterList.FirstOrDefault(p => p.Name == item.Key); if (inputParameter == null) { lst.Add(new NameValue { Name = item.Key, Value = item.Value }); } else { inputParameter.Value = item.Value; } } EvaluatedParameterList = lst; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void AddNewItemFromVsTemplate(string templateName, string language, string name) { if (name == null) { throw new ArgumentException("name"); } int activeProject = GetActiveProject(); ProjectItems parent = dte.Solution.Projects.Item(activeProject).ProjectItems; if (parent == null) { throw new ArgumentException("project"); } EnvDTE80.Solution2 sol = dte.Solution as EnvDTE80.Solution2; string filename = sol.GetProjectItemTemplate(templateName, language); parent.AddFromTemplate(filename, name); }
// http://social.msdn.microsoft.com/Forums/vstudio/en-US/36adcd56-5698-43ca-bcba-4527daabb2e3/finding-the-startup-project-in-a-complicated-solution public static EnvDTE.Project GetProject(EnvDTE80.Solution2 solution, string uniqueName) { EnvDTE.Project ret = null; if (solution != null && uniqueName != null) { foreach (EnvDTE.Project p in solution.Projects) { ret = GetSubProject(p, uniqueName); if (ret != null) { break; } } } return(ret); }
public static List <EnvDTE.Project> GetFolders(this EnvDTE80.Solution2 solution) { var folders = new List <EnvDTE.Project>(); for (var ii = 1; ii <= solution.Count; ii++) { var project = solution.Item(ii); switch (project.Kind) { case "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}": case "{66A26722-8FB5-11D2-AA7E-00C04F688DDE}": folders.Add(project); break; default: break; } } return(folders); }
private static Project GetSolutionSubFolder(EnvDTE80.Solution2 solution, string folderName) { ThreadHelper.ThrowIfNotOnUIThread(); Projects projects = solution.Projects; Project folder = null; foreach (Project project in projects) { if (!string.Equals(project.Name, folderName)) { continue; } folder = project; break; } return(folder ?? solution.AddSolutionFolder(folderName)); }
public static async Task <EnvDTE.Project> GetSolutionFolderProjectAsync(EnvDTE80.Solution2 solution2, string solutionFolderName) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var solutionFolderParts = solutionFolderName.Split('\\'); var solutionFolderProject = await GetSolutionFolderProjectAsync(solution2.Projects, solutionFolderParts, 0); if (solutionFolderProject == null) { throw new ArgumentException("No corresponding solution folder exists", nameof(solutionFolderName)); } var solutionFolder = solutionFolderProject.Object as EnvDTE80.SolutionFolder; if (solutionFolder == null) { throw new ArgumentException("Not a valid solution folder", nameof(solutionFolderName)); } return(solutionFolderProject); }
public static List <EnvDTE.Project> GetProjects(this EnvDTE80.Solution2 solution) { var projects = new List <EnvDTE.Project>(); for (var ii = 1; ii <= solution.Count; ii++) { var project = solution.Item(ii); switch (project.Kind) { //List: https://www.codeproject.com/reference/720512/list-of-visual-studio-project-type-guids case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}": //C# case "{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}": //ASP.NET 5 case "{9A19103F-16F7-4668-BE54-9A1E7A4F7556}": //.NET Core projects.Add(project); break; default: break; } } var folders = solution.GetFolders(); foreach (var f in folders) { for (var ii = 1; ii <= f.ProjectItems.Count; ii++) { var project = f.ProjectItems.Item(ii); var p = project.Object as EnvDTE.Project; if (p != null) { projects.Add(p); } } //((EnvDTE.ProjectItem)(CurrentSolution.GetFolders()[0].ProjectItems.Item(1))).Name } return(projects); }
internal Solution(DteSolution dteSolution, string fileName) { if (dteSolution == null) { throw new ArgumentNullException(nameof(dteSolution)); } if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentNullException(nameof(fileName)); } _dteSolution = dteSolution; _fileName = fileName; _projectTemplates = new Dictionary <ProjectTemplate, string> { [ProjectTemplate.ClassLibrary] = $@"Windows\{dteSolution.DTE.LocaleID}\ClassLibrary.zip", [ProjectTemplate.ConsoleApplication] = "ConsoleApplication.zip", [ProjectTemplate.Website] = "EmptyWeb.zip", [ProjectTemplate.WinFormsApplication] = "WindowsApplication.zip", [ProjectTemplate.WpfApplication] = "WpfApplication.zip", [ProjectTemplate.WebApplication] = "WebApplicationProject40" }; }
internal Solution(DteSolution dteSolution, string fileName) { if (dteSolution == null) { throw new ArgumentNullException(nameof(dteSolution)); } if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentNullException(nameof(fileName)); } _dteSolution = dteSolution; _fileName = fileName; _projectTemplates = new Dictionary<ProjectTemplate, string> { [ProjectTemplate.ClassLibrary] = $@"Windows\{dteSolution.DTE.LocaleID}\ClassLibrary.zip", [ProjectTemplate.ConsoleApplication] = "ConsoleApplication.zip", [ProjectTemplate.Website] = "EmptyWeb.zip", [ProjectTemplate.WinFormsApplication] = "WindowsApplication.zip", [ProjectTemplate.WpfApplication] = "WpfApplication.zip", [ProjectTemplate.WebApplication] = "WebApplicationProject40" }; }
public void ProjectFinishedGenerating(Project project) { if (selectedTypes != null) { string validationErrors = string.Empty; string itemPath = null; string fileExtension = null; EnvDTE80.Events2 objEvents2; EnvDTE80.Solution2 solution = project.DTE.Solution as EnvDTE80.Solution2; OutputWindowManager outPutWindowmng = new OutputWindowManager(); // Subscribe all the IDE events envDTE = project.DTE; objEvents2 = ((EnvDTE80.Events2)(envDTE.Events)); // Subscribe the item added event projectItemsEvents = objEvents2.ProjectItemsEvents; projectItemsEvents.ItemAdded += ProjectItemsEvents_ItemAdded; // Write the post-build command to register the assembly. if (VSOptionsValidator.CanCreatePostBuildEvent(ref validationErrors)) { // Build the command to call. string erpPath = Path.Combine(GeneralOptions.Instance.Path, "RegisterExtension.exe"); if (File.Exists(erpPath)) { // Add command-line parameters. string command = $"Call {string.Format("\"{0}\"", erpPath)} " + $" {GeneralOptions.Instance.Company} {GeneralOptions.Instance.UserName}" + $" {GeneralOptions.Instance.Password} {GeneralOptions.Instance.ProductLine}" + $" $(TargetPath) {GeneralOptions.Instance.CommonExtension}"; EnvDTE.Properties configmg = project.Properties; configmg.Item("PostBuildEvent").Value = command; outPutWindowmng.WriteMessage("The post-build command was added to the project.", OutputWindowMessagesType.Message); // Set start external program string erpEpp = string.Format("Erp100L{0}.exe", GeneralOptions.Instance.ProductLine == 0 ? "E" : "P"); Configuration activeConfig = project.ConfigurationManager.ActiveConfiguration; activeConfig.Properties.Item("StartAction").Value = prjStartAction.prjStartActionProgram; activeConfig.Properties.Item("StartProgram").Value = Path.Combine(GeneralOptions.Instance.Path, erpEpp); outPutWindowmng.WriteMessage("The start external program was set.", OutputWindowMessagesType.Message); } else { StringBuilder msg = new StringBuilder(); msg.Append("The post-build command could not be registered. \n"); msg.Append("The command line utility does not exist on the folder."); msg.Append(GeneralOptions.Instance.Path); msg.Append("Download it from https://developers.primaverabss.com/v10/como-automatizar-registo-extensoes/ \n"); outPutWindowmng.WriteMessage(msg.ToString(), OutputWindowMessagesType.Error); } } else { outPutWindowmng.WriteMessage("The post-build event has not been configured because of the following validation issues:", OutputWindowMessagesType.Warning); outPutWindowmng.WriteMessage(validationErrors, OutputWindowMessagesType.Message); outPutWindowmng.WriteMessage("Check this on Tools | Options | PRIMAVERA Extensibility.", OutputWindowMessagesType.Message); } if (project.Kind == PrjKind.prjKindCSharpProject) { itemPath = solution.GetProjectItemTemplate("PriClass.zip", "CSharp"); fileExtension = ".cs"; } else { itemPath = solution.GetProjectItemTemplate("PriClass.zip", "VisualBasic"); fileExtension = ".vb"; } if (!String.IsNullOrEmpty(itemPath)) { // Add generic references WizardHelper.AddBaseReferences(project, "Bas", GeneralOptions.Instance.Path); WizardHelper.AddBaseReferences(project, "Ext", GeneralOptions.Instance.Path); foreach (MyTreeNode type in selectedTypes) { this.SelectedNode = type; ProjectItem rootFolder = project.ProjectItems.Cast <ProjectItem>() .FirstOrDefault(i => i.Name == type.Module) ?? project.ProjectItems.AddFolder(type.Module); // Add the module reference. WizardHelper.AddModuleReference(project, "Primavera.Extensibility." + type.Module); // Add dependencies to the select modules. WizardHelper.AddDependenciesReference(project, type.Module); switch (type.ModuleType) { case "Editors": rootFolder.ProjectItems.AddFromTemplate(itemPath, "Ui" + type.ClassName + fileExtension); break; case "Services": rootFolder.ProjectItems.AddFromTemplate(itemPath, "Api" + type.ClassName + fileExtension); break; } } } outPutWindowmng.WriteMessage("The project was created with success."); // UnSubscribing event. projectItemsEvents.ItemAdded -= ProjectItemsEvents_ItemAdded; } }
public static async Task <bool> IsSolutionAvailableAsync(EnvDTE80.Solution2 solution2) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(solution2 != null && solution2.IsOpen); }
public void ProjectFinishedGenerating(Project project) { if (_selectedTypes != null) { string _validationErrors = string.Empty; string _itemPath = null; string _fileExtension = null; EnvDTE80.Events2 _objEvents2; EnvDTE80.Solution2 _solution = project.DTE.Solution as EnvDTE80.Solution2; OutputWindowManager outPutWindowmng = new OutputWindowManager(); // Subscribe all the IDE events _envDTE = project.DTE; _objEvents2 = ((EnvDTE80.Events2)(_envDTE.Events)); // Write the post-build command to register the assembly. if (VSOptionsValidator.CanCreatePostBuildEvent(ref _validationErrors)) { // Add command-line parameters. string command = $"copy /Y \"$(TargetPath)\" \"{WebApiOptions.Instance.Path}\\$(ProjectName).dll\""; EnvDTE.Properties configmg = project.Properties; configmg.Item("PostBuildEvent").Value = command; outPutWindowmng.WriteMessage("The post-build command was added to the project.", OutputWindowMessagesType.Message); } else { outPutWindowmng.WriteMessage("The post-build event has not been configured because of the following validation issues:", OutputWindowMessagesType.Warning); outPutWindowmng.WriteMessage(_validationErrors, OutputWindowMessagesType.Message); outPutWindowmng.WriteMessage("Check this on Tools | Options | PRIMAVERA Extensibility.", OutputWindowMessagesType.Message); } if (project.Kind == PrjKind.prjKindCSharpProject) { _itemPath = _solution.GetProjectItemTemplate("PriWebApiControler.zip", "CSharp"); _fileExtension = ".cs"; } else { _itemPath = _solution.GetProjectItemTemplate("PriWebApiControler.zip", "VisualBasic"); _fileExtension = ".vb"; } // Add folder to keep all controllers. ProjectItem rootFolder = project.ProjectItems.AddFolder("Controllers"); // Add the class to the project. rootFolder.ProjectItems.AddFromTemplate(_itemPath, _controllerName + _fileExtension); // Add generic references //WizardHelper.AddApiBaseDependencies(project); WizardHelper.AddBaseReferences(project, "Bas", GeneralOptions.Instance.Path); WizardHelper.AddBaseReferences(project, "Api", WebApiOptions.Instance.Path); // Add references to the select modules foreach (TreeNode type in _selectedTypes) { if (!String.IsNullOrEmpty(_itemPath)) { // Add dependencies to the select modules. WizardHelper.AddDependenciesReference(project, type.Text); } } outPutWindowmng.WriteMessage("The project was created with success."); } }
private readonly string _fileName; // Cache the filename as `_dteSolution` won't expose it unless the solution has been saved internal Solution(DteSolution dteSolution, string fileName) { _dteSolution = dteSolution; _fileName = fileName; }