예제 #1
0
 /// <summary>
 /// 通过文件后缀来删除项目项
 /// </summary>
 /// <param name="projectItem"></param>
 /// <param name="fileExtention"></param>
 /// <param name="isAllSub"></param>
 private static void DeleteFromExtention(ProjectItem projectItem, string fileExtention, bool isAllSub)
 {
     if (null == projectItem)
     {
         return;
     }
     if (!isAllSub)
     {
         if (Path.GetExtension(projectItem.Name) == fileExtention)
         {
             projectItem.Delete();
         }
     }
     else
     {
         if (Path.GetExtension(projectItem.Name) == fileExtention)
         {
             projectItem.Delete();
         }
         else
         {
             if (projectItem.ProjectItems.Count > 0)
             {
                 foreach (ProjectItem item in projectItem.ProjectItems)
                 {
                     DeleteFromExtention(item, fileExtention, true);
                 }
             }
         }
     }
 }
예제 #2
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;
     }
 }
예제 #3
0
 /// <summary>
 /// 根据文件和项目Copy创建项(无项目项文件夹)
 /// </summary>
 /// <param name="project">项目</param>
 /// <param name="filePath">文件路径</param>
 /// <returns>创建完成的项目项</returns>
 public static ProjectItem AddFromFileCopy(this Project project, string filePath)
 {
     if (!File.Exists(filePath))
     {
         return(null);
     }
     try
     {
         string      itemName    = Path.GetFileName(filePath);
         ProjectItem projectItem = project.ProjectItems.FindItem(itemName);
         //项存在删除
         if (null != projectItem)
         {
             projectItem.Delete();
         }
         projectItem = project.ProjectItems.AddFromFileCopy(filePath);
         if (null == projectItem)
         {
             projectItem = project.ProjectItems.FindItem(itemName);
         }
         return(projectItem);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        protected override void ExecuteCore()
        {
            var items = DTE.SelectedItems.OfType <SelectedItem>().ToArray();

            if (items.Length == 1)
            {
                ProjectItem childProjectItem = items[0].ProjectItem;
                if (childProjectItem.ProjectItems.Count > 0)
                {
                    MessageBox.Show("该项下面还有子项,请先移除所有子项。", "提示");
                    return;
                }
                var res = MessageBox.Show("是否需要把移除父子依赖成为独立的文件?\r\n", "提示", MessageBoxButton.OKCancel);
                if (res == MessageBoxResult.OK)
                {
                    var fileName = childProjectItem.get_FileNames(0);
                    var tmp      = Path.GetTempFileName();
                    File.Copy(fileName, tmp, true);
                    var p = childProjectItem.ContainingProject;
                    childProjectItem.Delete();
                    if (!File.Exists(fileName))
                    {
                        File.Copy(tmp, fileName, true);
                    }
                    p.ProjectItems.AddFromFile(fileName);
                }
            }
        }
예제 #5
0
 /// <summary>
 /// See <see cref="M:Microsoft.Practices.RecipeFramework.IAction.Undo"/>.
 /// </summary>
 public override void Undo()
 {
     if (outputProjectItem != null)
     {
         outputProjectItem.Delete();
     }
 }
예제 #6
0
        /// <summary>
        /// Saves and configures the additional output created by the transformation.
        /// </summary>
        /// <remarks>
        /// Note that this method currently cannot distinguish between files that are
        /// already in a Database project and files that are simply displayed with
        /// "Show All Files" option. Database project model makes these items appear
        /// as if they were included in the project.
        /// </remarks>
        private void ConfigureOutputFile(OutputFile output)
        {
            string outputFilePath = this.GetFullPath(output.Path);

            ProjectItem  outputItem = this.dte.Solution.FindProjectItem(outputFilePath);
            ProjectItems collection = this.FindProjectItemCollection(output);

            if (outputItem == null)
            {
                // If output file has not been added to the solution
                outputItem = collection.AddFromFile(outputFilePath);
            }
            else if (!Same(outputItem.Collection, collection))
            {
                // If the output file moved from one collection to another
                string backupFile = outputFilePath + ".bak";
                File.Move(outputFilePath, backupFile); // Prevent unnecessary source control operations
                outputItem.Delete();                   // Remove doesn't work on "DependentUpon" items
                File.Move(backupFile, outputFilePath);

                outputItem = collection.AddFromFile(outputFilePath);
            }

            ConfigureProjectItem(outputItem, output);
        }
예제 #7
0
        /// <summary>
        /// 从项目中删除文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="project"></param>
        private static void RemoveFromProject(string fileName, ClassDesignerInfo info)
        {
            Project  project = info.CurrentProject;
            FileInfo finfo   = new FileInfo(project.FileName);

            fileName = fileName.Replace(finfo.DirectoryName, "");
            string[]     strPart     = fileName.Split(new char[] { '\\' });
            ProjectItems curProjects = project.ProjectItems;
            ProjectItem  curItem     = null;

            foreach (string part in strPart)
            {
                if (string.IsNullOrEmpty(part))
                {
                    continue;
                }
                curItem = FindItem(curProjects, part);
                if (curItem == null)
                {
                    return;
                }
                curProjects = curItem.ProjectItems;
            }
            curItem.Delete();
        }
예제 #8
0
        private static void RemoveClass1File(Project newlyCreatedProject)
        {
            ProjectItem projectItem = null;

            if (ContainsItem(Class1ItemCreatedByTemplate, newlyCreatedProject.ProjectItems))
            {
                projectItem = newlyCreatedProject.ProjectItems.Item(Class1ItemCreatedByTemplate);
            }
            if (projectItem != null)
            {
                var fileName = projectItem.get_FileNames(0);
                if (File.Exists(fileName))
                {
                    try
                    {
                        Logger.InfoFormat("CreateProjectHelper.RemoveClass1File removing file={0}", fileName);
                        File.Delete(fileName);
                    }
                    catch (Exception e)
                    {
                        ExceptionLogHelper.LogException(e);
                    }
                }
                projectItem.Delete();
            }
        }
        /// <summary>
        /// Saves content accumulated by this transformation to the output files.
        /// </summary>
        /// <param name="outputFiles">
        /// <see cref="OutputFile"/>s that need to be added to the <paramref name="solution"/>.
        /// </param>
        /// <param name="solution">
        /// Current Visual Studio <see cref="Solution"/>.
        /// </param>
        /// <param name="projects">
        /// All <see cref="Project"/>s in the current <paramref name="solution"/>.
        /// </param>
        /// <param name="template">
        /// A <see cref="ProjectItem"/> that represents T4 template being transformed.
        /// </param>
        /// <remarks>
        /// Note that this method currently cannot distinguish between files that are
        /// already in a Database project and files that are simply displayed with
        /// "Show All Files" option. Database project model makes these items appear
        /// as if they were included in the project.
        /// </remarks>
        private static void UpdateOutputFiles(IEnumerable <OutputFile> outputFiles, Solution solution, IEnumerable <Project> projects, ProjectItem template)
        {
            foreach (OutputFile output in outputFiles)
            {
                UpdateOutputFile(output); // Save the output file before we can add it to the solution

                ProjectItem  outputItem = solution.FindProjectItem(output.File);
                ProjectItems collection = FindProjectItemCollection(output, projects, template);

                if (outputItem == null)
                {
                    // If output file has not been added to the solution
                    outputItem = collection.AddFromFile(output.File);
                }
                else if (!Same(outputItem.Collection, collection))
                {
                    // If the output file moved from one collection to another
                    string backupFile = output.File + ".bak";
                    File.Move(output.File, backupFile); // Prevent unnecessary source control operations
                    outputItem.Delete();                // Remove doesn't work on "DependentUpon" items
                    File.Move(backupFile, output.File);

                    outputItem = collection.AddFromFile(output.File);
                }

                SetProjectItemProperties(outputItem, output);
                SetProjectItemBuildProperties(outputItem, output);
                AddProjectItemReferences(outputItem, output);
            }
        }
예제 #10
0
        private void GenerateDgml(string processResult, Project project)
        {
            var         dgmlBuilder = new DgmlBuilder.DgmlBuilder();
            var         result      = BuildModelResult(processResult);
            ProjectItem item        = null;

            foreach (var info in result)
            {
                var dgmlText = dgmlBuilder.Build(info.Item2, info.Item1, GetTemplate());

                var path = Path.GetTempPath() + info.Item1 + ".dgml";
                File.WriteAllText(path, dgmlText, Encoding.UTF8);
                item = project.ProjectItems.GetItem(Path.GetFileName(path));
                if (item != null)
                {
                    item.Delete();
                }
                item = project.ProjectItems.AddFromFileCopy(path);
            }

            if (item != null)
            {
                var window = item.Open();
                window.Document.Activate();
            }
        }
        private void GenerateDgml(List <Tuple <string, string> > modelResult, Project project)
        {
            var         dgmlBuilder = new DgmlBuilder.DgmlBuilder();
            ProjectItem item        = null;

            foreach (var info in modelResult)
            {
                var dgmlText = dgmlBuilder.Build(info.Item2, info.Item1, GetTemplate());

                if (info.Item1.IndexOfAny(Path.GetInvalidPathChars()) >= 0 ||
                    info.Item1.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
                {
                    EnvDteHelper.ShowError("Invalid name: " + info.Item1);
                    return;
                }

                var path = Path.Combine(Path.GetTempPath(), info.Item1 + ".dgml");

                File.WriteAllText(path, dgmlText, Encoding.UTF8);
                item = project.ProjectItems.GetItem(Path.GetFileName(path));
                if (item != null)
                {
                    item.Delete();
                }
                item = project.ProjectItems.AddFromFileCopy(path);
            }

            if (item != null)
            {
                var window = item.Open();
                window.Document.Activate();
            }
        }
예제 #12
0
        private async Task <ProjectItem> SimulateCustomTool()
        {
            string      outputFileName = Path.Combine(Path.GetDirectoryName(this.project.FullName), this.input.GetItemAttribute(ItemMetadata.LastGenOutput));
            ProjectItem outputItem     = this.input.ProjectItems.Cast <ProjectItem>().SingleOrDefault(item => item.FileNames[1] == outputFileName);

            if (outputItem != null)
            {
                if (Path.GetExtension(outputFileName) == this.templatingCallback.Extension)
                {
                    // Required output file exists. Touch it and return.
                    File.SetLastWriteTime(outputFileName, DateTime.UtcNow);
                    await Dispatcher.Yield();

                    return(outputItem);
                }

                // Output file has a wrong name, delete it.
                outputItem.Delete();
            }

            // Create the new output file
            outputFileName = Path.ChangeExtension(this.input.FileNames[1], this.templatingCallback.Extension);
            this.input.SetItemAttribute(ItemMetadata.LastGenOutput, FileMethods.GetRelativePath(this.project.FullName, outputFileName).TrimStart('.', '\\'));
            outputItem = IntegrationTest.CreateTestProjectItemFromFile(this.input.ProjectItems, outputFileName);
            await Dispatcher.Yield();

            return(outputItem);
        }
예제 #13
0
        /// <summary>
        /// Adds a new text file to the project based on a given text
        /// </summary>
        /// <param name="targetFileName"></param>
        /// <param name="text"></param>
        public static void AddTextToProjectAsFile(string targetFileName, string text)
        {
            string       tempFilePath = Path.Combine(Path.GetTempPath(), targetFileName);
            StreamWriter sr           = new StreamWriter(tempFilePath);

            sr.Write(text);
            sr.Close();
            ProjectItem projectItemToBeDeleted = null;

            foreach (ProjectItem projectItem in Project.ProjectItems)
            {
                if (projectItem.Name == targetFileName)
                {
                    projectItemToBeDeleted = projectItem;
                }
            }

            if (projectItemToBeDeleted != null)
            {
                // if the file is already in the project, delete it
                projectItemToBeDeleted.Delete();
            }
            else
            {
                // if the file is not added to the project but exists anyway, delete it.
                string fileName = Path.Combine(Path.GetDirectoryName(Project.FullName), targetFileName);
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
            }
            Project.ProjectItems.AddFromFileCopy(tempFilePath);
        }
 public override void Undo()
 {
     if (_createdItem != null)
     {
         _createdItem.Delete();
     }
 }
예제 #15
0
 /// <summary>
 /// 通过字符串来添加项目项
 /// </summary>
 /// <param name="project">项目宿体</param>
 /// <param name="fileString">字符串</param>
 /// <param name="dirName">文件夹名称</param>
 /// <param name="itemName">文件名称</param>
 /// <returns></returns>
 public static ProjectItem AddFromFileString(this Project project, string fileString, string dirName, string itemName)
 {
     try
     {
         //创建项文件
         string dirPath = Path.Combine(project.ToDirectory(), dirName);
         //文件夹不存在创建项目文件夹
         if (!Directory.Exists(dirPath))
         {
             Directory.CreateDirectory(dirPath);
         }
         string filePath = Path.Combine(dirPath, itemName);
         using (FileStream create = new FileStream(filePath, FileMode.OpenOrCreate))
         {
             byte[] buffer = Encoding.Default.GetBytes(fileString);
             create.Write(buffer, 0, buffer.Length);
         }
         //添加项文件到项目中
         ProjectItem projectItem = project.ProjectItems.Find(itemName);
         if (null != projectItem)
         {
             projectItem.Delete();
         }
         projectItem = project.ProjectItems.AddFromFile(filePath);
         if (null == projectItem)
         {
             projectItem = project.ProjectItems.Find(itemName);
         }
         return(projectItem);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #16
0
 /// <summary>
 /// Safes the delete project item.
 /// </summary>
 /// <param name="projectItem">The project item.</param>
 public static void SafeDeleteProjectItem(ProjectItem projectItem)
 {
     if (projectItem != null)
     {
         projectItem.Delete();
     }
 }
예제 #17
0
        //https://stackoverflow.com/questions/36143663/create-a-visual-studio-project-template-that-pulls-nuget-references-from-online
        public static void InstallPackages(Project project)
        {
            ProjectItem config = project.ProjectItems.Item("packages.init");
            DTE         dte    = project.DTE;

            if (config == null && config.FileCount == 0)
            {
                return;
            }
            var path = config.FileNames[0];

            WriteToOutput(dte, "Installing packages for " + project.Name);

            var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
            IVsPackageInstallerServices installerServices =
                componentModel.GetService <IVsPackageInstallerServices>();
            var file = new PackageReferenceFile(path);

            foreach (PackageReference pRef in file.GetPackageReferences())
            {
                if (!installerServices.IsPackageInstalled(project, pRef.Id))
                {
                    WriteToOutput(dte, String.Format("Installing {0}, version {1}", pRef.Id, pRef.Version.Version.ToString()));

                    var installer = componentModel.GetService <IVsPackageInstaller>();
                    installer.InstallPackage(
                        "All",
                        project,
                        pRef.Id,
                        pRef.Version.Version,
                        false);
                }
            }
            config.Delete();
        }
예제 #18
0
        /// <summary>
        /// Called when [execute].
        /// </summary>
        public override void Execute()
        {
            string tempfile = Path.GetTempFileName();

            try
            {
                //string foldert = System.IO.Path.GetDirectoryName(Project.FullName);
                string fileFullName = string.Empty;
                //DirectoryInfo dInfo = new DirectoryInfo(foldert);
                ProjectItem folderItem = VSIPHelper.FindItemByName(Project.ProjectItems, Subfolder, true);
                if (folderItem == null)
                {
                    try
                    {
                        project.ProjectItems.AddFolder(Subfolder);
                        folderItem = VSIPHelper.FindItemByName(Project.ProjectItems, Subfolder, true);
                    }
                    catch
                    { }
                }

                using (StreamWriter sw = new StreamWriter(tempfile, false, new UTF8Encoding(true, true)))
                {
                    sw.WriteLine(content);
                }

                // Check it the targetFileName already exists and delete it so it can be added.
                ProjectItem targetItem = VSIPHelper.FindItemByName(Project.ProjectItems, targetFileName, true);
                if (targetItem != null)
                {
                    targetItem.Delete();
                }

                if (!String.IsNullOrEmpty(itemName))
                {
                    ProjectItem item = VSIPHelper.FindItemByName(Project.ProjectItems, itemName, true);

                    if (item != null)
                    {
                        projectItem = item.ProjectItems.AddFromTemplate(tempfile, targetFileName);
                    }
                }
                else
                {
                    //projectItem = project.ProjectItems.AddFromTemplate(tempfile, targetFileName);
                    projectItem = folderItem.ProjectItems.AddFromTemplate(tempfile, targetFileName);
                }

                if (open && projectItem != null)
                {
                    Window wnd = projectItem.Open(EnvDTE.Constants.vsViewKindPrimary);
                    wnd.Visible = true;
                    wnd.Activate();
                }
            }
            finally
            {
                File.Delete(tempfile);
            }
        }
예제 #19
0
        public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
        {
            UIThreadHelper.VerifyOnUIThread();
            var dte      = _serviceProvider.GetService <DTE2, DTE>();
            var solution = _serviceProvider.GetService <IVsSolution, SVsSolution>();

            try
            {
                Verify.HResult(solution.GetSolutionInfo(out string directory, out string solutionFile, out string optsFile));
                var         globalJsonPath = Path.Combine(directory, "global.json");
                ProjectItem globalJson     = dte.Solution.FindProjectItem(globalJsonPath);
                globalJson?.Delete();
                try
                {
                    _fileSystem.RemoveFile(globalJsonPath);
                }
                catch (FileNotFoundException) { }
                return(VSConstants.S_OK);
            }
            finally
            {
                Verify.HResult(solution.UnadviseSolutionEvents(SolutionCookie));
                // Don't keep a static reference around to an object that won't be used again.
                Assumes.True(ReferenceEquals(this, s_remover));
                s_remover = null;
            }
        }
예제 #20
0
 /// <summary>
 /// Undoes the creation of the item, then deletes the item
 /// </summary>
 public override void Undo()
 {
     if (projectItem != null)
     {
         projectItem.Delete();
     }
 }
예제 #21
0
        public void DeleteFiles(params string[] relativeFilePaths)
        {
            foreach (string relativeFilePath in relativeFilePaths)
            {
                string absoluteFile = new FileInfo(Path.Combine(WorkingDirectory, relativeFilePath)).FullName;

                try
                {
                    ProjectItem item    = VsHelpers.DTE.Solution.FindProjectItem(absoluteFile);
                    Project     project = item?.ContainingProject;

                    if (project != null)
                    {
                        item.Delete();
                    }
                    else
                    {
                        VsHelpers.CheckFileOutOfSourceControl(absoluteFile);
                        File.Delete(absoluteFile);
                    }

                    Logger.Log(string.Format(LibraryInstaller.Resources.Text.FileDeleted, relativeFilePath), LogLevel.Operation);
                }
                catch (Exception)
                {
                    Logger.Log(string.Format(LibraryInstaller.Resources.Text.FileDeleteFail, relativeFilePath), LogLevel.Operation);
                }
            }
        }
 /// <summary>
 /// Undoes the creation of the item, then deletes the item
 /// </summary>
 public override void Undo()
 {
     if (addedItem != null)
     {
         addedItem.Delete();
     }
 }
예제 #23
0
        protected override void ExecuteCore()
        {
            var array = base.DTE.SelectedItems.OfType <SelectedItem>().ToArray();

            if (array.Length == 1)
            {
                ProjectItem projectItem = array[0].ProjectItem;
                if (projectItem.ProjectItems.Count > 0)
                {
                    MessageBox.Show("该项下面还有子项,请先移除所有子项。", "提示");
                }
                else
                {
                    var res = MessageBox.Show("是否需要把移除父子依赖成为独立的文件?\r\n", "移除父子依赖", MessageBoxButton.OKCancel);
                    if (res == MessageBoxResult.OK)
                    {
                        string text         = projectItem.get_FileNames(0);
                        string tempFileName = Path.GetTempFileName();
                        File.Copy(text, tempFileName, true);
                        Project containingProject = projectItem.ContainingProject;
                        projectItem.Delete();
                        if (!File.Exists(text))
                        {
                            File.Copy(tempFileName, text, true);
                        }
                        containingProject.ProjectItems.AddFromFile(text);
                    }
                }
            }
        }
        private async System.Threading.Tasks.Task CreateDtoFile(string inputCamel, string folder,
                                                                object selectedItem,
                                                                ProjectItem dtoProject,
                                                                Project project,
                                                                TemplateType templateType)
        {
            var file = CreateFileInfo(inputCamel, folder, templateType);

            PackageUtilities.EnsureOutputPath(folder);

            if (!file.Exists)
            {
                int position = await WriteFileAsync(project, file.FullName, inputCamel, templateType);

                try
                {
                    ProjectItem projectItem = null;
                    if (selectedItem is ProjectItem projItem)
                    {
                        if ("{6BB5F8F0-4483-11D3-8BCF-00C04F8EC28C}" == projItem.Kind) // Constants.vsProjectItemKindVirtualFolder
                        {
                            projectItem = projItem.ProjectItems.AddFromFile(file.FullName);
                        }
                    }

                    if (projectItem == null)
                    {
                        projectItem = dtoProject.ProjectItems.AddFromFile(file.FullName);
                    }

                    if (file.FullName.EndsWith("__dummy__"))
                    {
                        projectItem?.Delete();
                        return;
                    }

                    VsShellUtilities.OpenDocument(this, file.FullName);

                    // Move cursor into position
                    if (position > 0)
                    {
                        Microsoft.VisualStudio.Text.Editor.IWpfTextView view = ProjectHelpers.GetCurentTextView();

                        view?.Caret.MoveTo(new SnapshotPoint(view.TextBuffer.CurrentSnapshot, position));
                    }

                    _dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");
                    _dte.ActiveDocument.Activate();
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("The file '" + file + "' already exist.");
            }
        }
예제 #25
0
        public WinFormBaseGengerator(Project pjt1, string ctlname, List <SQLTableInfo> stltmp)
        {
            pjt = pjt1;
            stl = stltmp;
            Common.ShowInfo("正在准备控件" + ctlname);
            Solution2 slu     = (Solution2)Common.chDTE.Solution;
            string    itmname = ctlname + Kit.GetProjectLaneExt(Kit.GetProjectLangType(pjt));

            if (itmname == null)
            {
                throw new Exception("错误002 不支持此项目类型");
            }
            string pit = "";

            if (Kit.GetProjectLangType(pjt) == KeelKit.Core.cfLangType.CPP)
            {
            }
            else
            {
                pit = slu.GetProjectItemTemplate("UserControl.zip", Kit.GetProjectLangStr(Kit.GetProjectLangType(pjt)));
            }
            //string aaa = slu.get_TemplatePath(Kit.GetProjectLangStr(Kit.GetProjectLangType(pjt)));
            if (pit == null)
            {
                throw new Exception("错误003 未能得到对应项目模板,请确认此语言项目是否正确安装!");
            }
            pi = Kit.GetProjectItemByName(pjt, itmname);
            if (pi != null)
            {
                pi.Delete();
            }
            try
            {
                DeleteFile(itmname);
                pi = pjt.ProjectItems.AddFromTemplate(pit, itmname);
            }
            catch (Exception)
            {
                pi = null;
            }

            if (pi == null)
            {
                pi = Kit.GetProjectItemByName(pjt, itmname);
            }
            if (pi == null)
            {
                return;
            }
            Window itemDesigner = pi.Open(Constants.vsViewKindDesigner);

            this.SaveForm();
            itemDesigner.Activate();
            host = itemDesigner.Object as IDesignerHost;
            if (host != null)
            {
                ic = host.Container;
            }
        }
예제 #26
0
 private static void DeleteAndAdd(ProjectItem item, string path)
 {
     string temp = Path.GetTempFileName();
     File.Copy(path, temp, true);
     item.Delete();
     File.Copy(temp, path);
     File.Delete(temp);
 }
예제 #27
0
        private void DeleteItem(ProjectItem projectItem, DTE vs)
        {
            string itemPath = DteHelper.BuildPath(projectItem);

            itemPath = DteHelper.GetPathFull(vs, itemPath);

            projectItem.Remove();
            projectItem.Delete();
        }
        /// <summary>
        /// Depois que tudo estiver pronto. Apaga a pasta temp criada pelo visual studio e deixa somente as pastas criadas personalizadamente.
        /// Insere toda injeção de depêndencia. Faz o Mapeamento. Configura o DbSet.
        /// </summary>
        public void RunFinished()
        {
            _pastaTemp?.Remove();
            _pastaTemp?.Delete();

            IoCConfig();
            AutoMapperConfig();
            ContextConfig();
            //CreateEntity();
        }
예제 #29
0
 /// <summary>
 /// Deletes the created items
 /// </summary>
 public override void Undo()
 {
     foreach (ProjectItem projectItem in projectItems)
     {
         if (projectItem != null)
         {
             projectItem.Delete();
         }
     }
 }
        /// <summary>
        /// Delete an item from a project
        /// </summary>
        public override void Execute()
        {
            DTE dte1 = (DTE)base.GetService(typeof(DTE));

            // The search will be recursive to explore every sub filder inside the specified project.
            ProjectItem item = DteHelperEx.FindItemByName(this.Project.ProjectItems, this.itemName, true);

            if (item != null)
            {
                item.Delete();
            }
        }
예제 #31
0
        public static bool DeleteProjectItem(this Project project, string path)
        {
            ProjectItem projectItem = GetProjectItem(project, path);

            if (projectItem == null)
            {
                return(false);
            }

            projectItem.Delete();
            return(true);
        }
예제 #32
0
파일: Worker.cs 프로젝트: GitObjects/nestin
		private static void UnNest(Project parent, ProjectItem childItem)
		{
			foreach (var grandChild in childItem.ProjectItems.OfType<ProjectItem>())
			{
				UnNest(parent, grandChild);
			}

			var contentType = childItem.Properties.Item("ItemType").Value;

			var filePath = childItem.FileNames[0];
			var tempFile = Path.GetTempFileName();
			File.Copy(filePath, tempFile, true); 
			
			childItem.Delete();
			
			File.Copy(tempFile, filePath); 
			File.Delete(tempFile);
			var newItem = parent.ProjectItems.AddFromFile(filePath);
			newItem.Properties.Item("ItemType").Value = contentType;
		}
예제 #33
0
        /// <summary>
        /// Deletes the specified <paramref name="item" /> and its parent folders if they are empty.
        /// </summary>
        /// <param name="item">
        /// A Visual Studio <see cref="ProjectItem" />.
        /// </param>
        /// <remarks>
        /// This method correctly deletes empty parent folders in C# and probably
        /// Visual Basic projects which are implemented in C++ as pure COM objects.
        /// However, for Database and probably WiX projects, which are implemented
        /// as .NET COM objects, the parent collection indicates item count = 1
        /// even after its only child item is deleted. So, for new project types,
        /// this method doesn't delete empty parent folders. However, this is probably
        /// desirable for Database projects that create a predefined, empty folder
        /// structure for each schema. We may need to solve this problem in the
        /// future by recording which folders were actually created by the code
        /// generator in the log file and deleting the empty parent folders when
        /// the previously generated folders become empty.
        /// </remarks>
        private static void DeleteProjectItem(ProjectItem item)
        {
            ProjectItems parentCollection = item.Collection;

            item.Delete();

            if (parentCollection.Count == 0)
            {
                var parent = parentCollection.Parent as ProjectItem;
                if (parent != null && parent.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
                {
                    DeleteProjectItem(parent);
                }
            }
        }
        private void DeleteItem(ProjectItem projectItem, DTE vs)
        {
            string itemPath = DteHelper.BuildPath(projectItem);
            itemPath = DteHelper.GetPathFull(vs, itemPath);

            projectItem.Remove();
            projectItem.Delete();
        }
예제 #35
0
        /// <summary>
        /// Removes the specified project item from the test project.
        /// </summary>
        /// <param name="projectItem">The project item to remove.</param>
        public static void RemoveFromProject(ProjectItem projectItem)
        {
            Assert.IsNotNull(projectItem);

            UIThreadInvoker.Invoke(new Action(() =>
            {
                int initialCount = Project.ProjectItems.Count;

                projectItem.Delete();

                Assert.AreEqual(initialCount - 1, Project.ProjectItems.Count);
            }));
        }
예제 #36
0
        /// <summary>
        /// 移除项目中的项
        /// </summary>
        /// <param name="projectItem"></param>
        /// <param name="itemName">项名称</param>
        /// <param name="isDelete">是否删除或者移除</param>
        private bool RemoveItemFromItems(ProjectItem projectItem, string itemName, bool isDelete)
        {
            bool isRemove = false;
            ProjectItem item;
            if (projectItem.Name == itemName)
            {
                item = projectItem;
                if (isDelete)
                {
                    item.Delete();
                }
                else
                {
                    item.Remove();
                }
                isRemove = true;
            }
            else if (projectItem.ProjectItems.Count > 0)
            {
                item = FindProjectItem(projectItem, itemName);
                if (item.Name == itemName)
                {
                    if (isDelete)
                    {
                        item.Delete();
                    }
                    else
                    {
                        item.Remove();
                    }
                    isRemove = true;
                }
            }

            return isRemove;
        }