// Methods
        public override void Execute()
        {
            DTE dte = base.GetService <DTE>();

            string solutionDirectory = Path.GetDirectoryName((string)dte.Solution.Properties.Item("Path").Value);
            string targetPath        = Path.Combine(solutionDirectory, this.RelativePath);
            string targetDir         = Path.GetDirectoryName(targetPath);

            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }
            using (StreamWriter writer = new StreamWriter(targetPath, false, new UTF8Encoding(true, true)))
            {
                writer.WriteLine(this.content);
            }

            SolutionFolder sf = DteHelper.FindSolutionFolderByPath(dte.Solution, Path.GetDirectoryName(this.RelativePath));

            if (null != sf)
            {
                sf.Parent.ProjectItems.AddFromFile(targetPath);
            }
            else
            {
                DteHelper.SelectSolution(dte);
                ProjectItem pi = dte.ItemOperations.AddExistingItem(targetPath);
            }
            dte.ActiveWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
        }
示例#2
0
 /// <summary>
 /// Converts <paramref name="value"/> to type <paramref name="destinationType"/>
 /// </summary>
 /// <param name="context"></param>
 /// <param name="culture"></param>
 /// <param name="value">A <see cref="string"/> object</param>
 /// <param name="destinationType"></param>
 /// <returns>The SolutionFolder of a <see cref="string"/></returns>
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
 {
     if (value is string)
     {
         EnvDTE.DTE vs = (EnvDTE.DTE)context.GetService(typeof(EnvDTE.DTE));
         return(DteHelper.FindSolutionFolderByPath(vs.Solution, (string)value));
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
示例#3
0
        /// <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);
            }
        }