本文整理汇总了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;
}
示例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);
}
示例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;
}
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}