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"); } }
/// <summary> /// Creates solution directory and includes files from destination /// </summary> private void createSolutionDirAndFiles(string SolutionDir, string SourcePath, string DestinationPath) { // Add a solution Folder for the //Solution Items ( from root ) string[] dirs = SolutionDir.Split('\\'); EnvDTE.Project solutionsFolderProject = _solution.AddSolutionFolder(dirs[0]); // Add sub directories if needed for (int i = 1; i < dirs.Count(); i++) { SolutionFolder SF = (SolutionFolder)solutionsFolderProject.Object; solutionsFolderProject = SF.AddSolutionFolder(dirs[i]); } // Copy and add the files foreach (string newPath in Directory.GetFiles(SourcePath, "*.*", SearchOption.TopDirectoryOnly)) { // The filename to copy over string fileName = newPath.Replace(SourcePath, DestinationPath); // Don't add the fake project if (!fileName.EndsWith("proj")) { // Strip out extra directory character fileName = fileName.Replace("\\\\", "\\"); // Copy to new home on hard drive File.Copy(newPath, fileName, true); Logger.Log("Rootwizard ~~~~ Adding File to solution=" + fileName); // Add the item from the local hard drive to the project EnvDTE.ProjectItem addedFile = solutionsFolderProject.ProjectItems.AddFromFile(fileName); // Optionally close the pointless window to clean up the solution from the start addedFile.DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo); } } }
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"); }
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); }
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 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(); }
public static Project GetSolutionItemsProject() { Solution2 solution = TsWspPackage.DTE.Solution as Solution2; return(solution.Projects .OfType <Project>() .FirstOrDefault(p => p.Name.Equals(TsWspConstants.SOLUTION_ITEMS_FOLDER, StringComparison.OrdinalIgnoreCase)) ?? solution.AddSolutionFolder(TsWspConstants.SOLUTION_ITEMS_FOLDER)); }
/// <summary> /// Executes the action. /// </summary> public override void Execute() { EnvDTE.DTE vs = this.GetService <EnvDTE.DTE>(true); // Add the solution folder Solution2 sln = (Solution2)vs.Solution; sln.AddSolutionFolder(Name); }
///<summary>Gets the Solution Items solution folder in the current solution, creating it if it doesn't exist.</summary> public static Project GetSolutionItemsProject() { Solution2 solution = EditProjectPackage.DTE.Solution as Solution2; return(solution.Projects .OfType <Project>() .FirstOrDefault(p => p.Name.Equals(SolutionItemsFolder, StringComparison.OrdinalIgnoreCase)) ?? solution.AddSolutionFolder(SolutionItemsFolder)); }
public static Project GetOrCreateSolutionFolder(this Solution solution, string name) { if (solution.TryFindSolutionFolder(name, out Project solutionFolder)) { return(solutionFolder); } Solution2 solution2 = solution as Solution2; return(solution2.AddSolutionFolder(name)); }
/// <summary> /// Adds the item. /// </summary> /// <param name="instance">The instance.</param> /// <param name="solutionFolder">The solution folder.</param> /// <param name="path">The path.</param> /// <returns> /// The project item. /// </returns> public static ProjectItem AddSolutionItem( this Solution2 instance, string solutionFolder, string path) { TraceService.WriteLine("SolutionExtensions::AddSolutionItem path=" + path); Project project = instance.GetProject(solutionFolder) ?? instance.AddSolutionFolder(solutionFolder); return(project.ProjectItems.AddFromFile(path)); }
public override void Execute() { string snPath = GetBasePath() + "\\Tools\\sn.exe"; DTE dte = this.GetService <DTE>(true); string solutionPath = (string)dte.Solution.Properties.Item("Path").Value; string solutionDir = Path.GetDirectoryName(solutionPath); string keyFilePath = Path.Combine(solutionDir, this.KeyFileName); // Launch the process and wait until it's done (with a 10 second timeout). ProcessStartInfo startInfo = new ProcessStartInfo(snPath, string.Format("-k \"{0}\"", keyFilePath)); startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; Process snProcess = Process.Start(startInfo); snProcess.WaitForExit(20000); try { Solution2 soln = (Solution2)dte.Solution; Project projecttargetfolder = Helpers.GetSolutionFolder(soln, "ApplicationConfiguration"); if (projecttargetfolder == null) { projecttargetfolder = soln.AddSolutionFolder("ApplicationConfiguration"); } if (projecttargetfolder != null) { try { Helpers.AddFromFile(projecttargetfolder, keyFilePath); dte.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo); } catch (Exception ex) { Helpers.LogMessage(dte, this, ex.ToString()); } } //dte.Solution.AddFromFile(keyFilePath, false); //dte.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); /* * DteHelper.SelectSolution(dte); * dte.ItemOperations.AddExistingItem(keyFilePath); * dte.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); * */ } catch (Exception) { } }
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); }
/// <summary> /// 新增项目文件夹 /// </summary> /// <param name="dte"></param> /// <param name="folderName">文件夹名称</param> /// <returns></returns> public static Project AddSolutionFolder(this DTE dte, string folderName) { Project project = null; try { Solution2 sln = dte.Solution as Solution2; project = (dte.Solution as Solution).FindProject(folderName); if (project == null) { project = sln.AddSolutionFolder(folderName); } } catch (Exception ex) { throw ex; } return(project); }
public void ProjectFinishedGenerating(Project project) { //Get the DTE related to the solution EnvDTE.DTE dte = project.DTE; //Get the first project of all the solution project Project firstProject = dte.Solution.Projects.Cast <Project>().FirstOrDefault(); //Cast the project items as IEnumerable<ProjectItem> IEnumerable <ProjectItem> projectItems = firstProject.ProjectItems.Cast <ProjectItem>(); //Cast the solution as s Solution2 (has the AddSolutionFolder method) Solution2 solution = (Solution2)dte.Solution; //Get the ProjectItem solutionFilesItem = projectItems.Single(i => i.Name == "SolutionFiles"); if (solutionFilesItem != null) { // Get the LocalPath property Property prop = solutionFilesItem.Properties.Cast <Property>().Single(i => i.Name == "LocalPath"); //Get the attribute and check if it a folder or not if (File.GetAttributes(prop.Value.ToString()).HasFlag(FileAttributes.Directory)) { //Create a new solution folder and return a Project object Project solutionFolderProject = solution.AddSolutionFolder("Solution Files"); //Cast the Project object to a SolutionFolder to be able to create more Solution Folders children SolutionFolder solutionFolder = (SolutionFolder)solutionFolderProject.Object; //Call the function to add the original files to the solution folder addFilesToSolution(solutionFolderProject, solutionFolder, prop.Value.ToString()); //Delete the original files and remove the project reference Directory.Delete(prop.Value.ToString(), true); solutionFilesItem.Remove(); } else { } } }
public static (bool success, ProjectItem projectItem) TryAddFileToSolution(this Solution2 solution, DTE2 dte, string fileName) { 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"); } return(currentProject.TryAddFileToProject(dte, fileName, "None")); }
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); }
public static void CreateStylesheet() { string file = Path.Combine(ProjectHelpers.GetSolutionFolderPath(), _stylesheet); using (StreamWriter writer = new StreamWriter(file, false, new UTF8Encoding(true))) { writer.Write("body { background: yellow; }"); } Solution2 solution = EditorExtensionsPackage.DTE.Solution as Solution2; Project project = solution.Projects .OfType <Project>() .FirstOrDefault(p => p.Name.Equals(Settings._solutionFolder, StringComparison.OrdinalIgnoreCase)); if (project == null) { project = solution.AddSolutionFolder(Settings._solutionFolder); } project.ProjectItems.AddFromFile(file); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { try { Project solutionFolder = null; DirectoryInfo folder = GetFolder(); if (folder == null) { return; } Solution2 solution = (Solution2)dte.Solution; var projects = solution.Projects; foreach (Project item in projects) { if (item.Name == folder.Name) { solutionFolder = item; break; } } if (solutionFolder == null) { solutionFolder = solution.AddSolutionFolder(folder.Name); } dte.StatusBar.Text = $"Creating Solution Folders for {folder.Name}"; IncludeFiles(folder, solutionFolder); dte.StatusBar.Text = $"Created Solution Folders for {folder.Name}"; } catch (Exception ex) { dte.StatusBar.Text = $"Error while Creating Solution Folders: {ex.Message}"; } }
public static Project GetSolutionFolder(this Solution solution, string solutionFolderName) { Solution2 solution2 = (Solution2)solution; Project project = solution2.Projects .OfType <Project>() .FirstOrDefault(p => p.Name.Equals(solutionFolderName, StringComparison.OrdinalIgnoreCase)); if (project == null) { try { project = solution2.AddSolutionFolder(solutionFolderName); } catch (Exception) { // VWD doesn't allow adding solution folder. // In that case, just silently ignore and return } } return(project); }
public static void CreateSolutionColors() { if (!SolutionColorsExist) { string assembly = Assembly.GetExecutingAssembly().Location; string folder = Path.GetDirectoryName(assembly); string path = Path.Combine(folder, "schemas\\WE-Palette.css"); File.Copy(path, GetSolutionFilePath(), true); Solution2 solution = (Solution2)EditorExtensionsPackage.DTE.Solution; Project project = solution.Projects .OfType <Project>() .FirstOrDefault(p => p.Name.Equals(Settings._solutionFolder, StringComparison.OrdinalIgnoreCase)); if (project == null) { project = solution.AddSolutionFolder(Settings._solutionFolder); } project.ProjectItems.AddFromFile(path); } }
protected override void Execute() { ISolutionOptions options = DialogService.CreateSolutionViaDialog(); if (options != null) { Directory.CreateDirectory(options.RepositoryDirectory); Directory.CreateDirectory(options.SolutionDirectory); DirectoryBuildPropsWriter.WriteDirectoryBuildProps(options); RuleSetWriter.WriteRuleSet(options); Solution.CreateSolution(options.SolutionDirectory, options.SolutionName, CreateSolutionFlags.Overwrite); Solution.SaveSolutionElement(SaveSolutionOptions.ForceSave, null, 0); Solution.OpenSolutionFile(OpenSolutionFlags.Silent, options.SolutionFilePath); Project project = Solution2.AddSolutionFolder("Build"); project.ProjectItems.AddFromFile(options.DirectoryBuildPropsPath); } }
private void MakeSolutionFolderWithItems(DTE2 dte, string linqPadFolder) { ThreadHelper.ThrowIfNotOnUIThread(); var folderName = "LINQPad"; Solution2 solution = (Solution2)dte.Solution; Project solutionFolder = null; foreach (Project item in solution.Projects) { if (item.Name == folderName) { solutionFolder = item; break; } } // create if not exist if (solutionFolder == null) { solutionFolder = solution.AddSolutionFolder("LINQPad"); IncludeFiles(linqPadFolder, solutionFolder); } }
public void ProjectFinishedGenerating(Project project) { DTE dte = project.DTE; var solItems = dte.Solution.Projects.Cast <Project>().FirstOrDefault(p => p.Name == "Solution Items" || p.Kind == EnvDTE.Constants.vsProjectItemKindSolutionItems); if (solItems == null) { Solution2 sol2 = (Solution2)dte.Solution; solItems = sol2.AddSolutionFolder("Solution Items"); string solDir = Path.GetDirectoryName(sol2.FullName); if (outputRepoFile) { RepositoryTemplate repositoryTemplate = new RepositoryTemplate { Session = templateParameters }; repositoryTemplate.Initialize(); string repositoryTemplateContent = repositoryTemplate.TransformText(); string repositoryFilePath = $"{solDir}\\repository.json"; File.WriteAllText(repositoryFilePath, repositoryTemplateContent); solItems.ProjectItems.AddFromFile(repositoryFilePath); } ConfigTemplate configTemplate = new ConfigTemplate { Session = templateParameters }; configTemplate.Initialize(); string configTemplateContent = configTemplate.TransformText(); string configFilePath = $"{solDir}\\config.json"; File.WriteAllText(configFilePath, configTemplateContent); solItems.ProjectItems.AddFromFile(configFilePath); string runtimePath = Directory.GetCurrentDirectory(); solItems.ProjectItems.AddFromFileCopy(runtimePath + "\\.gitignore"); solItems.ProjectItems.AddFromFileCopy(runtimePath + "\\pre_build.ps1"); solItems.ProjectItems.AddFromFileCopy(runtimePath + "\\post_build.ps1"); solItems.ProjectItems.AddFromFileCopy(runtimePath + "\\launch_game.ps1"); // pre-copy references Directory.CreateDirectory($"{solDir}\\references"); string referencesGitIgnorePath = $"{solDir}\\references\\.gitignore"; File.WriteAllText(referencesGitIgnorePath, "*\n!.gitignore"); string pre_build = $@"{solDir.Replace(@"\", @"\\")}\\pre_build.ps1"; string argument = $@"-ExecutionPolicy Unrestricted -File ""{pre_build}"" -SolutionDir ""{solDir.Replace(@"\", @"\\")}\\"""; if ((bool)templateParameters["UseModMenu"]) { argument += @" -ModAssemblyReferences ""blendermf.XLShredMenu\\XLShredLib.dll"""; } var process = new System.Diagnostics.Process { StartInfo = new System.Diagnostics.ProcessStartInfo { FileName = "powershell", Arguments = argument, UseShellExecute = false, RedirectStandardOutput = false, CreateNoWindow = true } }; process.Start(); process.WaitForExit(); } else { var repo = solItems.ProjectItems.Cast <ProjectItem>().FirstOrDefault(p => p.Name == "repository.json"); } (project.Object as VSProject)?.Refresh(); foreach (Configuration config in project.ConfigurationManager) { config.Properties.Item("StartAction").Value = 1; // Launch external program config.Properties.Item("StartProgram").Value = @"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe"; config.Properties.Item("StartArguments").Value = @"-ExecutionPolicy Unrestricted -File ""./launch_game.ps1"""; config.Properties.Item("StartWorkingDirectory").Value = @"../../../"; } project.Save(project.FileName); }
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 override void Execute() { if (!_AdditionalCondition) { return; } DTE vs = this.GetService <DTE>(true); if ((_SolutionFolder != "") && (_UseSolutionFolder)) { Solution2 soln = (Solution2)vs.Solution; Project p = Helpers.GetSolutionFolder(soln, _SolutionFolder); if (p == null) { p = soln.AddSolutionFolder(_SolutionFolder); } this.Root = p; } else { this.Root = vs.Solution; } string solutionPath = (string)vs.Solution.Properties.Item("Path").Value; string solutionDir = System.IO.Path.GetDirectoryName(solutionPath); //solutionpath + ProjectName //string solutionfolder = vs.Solution.FullName; //solutionfolder = solutionfolder.Substring(0,solutionfolder.LastIndexOf("\\")); DestinationFolder = solutionDir + "\\" + ProjectName; //ProjectName ItemName = ProjectName; templateItemLists = new List <TemplateItem>(); configurationService = GetService <IConfigurationService>(true); if (!System.IO.Path.IsPathRooted(this.Template) && configurationService != null) { this.Template = new FileInfo(System.IO.Path.Combine(configurationService.BasePath + @"\Templates\", this.Template)).FullName; } //Helpers.LogMessage(vs, this, "Unfolding template " + this.Template); string templateDirectory = Directory.GetParent(this.Template).FullName; FileIOPermission FIOP = new FileIOPermission(FileIOPermissionAccess.Read, templateDirectory); FIOP.Demand(); IDictionaryService dictionaryService = GetService <IDictionaryService>(); // * !!! //remove wizard not possible because dictionary with recipe arguments is //already loaded and we have conflicts :-( // vsnet loads the vstemplate file from the internal cached zip file // later update impossible //remove recipe from the vstemplate file /* * string vstemplateOriginal = this.Template; * string vstemplatBackupFileName = System.IO.Path.GetTempFileName(); * File.Copy(vstemplateOriginal, vstemplatBackupFileName, true); * RemoveWizards(vstemplateOriginal); * //this.Template = vstemplateOriginal; //set the template again */ ReadTemplate(); foreach (TemplateItem templateItem in templateItemLists) { if (templateItem.OriginalFileName.ToLower().Contains(".dll") || templateItem.OriginalFileName.ToLower().Contains(".exe")) { //donothing } else { templateItem.ParseItem(dictionaryService); } } try { base.Execute(); } finally { //copy vstemplate back //File.Copy(vstemplatBackupFileName, vstemplateOriginal, true); foreach (TemplateItem templateItem in templateItemLists) { templateItem.Restore(); } } }
public ShellProject AddSolutionFolder(string Name) { return(new ShellProject(_solution.AddSolutionFolder(Name))); }
public override void Execute() { EnvDTE.DTE dte = this.GetService <EnvDTE.DTE>(true); string evaluatedSourceFileName = EvaluateParameterAsString(dte, SourceFileName); string template = ""; if (Content != "") { template = Path.GetTempFileName(); using (StreamWriter writer = new StreamWriter(template, false)) { writer.WriteLine(Content); } } else { template = evaluatedSourceFileName; } if (template != "") { string templateBasePath = GetTemplateBasePath(); if (!Path.IsPathRooted(template)) { template = Path.Combine(templateBasePath, template); } template = new FileInfo(template).FullName; string solutionPath = (string)dte.Solution.Properties.Item("Path").Value; string solutionDir = Path.GetDirectoryName(solutionPath); string keyFilePath = Path.Combine(solutionDir, this.TargetFolder); Solution2 soln = (Solution2)dte.Solution; Project projecttargetfolder = Helpers.GetSolutionFolder(soln, TargetFolder); if (projecttargetfolder == null) { projecttargetfolder = soln.AddSolutionFolder(TargetFolder); } if (projecttargetfolder != null) { string filename = Path.Combine(solutionDir, _TargetFilename); if (File.Exists(filename)) { if (Overwrite || dte.SuppressUI) { Helpers.EnsureCheckout(dte, filename); Helpers.LogMessage(dte, dte, filename + ": File overwritten"); File.Copy(template, filename, true); } else { if (MessageBox.Show("File '" + _TargetFilename + "' already exists. Overwrite?", "Overwrite existing file?", MessageBoxButtons.YesNo) == DialogResult.Yes) { Helpers.EnsureCheckout(dte, filename); Helpers.LogMessage(dte, dte, filename + ": File overwritten"); File.Copy(template, filename, true); } } } else { Helpers.LogMessage(dte, dte, filename + ": File added"); File.Copy(template, filename); } try { //is item already in project ProjectItem existingItem = Helpers.GetProjectItemByName(projecttargetfolder.ProjectItems, _TargetFilename); if (existingItem == null) { Helpers.AddFromFile(projecttargetfolder, filename); if (dte.ActiveWindow.Document != null) { if (dte.ActiveWindow.Document.FullName == filename) { //only close window if the document has been openend otherwise there are problems in recipe migrate application dte.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); } } } } catch (Exception ex) { Helpers.LogMessage(dte, this, ex.ToString()); } } } }
public INVsSolutionFolder AddSolutionFolder(string name) { var solutionFolder = Solution.AddSolutionFolder(name); return(new NVsSolutionFolder(Solution, solutionFolder)); }
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); }
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"); }
/// Runs custom wizard logic when the wizard has completed all tasks. public void RunFinished() { var solutionDir = Path.GetDirectoryName(_solution.FullName); var project = EnvDteExtensions.GetProject(_solution, _projectName, EnvDteExtensions.CSharpType); var projectDir = Path.GetDirectoryName(project.FullName); // Add solution items var initDir = Path.Combine(projectDir, "init"); var buildDir = Directory.Exists(Path.Combine(solutionDir, ".build")) ? Path.Combine(solutionDir, ".build") : FileSystemExtensions.CreateDirectory(Path.Combine(solutionDir, ".build")); var solutionItemsFolder = EnvDteExtensions.GetSolutionFolders(_solution).FirstOrDefault(x => x.Name == "Solution Items") ?? _solution.AddSolutionFolder("Solution Items"); var nugetFolder = EnvDteExtensions.GetSolutionFolders(_solution).FirstOrDefault(x => x.Name == ".nuget") ?? _solution.AddSolutionFolder(".nuget"); if (!File.Exists(Path.Combine(solutionDir, ".gitignore"))) { File.Copy(Path.Combine(initDir, ".gitignore"), Path.Combine(solutionDir, ".gitignore")); } if (!File.Exists(Path.Combine(solutionDir, "NuGet.Config"))) { File.Copy(Path.Combine(initDir, "NuGet.Config"), Path.Combine(solutionDir, "NuGet.Config")); } if (EnvDteExtensions.GetProjectItem(nugetFolder, "NuGet.config") == null) { nugetFolder.ProjectItems.AddFromFile(Path.Combine(solutionDir, "NuGet.Config")); } if (!File.Exists(Path.Combine(solutionDir, "README.md"))) { File.Copy(Path.Combine(initDir, "README.md"), Path.Combine(solutionDir, "README.md")); } if (EnvDteExtensions.GetProjectItem(solutionItemsFolder, "README.md") == null) { solutionItemsFolder.ProjectItems.AddFromFile(Path.Combine(solutionDir, "README.md")); } if (!File.Exists(Path.Combine(buildDir, "build.ps1"))) { File.Copy(Path.Combine(initDir, ".build", "build.ps1"), Path.Combine(buildDir, "build.ps1")); } // Delete init directory EnvDteExtensions.DeleteProjectItem(project, "init"); // Install Pask.Nuget and Pester var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel)); var packageInstaller = componentModel.GetService <IVsPackageInstaller2>(); packageInstaller.InstallLatestPackage("https://api.nuget.org/v3/index.json", project, "Pask.Nuget", false, false); packageInstaller.InstallLatestPackage("https://api.nuget.org/v3/index.json", project, "Pester", false, false); // Modify project files var packageInstallerServices = componentModel.GetService <IVsPackageInstallerServices>(); var paskPackage = packageInstallerServices.GetInstalledPackages().Single(p => p.Id == "Pask"); var projectItems = project.ProjectItems.GetEnumerator(); while (projectItems.MoveNext()) { var projectItem = projectItems.Current as ProjectItem; if (projectItem == null) { continue; } if (projectItem.Name == $"{_projectName}.nuspec") { // Set Pask dependency version in the.nuspec file var fileName = projectItem.FileNames[1]; File.WriteAllText(fileName, File.ReadAllText(fileName).Replace("$paskversion$", paskPackage.VersionString)); } else if (projectItem.Name == "readme.txt") { // Delete readme.txt projectItem.Delete(); } else if (projectItem.Name == "packages.config") { // Set Pester to development dependency var fileName = projectItem.FileNames[1]; var xmlDocument = new XmlDocument(); xmlDocument.Load(fileName); var pester = xmlDocument.GetElementsByTagName("package") .Cast <XmlNode>() .SingleOrDefault(p => p.Attributes != null && p.Attributes["id"].InnerText == "Pester"); var attribute = xmlDocument.CreateAttribute("developmentDependency"); attribute.Value = "true"; pester?.Attributes?.Append(attribute); xmlDocument.Save(fileName); } } _dte.Documents.CloseAll(); }