// Methods private void AddItemTemplate(Project rootproject) { DTE service = (DTE)this.GetService(typeof(DTE)); string str2 = DteHelper.BuildPath(rootproject); if (!string.IsNullOrEmpty(this.Path)) { str2 = System.IO.Path.Combine(str2, this.Path); } ProjectItem item = DteHelper.FindItemByPath(service.Solution, str2); if (item != null) { this.NewItem = item.ProjectItems.AddFromTemplate(this.Template, this.ItemName); } else { Project project = DteHelper.FindProjectByPath(service.Solution, str2); if (project == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "InsertionPointException", new object[] { str2 })); } project.ProjectItems.AddFromTemplate(this.Template, this.ItemName); } }
private void AddItemTemplate(Project rootproject) { DTE dte = (DTE)GetService(typeof(DTE)); string projectPath = DteHelper.BuildPath(rootproject); string folderPath = projectPath; if (!string.IsNullOrEmpty(this.Path)) { folderPath += "\\" + this.Path; } ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, folderPath); if (prItem != null) { this.NewItem = prItem.ProjectItems.AddFromTemplate(this.Template, this.ItemName); } else { Project project = DteHelper.FindProjectByPath(dte.Solution, folderPath); if (project != null) { this.NewItem = project.ProjectItems.AddFromTemplate(this.Template, this.ItemName); } else { throw new InvalidOperationException( String.Format("Cannot find insertion point {0}", folderPath)); } } }
private void AddItemTemplate(Project rootproject) { DTE dte = (DTE)GetService(typeof(DTE)); string projectPath = DteHelper.BuildPath(rootproject); string folderPath = projectPath; if (!string.IsNullOrEmpty(this.Path)) { folderPath = System.IO.Path.Combine(folderPath, this.Path); } ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, folderPath); if (prItem != null) { this.NewItem = prItem.ProjectItems.AddFromTemplate(this.Template, this.ItemName); } else { Project project = DteHelper.FindProjectByPath(dte.Solution, folderPath); if (project != null) { project.ProjectItems.AddFromTemplate(this.Template, this.ItemName); } else { throw new InvalidOperationException( String.Format(CultureInfo.CurrentUICulture, Resources.InsertionPointException, folderPath)); } } }
private void AddProjectTemplate(Project project) { DTE dte = (DTE)GetService(typeof(DTE)); SolutionFolder slnFolder = null; if (project == null) { if (string.IsNullOrEmpty(this.Path)) { this.NewItem = dte.Solution.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName, false); } else { Project subProject = DteHelper.FindProjectByPath(dte.Solution, this.Path); slnFolder = (SolutionFolder)subProject.Object; this.NewItem = slnFolder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName); } } else { slnFolder = (SolutionFolder)project.Object; this.NewItem = slnFolder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName); } if (this.newItem == null) { //Return the project already added if the AddFromTemplate method returns null ProjectItems childItems; if (slnFolder != null) { childItems = slnFolder.Parent.ProjectItems; } else { childItems = dte.Solution.Projects as ProjectItems; } if (childItems != null) { foreach (ProjectItem item in childItems) { if (item.Name.Contains(this.ItemName)) { this.NewItem = item.Object as Project; break; } } } else { this.NewItem = DteHelperEx.FindProjectByName(dte, this.ItemName, false); } } }
public object LocateTarget(IServiceProvider serviceProvider, string serializedData) { DTE vs = (DTE)serviceProvider.GetService(typeof(DTE)); Project project = DteHelper.FindProjectByPath(vs.Solution, serializedData); if (project != null) { return(project.Object as EnvDTE80.SolutionFolder); } return(null); }
/// <summary> /// Gets the value. /// </summary> /// <returns></returns> private object GetValue() { DTE dte = (DTE)GetService(typeof(DTE)); object newValue; ExpressionEvaluationService evaluator = new ExpressionEvaluationService(); IDictionaryService dictservice = (IDictionaryService)GetService(typeof(IDictionaryService)); string path = evaluator.Evaluate( this.pathExpression, new ServiceAdapterDictionary(dictservice)).ToString(); newValue = DteHelper.FindProjectByPath(dte.Solution, path); return(newValue); }
/// <summary> /// Uses <see cref="DteHelper.FindProjectByPath"/> to search for the project specified by the "Path" attributte /// </summary> /// <param name="currentValue"></param> /// <param name="newValue"></param> /// <returns></returns> /// <seealso cref="ValueProvider.OnBeginRecipe"/> /// <seealso cref="DteHelper.FindProjectByPath"/> public override bool OnBeginRecipe(object currentValue, out object newValue) { DTE dte = (DTE)GetService(typeof(DTE)); if (currentValue == null) { newValue = DteHelper.FindProjectByPath(dte.Solution, this.path); if (newValue != null) { return(true); } } newValue = currentValue; return(false); }
/// <summary> /// Renames the project with the provided name /// </summary> public override void Execute() { DTE dte = GetService <DTE>(true); this.project = DteHelper.FindProjectByPath(dte.Solution, projectPath); if (this.project == null) { throw new ArgumentException(String.Format( System.Globalization.CultureInfo.CurrentCulture, Properties.Resources.RenameProjectAction_CantFindProject, projectPath)); } else { this.oldName = this.project.Name; this.oldAssembly = this.project.Properties.Item("AssemblyName").Value.ToString(); this.project.Name = newProjectName; this.project.Properties.Item("AssemblyName").Value = newProjectName; } }
private VsBoundReference GetReferenceTarget(string target, string recipeName) { VsBoundReference vsTarget = null; DTE dte = GetService <DTE>(true); target = DteHelper.ReplaceParameters(target, this.ReplacementDictionary); // Special case for "/" value. if (target.Equals("/") || target.Equals("\\")) { // "/" is the solution if we're in a solution template, the // project it this is a project template or the item if it's an item template. if (this.Project != null) { vsTarget = new ProjectReference(recipeName, this.Project); } else if (this.Item != null) { vsTarget = new ProjectItemReference(recipeName, this.Item); } else { vsTarget = new SolutionReference(recipeName, dte.Solution); } } else if (template.VSKind == WizardRunKind.AsMultiProject) { string pathToTarget = target.Substring(1); if (root != null && root.Object is SolutionFolder) { pathToTarget = DteHelper.BuildPath(root) + target; } ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, pathToTarget); if (prItem != null) { vsTarget = new ProjectItemReference(recipeName, prItem); } else { // Try finding a project. Project prj = DteHelper.FindProjectByPath(dte.Solution, pathToTarget); if (prj != null) { vsTarget = new ProjectReference(recipeName, prj); } } } else if (template.VSKind == WizardRunKind.AsNewProject && this.Project != null) { ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, DteHelper.BuildPath(this.Project) + target); // Can only refer to items. if (prItem != null) { vsTarget = new ProjectItemReference(recipeName, prItem); } } else { // We got here because there's an Item template that contains an assetname other than "\". throw new ArgumentException(String.Format( CultureInfo.CurrentCulture, Properties.Resources.Templates_ItemTargetInvalid, Path.GetFileName(template.FileName), target), "Target"); } return(vsTarget); }
/// <summary> /// Converts from a given solution relative path to a corresponding EnvDTE.ProjecItem /// in case it exists in the current solution /// </summary> /// <param name="context"></param> /// <param name="culture"></param> /// <param name="value"></param> /// <param name="throwErrors"></param> /// <returns></returns> protected virtual internal object ConvertFromInternal(ITypeDescriptorContext context, CultureInfo culture, object value, bool throwErrors) { if (value is string) { // The helper requests the service and ensures that it exists. DTE vs = (DTE)ServiceHelper.GetService(context, typeof(DTE), this); if (vs.Solution == null) { if (throwErrors) { throw new InvalidOperationException(Properties.Resources.DteElementConverter_NoSolutionOpened); } else { return(null); } } string path = (string)value; // First determine solution reference. if (path.Length == 0) { return(null); } if (path.Length == 1) { if (path == "\\" || path == "/") { return(vs.Solution); } else { if (throwErrors) { throw new FormatException(Properties.Resources.DteElementConverter_MustStartWithSlash); } else { return(null); } } } else { // Remove slash and try to locate project. if (path.StartsWith("/") || path.StartsWith("\\")) { path = path.Substring(1); } Project project = DteHelper.FindProjectByPath(vs.Solution, path); if (project != null) { return(project); } else { // Try with item. Must find something to be valid. ProjectItem item = DteHelper.FindItemByPath(vs.Solution, path); if (item != null) { return(item); } else { if (throwErrors) { throw new FormatException(Properties.Resources.DteElementConverter_CantFindElement); } else { return(null); } } } } } else { try { return(base.ConvertFrom(context, culture, value)); } catch { if (throwErrors) { throw; } else { return(null); } } } }
public object LocateTarget(IServiceProvider serviceProvider, string serializedData) { DTE vs = (DTE)serviceProvider.GetService(typeof(DTE)); return(DteHelper.FindProjectByPath(vs.Solution, serializedData)); }
private void AddProjectTemplate(Project project) { try { IRecipeManagerService provider = (IRecipeManagerService)this.GetService(typeof(IRecipeManagerService)); GuidancePackage p = provider.GetPackage("SharePointSoftwareFactory.Base"); GuidancePackage p2 = provider.EnablePackage("SharePointSoftwareFactory.Base"); } catch (Exception) { } DTE service = (DTE)this.GetService(typeof(DTE)); SolutionFolder folder = null; if (project == null) { if (string.IsNullOrEmpty(this.Path)) { //char[] invalidedChars = System.IO.Path.GetInvalidPathChars(); //foreach (char c in invalidedChars) //{ // if (this.Template.IndexOf(c) > 0) // { // } // if (this.DestinationFolder.IndexOf(c) > 0) // { // } //} this.NewItem = service.Solution.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName, false); } else { folder = (SolutionFolder)DteHelper.FindProjectByPath(service.Solution, this.Path).Object; this.NewItem = folder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName); } } else { //sometimes in the solutionfolder a project already exists but is not part of the project //so we delete the folder if it already exists if (Directory.Exists(this.DestinationFolder)) { if (MessageBox.Show("Directory '" + this.DestinationFolder + "' already exists in the solution. Delete directory? If you choose 'No' the directory will be renamed to '" + this.DestinationFolder + "_Backup'", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) { Directory.Delete(this.DestinationFolder, true); } else { string backupDirectoryName = this.DestinationFolder + "_Backup"; int count = 1; while (Directory.Exists(backupDirectoryName)) { backupDirectoryName = this.DestinationFolder + "_Backup" + count.ToString(); count++; } Directory.Move(this.DestinationFolder, backupDirectoryName); } } folder = (SolutionFolder)project.Object; this.NewItem = folder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName); } if (this.newItem == null) { ProjectItems projectItems; if (folder != null) { projectItems = folder.Parent.ProjectItems; } else { projectItems = service.Solution.Projects as ProjectItems; } if (projectItems != null) { foreach (ProjectItem item in projectItems) { if (item.Name.Contains(this.ItemName)) { this.NewItem = item.Object as Project; break; } } } else { this.NewItem = FindProjectByName(service, this.ItemName, false); } } }
/// <summary> /// Delete an item from a project /// </summary> public override void Execute() { DTE dte = GetService <DTE>(); this.project = DteHelper.FindProjectByPath(dte.Solution, this.projectName); }