private static void SetDependentUpon(ProjectItem item, string value) { if (item.ContainsProperty("DependentUpon")) { item.Properties.Item("DependentUpon").Value = value; } }
public static ProjectItem AddNestedFile(ProjectItem item, string newFile, string itemType, bool force = false) { try { if (item == null || item.ContainingProject == null) { return(null); } ProjectItem newItem = null; bool mayNeedAttributeSet = item.ContainingProject.IsKind(ProjectTypes.DOTNET_Core, ProjectTypes.UNIVERSAL_APP); if (item.ProjectItems == null) { item.ContainingProject.AddFileToProject(newFile, itemType); } else if ((newItem = _dte.Solution.FindProjectItem(newFile)) == null || force) { newItem = item.ProjectItems.AddFromFileCopy(newFile); } bool isVisualStudioRTM = false; if (mayNeedAttributeSet) { if (newItem != null) { if (newItem.ContainsProperty("DependentUpon")) { isVisualStudioRTM = true; newItem.Properties.Item("DependentUpon").Value = item.FileNames[0]; } } //如果是免费版VS,则要手动修改项目文件。 if (!isVisualStudioRTM) { Helper.NestedHelper helper = new NestedHelper(); string parentItemType = item.Properties.Item("ItemType").Value.ToString(); if (string.IsNullOrEmpty(parentItemType)) { parentItemType = "None"; } //防止项目未保存,而本地的项目文件却已经修改。 item.ContainingProject.Save(); helper.NestedFile(item, parentItemType, newFile, itemType); } } return(newItem); } catch (Exception ex) { Logger.Log(ex); return(null); } }