本文整理汇总了C#中ProjectItems.Item方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectItems.Item方法的具体用法?C# ProjectItems.Item怎么用?C# ProjectItems.Item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProjectItems
的用法示例。
在下文中一共展示了ProjectItems.Item方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CopyProjectItems
private static void CopyProjectItems(ProjectItems sourceItems, ProjectItems targetItems)
{
foreach (ProjectItem projectItem in sourceItems)
{
ProjectItem tempItem = null;
try
{
tempItem = targetItems.Item(projectItem.Name);
}
catch (ArgumentException)
{
if (projectItem.Kind == "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}")
{
if (projectItem.Name != "Properties")
{
tempItem = targetItems.AddFolder(projectItem.Name);
}
}
else if (projectItem.Name != "packages.config")
{
tempItem = targetItems.AddFromFile(projectItem.Properties.Item("LocalPath").Value as string);
}
}
if (tempItem != null)
{
CopyProjectItems(projectItem.ProjectItems, tempItem.ProjectItems);
}
}
}
示例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: FindProjectItem
internal static ProjectItem FindProjectItem(ProjectItems projectItems, string lookupName)
{
int count = projectItems.Count;
for (int i = 1; i <= count; i++)
{
ProjectItem projectItem = projectItems.Item(i);
if (string.Equals(lookupName, projectItem.Name, StringComparison.OrdinalIgnoreCase))
{
return projectItem;
}
}
return null;
}
示例5: 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);
}
示例6: RemoveNestedItems
/// <summary>
/// Removes the nested items of an item of which the soure does not exists.
/// </summary>
/// <param name="projectItems">The project items.</param>
/// <param name="relatedProjects">The related projects.</param>
/// <exception cref="ArgumentNullException">The <paramref name="projectItems" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException">The <paramref name="relatedProjects" /> is <c>null</c>.</exception>
private void RemoveNestedItems(ProjectItems projectItems, Project[] relatedProjects)
{
Argument.IsNotNull("projectItems", projectItems);
Argument.IsNotNull("relatedProjects", relatedProjects);
for (int i = 1; i < projectItems.Count + 1; i++)
{
ProjectItem folderItem = projectItems.Item(i);
if (folderItem.IsFolder())
{
RemoveNestedItems(folderItem.ProjectItems, relatedProjects);
if (folderItem.ProjectItems.Count == 0)
{
Log.Debug("Removing folder '{0}' because it no longer contains items", folderItem.Name);
folderItem.Remove();
i--;
}
}
else
{
// If this is a linked file and not an actual file in another related project, remove it
if (folderItem.IsLinkedFile() && !folderItem.IsActualFileInAnyRelatedProject(relatedProjects))
{
folderItem.Remove();
i--;
}
}
}
}
示例7: RemoveFilesAndFolders
/// <summary>
/// Removes the files and folders.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="targetProjectType">Type of the target project.</param>
/// <param name="levels">The number of levels to walk down the chain. If <c>-1</c>, it will handle all levels.</param>
/// <param name="fileFilter">An enumerable of files that should be handled with care, can be <c>null</c>.</param>
/// <exception cref="ArgumentNullException">The <paramref name="source" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException">The <paramref name="target" /> is <c>null</c>.</exception>
private void RemoveFilesAndFolders(ProjectItems source, ProjectItems target, ProjectType targetProjectType, int levels, IEnumerable<string> fileFilter)
{
Argument.IsNotNull("source", source);
Argument.IsNotNull("target", target);
if (fileFilter == null)
{
fileFilter = new string[] { };
}
string targetParentName = target.Parent.GetObjectName();
Log.Debug("Removing files and folders from target '{0}'", targetParentName);
if (levels == 0)
{
return;
}
levels--;
// Yep, this is right, we start at 1... :(
for (int i = 1; i < target.Count + 1; i++)
{
var targetItem = target.Item(i);
if (ShouldSkipRemovingOfItem(source.ContainingProject, targetItem, targetProjectType))
{
Log.Debug("Skipping item '{0}' because it is ignored by a rule for target project {1}", targetItem.GetObjectName(), targetProjectType);
continue;
}
var existingSourceItem = (from sourceItem in source.Cast<ProjectItem>() where string.Equals(targetItem.Name, sourceItem.Name, StringComparison.InvariantCultureIgnoreCase) select sourceItem).FirstOrDefault();
if (existingSourceItem != null && !fileFilter.Any(x => string.Equals(x, targetItem.GetNameRelativeToRoot(), StringComparison.InvariantCultureIgnoreCase)))
{
// Check if the item should be removed (when the item should not be added as linked file, then we should remove it)
if (!ShouldSkipAddingOfItem(existingSourceItem, targetProjectType))
{
RemoveFilesAndFolders(existingSourceItem.ProjectItems, targetItem.ProjectItems, targetProjectType, levels, fileFilter);
continue;
}
Log.Debug("Found linked file '{0}' that is now ignored by a rule, removing it", targetItem.FileNames[0]);
}
// Get it once, we don't want to retrieve this several times
var relatedProjects = source.ContainingProject.GetRelatedProjects(false);
if (targetItem.IsFolder())
{
RemoveNestedItems(targetItem.ProjectItems, relatedProjects);
if (targetItem.ProjectItems.Count == 0)
{
Log.Debug("Removing folder '{0}' because it no longer contains items", targetItem.Name);
targetItem.Remove();
i--;
}
}
else
{
// If this is a linked file and not an actual file in another related project, remove it
if (targetItem.IsLinkedFile() && !targetItem.IsActualFileInAnyRelatedProject(relatedProjects))
{
Log.Debug("Removing file '{0}' because it is a linked file to the root project", targetItem.FileNames[0]);
targetItem.Remove();
i--;
}
}
}
Log.Debug("Removed files and folders from target '{0}'", targetParentName);
}
示例8: EnumerateProjectItems
private IEnumerable<ProjectItemWrapper> EnumerateProjectItems(ProjectItems items)
{
if (items != null)
{
for (int i = 1; i <= items.Count; i++)
{
var itm = items.Item(i);
var itmGuid = Guid.Parse(itm.Kind);
foreach (var res in EnumerateProjectItems(itm.ProjectItems))
{
yield return res;
}
if (itmGuid.Equals(ProjectVirtualFolderGuid)
|| itmGuid.Equals(ProjectFolderGuid))
{
continue;
}
for (short j = 0; itm != null && j < itm.FileCount; j++)
{
bool bSkip = false;
foreach (var ending in FileEndingsToSkip)
{
if (itm.FileNames[1] == null || itm.FileNames[1].EndsWith(ending))
{
bSkip = true;
break;
}
}
if (!bSkip)
{
yield return new ProjectItemWrapper(itm);
}
}
}
}
}
示例9: GetGroupFolder
private static ProjectItem GetGroupFolder(string groupFolderName, ProjectItems ProjectItems)
{
ProjectItem groupFolder = ProjectItems.Item(groupFolderName);
if (groupFolder == null)
throw new Exception(string.Empty);
return groupFolder;
}
示例10: GetSqlFileItems
private static ProjectItems GetSqlFileItems(string groupFolderName, ProjectItems scheduledTasksProjectItems)
{
ProjectItems groupFolderFileItems;
ProjectItem groupFolder = GetGroupFolder(groupFolderName, scheduledTasksProjectItems.Item("sql").ProjectItems);
groupFolderFileItems = groupFolder.ProjectItems;
return groupFolderFileItems;
}
示例11: IncludeExistingFolder
private ProjectItem IncludeExistingFolder(string folderName, ProjectItems collection)
{
IVsHierarchy targetHierarchy = TargetProject.GetVsHierarchy(solution);
IVsProject targetIVsProject = targetHierarchy as IVsProject;
if (targetIVsProject != null)
{
string folderAbsolutePath;
ProjectItem parentProjectItem = collection.Parent as ProjectItem;
if (parentProjectItem != null)
{
folderAbsolutePath = Path.Combine(parentProjectItem.Properties.GetValue("FullPath", string.Empty), folderName);
}
else
{
folderAbsolutePath = Path.Combine(Path.GetDirectoryName(TargetProject.FullName), folderName);
}
string containerFolderRelativePath = GetPathRelativeToProject(TargetProject, Path.GetDirectoryName(folderAbsolutePath));
uint containerFolderId = hierarchyHelper.GetItemId(targetHierarchy, containerFolderRelativePath);
VSADDRESULT[] result = new VSADDRESULT[1];
int hr = targetIVsProject.AddItem(containerFolderId,
VSADDITEMOPERATION.VSADDITEMOP_OPENFILE,
string.Empty, //No file name because it's a directory
1, // Has to correspond to #items below...
new[] { folderAbsolutePath }, // Full path to item
IntPtr.Zero, // Don't show window
result); // Result array...
ErrorHandler.ThrowOnFailure(hr);
logger.Log(string.Format(CultureInfo.CurrentCulture, Resources.IncludingExistingFolderInProject, GetPathRelativeToProject(TargetProject, folderAbsolutePath), TargetProject.Name));
}
return collection.Item(folderName);
}
示例12: FindProjectItemByFileName
public static ProjectItem FindProjectItemByFileName(ProjectItems projectItems, string relativePathAndName)
{
for (var ii = 1; ii <= projectItems.Count; ii++)
{
var projectItem = projectItems.Item(ii);
if (projectItem != null)
{
if (projectItem.Kind == Constants.vsProjectItemKindPhysicalFolder)
{
var p = FindProjectItemByFileName(projectItem.ProjectItems, relativePathAndName);
if (p != null) return p;
}
else
{
var fileName = projectItem.FileNames[0];
if (fileName.ToLower() == relativePathAndName.ToLower())
{
return projectItem;
}
}
}
}
return null;
}
示例13: duplicateFiles
private void duplicateFiles(ProjectItems projItems)
{
ProjectItem projItem;
for (int i = 1; i <= projItems.Count; i++)
{
projItem = projItems.Item(i);
Debug.Write(projItem.Name + " " + projItem.Kind);
try
{
if (projItem.ProjectItems.Count > 0)
{
duplicateFiles(projItem.ProjectItems);
}
else if (selectedProjectItems.Contains(projItem))
{
selectedProjectItems.Remove(projItem);
String newPath = copyFile(projItem);
if (newPath != null)
{
try
{
lastAdded = projItems.AddFromFile(newPath);
}
catch (Exception) { }
}
}
}
catch (Exception)
{
}
}
}
示例14: UpdateModel
/// <summary>
/// Updates the model.
/// </summary>
/// <param name="projectItems">The project items.</param>
/// <param name="fw">The fw.</param>
public static void UpdateModel(
ProjectItems projectItems,
ITestFramework fw)
{
for (var i = 1; i < projectItems.Count - 1; i++)
{
var projectItem = projectItems.Item(i);
if (projectItem.Name.EndsWith(
".log",
StringComparison.OrdinalIgnoreCase)) continue;
var testClass =
(from tc in fw.Classes
where tc.Name == projectItem.Name.Replace(".cs", "")
select tc).FirstOrDefault();
if (testClass == null)
{
//todo: dump code to log....
continue;
}
string fileContent;
using (var sr = new StreamReader(projectItem.FileNames[0]))
{
fileContent = sr.ReadToEnd();
}
var usingMatches = s_usingRegex.Matches(fileContent);
for (var j = 0; j < usingMatches.Count; j++)
{
var match = usingMatches[j];
if (!testClass.UsingStatements.Contains(match.Value))
{
testClass.UsingStatements.Add(match.Value);
}
}
var matches = s_codeRegex.Matches(fileContent);
for (var j = 0; j < matches.Count; j++)
{
var match = matches[j];
if (!match.Success) continue;
var testName = match.Groups["testname"].Value;
var testAttributes = match.Groups["attributes"].Value;
var testImplementation = match.Groups["code"].Value;
var test =
(from t in testClass.Tests
where t.Name == testName
select t).FirstOrDefault();
if (test == null)
{
//todo: dump code to log....
continue;
}
test.Attributes = testAttributes;
test.Implementation = testImplementation;
}
}
}
示例15: GetItem
private ArrayList GetItem(ProjectItems prj, string prjName)
{
ArrayList result = new ArrayList();
try
{
for(int iProjectItem = 0; iProjectItem < prj.Count; iProjectItem++)
{
ProjectItem prjItem = prj.Item(iProjectItem+1);
Property ob = null;
for(int i = 0; i < prjItem.Properties.Count; i++)
{
Property p = prjItem.Properties.Item(i+1);
if (p.Name == "SubType")
{
ob = p;
break;
}
}
if (ob != null)
{
int img = -1;
int add = 0;
if (_onlyOpenned)
if (prjItem.Document == null) continue;
if (prjItem.Document != null)
add = 4;
if (ob.Value.ToString() == "Code")
img = 0 + add;
if (ob.Value.ToString() == "Form")
img = 1 + add;
if (ob.Value.ToString() == "UserControl")
img = 2 + add;
if (ob.Value.ToString() == "Component")
img = 3 + add;
//if (img == -1)
//continue;
result.Add(new ListItemData(prjItem.Name, img, prjName, prjItem));
}
if (prjItem.ProjectItems != null)
{
result.AddRange(GetItem(prjItem.ProjectItems, prjName + "\\" + prjItem.Name));
}
}
}
catch
{
//System.Diagnostics.Trace.WriteLine(e.Message, "AS VS Expert: GetItem");
}
return result;
}