当前位置: 首页>>代码示例>>C#>>正文


C# ProjectItems.AddFromTemplate方法代码示例

本文整理汇总了C#中ProjectItems.AddFromTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectItems.AddFromTemplate方法的具体用法?C# ProjectItems.AddFromTemplate怎么用?C# ProjectItems.AddFromTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProjectItems的用法示例。


在下文中一共展示了ProjectItems.AddFromTemplate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddFromFile

 public void AddFromFile(string fileName,string itemName)
 {
     string folderName = GetFolderName();
     GetCurrentProject();
     viewsFolder = curProject.ProjectItems; ;//default ViewsFolder is  the root of the project
     SearchFolder(folderName, viewsFolder);//find the real folder the new view must be inserted to
     viewsFolder.AddFromTemplate(fileName, itemName);
     int i = 1;
     for (; i < viewsFolder.Count; i++)
         if (viewsFolder.Item(i).Name == itemName)
             break;
     //EnvDTE.Constants.vsViewKindCode = {7651A701-06E5-11D1-8EBD-00A0C90F26EA}
     viewsFolder.Item(i).Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}").Visible = true;
 }
开发者ID:IntranetFactory,项目名称:ndjango,代码行数:14,代码来源:ViewWizard.cs

示例2: AddNewItemFromVsTemplate

        /// <summary>
        /// Create a new item in the project
        /// </summary>
        /// <param name="parent">the parent collection for the new item</param>
        /// <param name="templateName"></param>
        /// <param name="language"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ProjectItem AddNewItemFromVsTemplate(ProjectItems parent, string templateName, string language, string name)
        {
            if (parent == null)
                throw new ArgumentException("project");
            if (name == null)
                throw new ArgumentException("name");

            DTE dte = (DTE)VsIdeTestHostContext.ServiceProvider.GetService(typeof(DTE));

            Solution2 sol = dte.Solution as Solution2;

            string filename = sol.GetProjectItemTemplate(templateName, language);

            parent.AddFromTemplate(filename, name);

            return parent.Item(name);
        }
开发者ID:reima,项目名称:codemaid,代码行数:25,代码来源:TestUtils.cs

示例3: AddFromFile

        public void AddFromFile(string fileName,string itemName)
        {
            int rootLen = projectDir.Length;
            string folderName = viewsFolderName.Substring(rootLen + 1, viewsFolderName.Length - rootLen - 1);
            int index = GetActiveProject();
            if (index > 0)
            {
                viewsFolder = dte.Solution.Projects.Item(index).ProjectItems; ;//default ViewsFolder is  the root of the project
                SearchFolder(folderName, viewsFolder);//find the real folder the new view must be inserted to
                viewsFolder.AddFromTemplate(fileName, itemName);
                int i = 1;
                for (; i < viewsFolder.Count; i++)
                    if (viewsFolder.Item(i).Name == itemName)
                        break;
                //EnvDTE.Constants.vsViewKindCode = {7651A701-06E5-11D1-8EBD-00A0C90F26EA}
                viewsFolder.Item(i).Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}").Visible = true;

            }
        }
开发者ID:IntranetFactory,项目名称:ndjango,代码行数:19,代码来源:ViewWizard.cs

示例4: AddToNewFile

        private static void AddToNewFile(string code, ProjectItems items, string filename) {
            var tempFile = Path.GetTempFileName();
            File.WriteAllText(tempFile, code);

            var projectItem = items.AddFromTemplate(tempFile, filename);
            var window = projectItem.Open();
            window.Activate();
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:8,代码来源:MLPackage.cs

示例5: CreateTestProjectItem

        protected ProjectItem CreateTestProjectItem(ProjectItems projectItems, string templateName)
        {
            if (projectItems == null)
            {
                throw new ArgumentNullException("projectItems");
            }

            string templateFile = Solution.GetProjectItemTemplate(templateName, this.TargetProject.Language);
            string itemName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            ProjectItem projectItem = projectItems.AddFromTemplate(templateFile, itemName)
                ?? projectItems.Cast<ProjectItem>().First(pi => Path.GetFileNameWithoutExtension(pi.Name) == itemName);
            projectItem.Document.Close(); // To avoid sideffects and enable testing by writing to files as opposed to document manipulation
            return projectItem;
        }
开发者ID:icool123,项目名称:T4Toolbox,代码行数:14,代码来源:IntegrationTest.cs

示例6: AddFromTemplate

        internal static ProjectItem AddFromTemplate(ProjectItems projectItems, string template, string TargetFileName, bool overwrite)
        {
            ProjectItem pitem = null;
            try
            {
                //is there already a project item with the target name 
                ProjectItem existingItem = GetProjectItemByName(projectItems, TargetFileName);
                if (existingItem != null)
                {
                    //item with the same name already there
                    //overwrite it?
                    if (overwrite || projectItems.DTE.SuppressUI)
                    {
                        //overwrite the file with the new contents
                        string pathToExistingItem = Helpers.GetFullPathOfProjectItem(existingItem);
                        Helpers.EnsureCheckout(projectItems.DTE, pathToExistingItem);
                        File.Copy(template, pathToExistingItem, true);
                        Helpers.LogMessage(projectItems.DTE, projectItems.DTE, pathToExistingItem + ": Contents updated");
                    }
                    else
                    {
                        if (MessageBox.Show("File " + TargetFileName + " already exists. Overwrite?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            //overwrite the file with the new contents
                            string pathToExistingItem = Helpers.GetFullPathOfProjectItem(existingItem);
                            Helpers.EnsureCheckout(projectItems.DTE, pathToExistingItem);
                            File.Copy(template, pathToExistingItem, true);
                            Helpers.LogMessage(projectItems.DTE, projectItems.DTE, pathToExistingItem + ": Contents updated");
                        }
                    }
                    return existingItem;
                }

                //is there already a file with the same name, but it is not part of the project
                string pathToExistingFile = Path.Combine(GetPathOfProjectItems(projectItems), TargetFileName);
                if (File.Exists(pathToExistingFile))
                {
                    //ups, file with same name exists, but is not part of the project
                    //update the contents and include the file to the project
                    Helpers.EnsureCheckout(projectItems.DTE, pathToExistingFile);
                    File.Copy(template, pathToExistingFile, true);
                    return Helpers.AddFromFile(projectItems, pathToExistingFile);
                }

                //default situation: a file or item with the same name does not exists at the target location
                pitem = projectItems.AddFromTemplate(template, TargetFileName);
//                Helpers.LogMessage(projectItems.DTE, projectItems.DTE, Helpers.GetFullPathOfProjectItem(pitem) + ": File Added");
                Helpers.CheckSharePointReferences(pitem);
            }
            catch (Exception)
            {
                Helpers.LogMessage(projectItems.DTE, projectItems.DTE, Helpers.GetFullPathOfProjectItem(pitem) + ": Already exists");
            }

            return pitem;
        }
开发者ID:manuel11g,项目名称:SharePoint-Software-Factory,代码行数:56,代码来源:Helpers.cs

示例7: CreateDocumentFromTemplete

 /// <summary>
 ///创建基于模板的文档
 /// </summary>
 /// <param name="projectItems">某个项目下面的ProjectItems</param>
 /// <param name="documentType">DocumentType枚举</param>
 /// <param name="documentName">文档名字(不包含后缀)</param>
 public void CreateDocumentFromTemplete(ProjectItems projectItems, string documentType, string documentName)
 {
     if (VSSolution.CurrentSolution2 != null)
     {
         string projectTemplate = VSSolution.CurrentSolution2.GetProjectItemTemplate(documentType, "CSharp");
         if (!string.IsNullOrEmpty(projectTemplate))
         {
             projectItems.AddFromTemplate(projectTemplate, documentName);
         }
     }
 }
开发者ID:qianlifeng,项目名称:easyvsx,代码行数:17,代码来源:VSProject.cs

示例8: AddFromItemTypeName

        private static void AddFromItemTypeName(Project project, ProjectItems items, string path, string itemTypeName,
                                                NewItemDynamicParameters p, Solution2 sln)
        {
            if ("folder" == itemTypeName.ToLowerInvariant())
            {
                if (project.Object is SolutionFolder)
                {
                    var folder = project.Object as SolutionFolder;
                    folder.AddSolutionFolder(path);
                }
                else
                {
                    items.AddFolder(path, Constants.vsProjectItemKindPhysicalFolder);
                }
            }
            else
            {
                if (!itemTypeName.ToLowerInvariant().EndsWith(".zip"))
                {
                    itemTypeName += ".zip";
                }

                p.Category = GetSafeCategoryValue(p.Category, project.CodeModel);

                //todo: validate p.Category against available item/project tmps

                if (project.Object is SolutionFolder)
                {
                    SolutionFolder folder = project.Object as SolutionFolder;
                    NewTemplateItemInSolutionFolder(path, itemTypeName, sln, p, folder);
                }
                else
                {
                    var t = sln.GetProjectItemTemplate(itemTypeName, p.Category);
                    items.AddFromTemplate(t, path);
                }
            }
        }
开发者ID:wangchunlei,项目名称:MyGit,代码行数:38,代码来源:NewProjectItemManager.cs

示例9: AddNewItemFromVsTemplate

        /// <summary>
        /// Create a new item in the project
        /// </summary>
        /// <param name="project">the project collection for the new item</param>
        /// <param name="templateName"></param>
        /// <param name="language"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public ProjectItem AddNewItemFromVsTemplate(ProjectItems project, string templateName, string language, string name)
        {
            if (project == null)
                throw new ArgumentException(nameof(project));
            if (name == null)
                throw new ArgumentException(nameof(name));

            var dte = (DTE)VsIdeTestHostContext.ServiceProvider.GetService(typeof(DTE));

            var sol = (Solution2) dte.Solution;

            var filename = sol.GetProjectItemTemplate(templateName, language);

            project.AddFromTemplate(filename, name);

            return project.Item(name);
        }
开发者ID:davidkron,项目名称:DevArch,代码行数:25,代码来源:Testutils.cs


注:本文中的ProjectItems.AddFromTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。