/// <summary> /// Add Bar Descriptor to each project. /// </summary> private void AddBarDescriptor() { try { DTE dte = _applicationObject as DTE; Projects projs = dte.Solution.Projects; List<Project> projList = new List<Project>(); foreach (Project proj in projs) { projList.Add(proj); } while (projList.Count > 0) { Project proj = projList.ElementAt(0); projList.RemoveAt(0); Configuration config; Property prop; try { config = proj.ConfigurationManager.ActiveConfiguration; prop = config.Properties.Item("ConfigurationType"); } catch { config = null; prop = null; } if (prop == null) { if (proj.ProjectItems != null) { foreach (ProjectItem projItem in proj.ProjectItems) { if (projItem.SubProject != null) projList.Add(projItem.SubProject); } } continue; } if (Convert.ToInt16(prop.Value) != Convert.ToInt16(ConfigurationTypes.typeApplication)) continue; if (config.PlatformName != BLACKBERRY && config.PlatformName != BLACKBERRYSIMULATOR) continue; ProjectItem baritem = proj.ProjectItems.Item(BAR_DESCRIPTOR); string n = proj.Name; if (baritem == null) { tokenProcessor = new TokenProcessor(); Debug.WriteLine("Add bar descriptor file to the project"); string templatePath = dte.Solution.ProjectItemsTemplatePath(proj.Kind); templatePath += BAR_DESCRIPTOR_PATH + BAR_DESCRIPTOR; tokenProcessor.AddReplace(@"[!output PROJECT_NAME]", proj.Name); string destination = System.IO.Path.GetFileName(templatePath); // Remove directory used in previous versions of this plug-in. string folder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(proj.FullName), proj.Name + "_barDescriptor"); if (Directory.Exists(folder)) { try { Directory.Delete(folder); } catch (Exception e) { } } folder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(proj.FullName), "BlackBerry-" + proj.Name); System.IO.Directory.CreateDirectory(folder); destination = System.IO.Path.Combine(folder, destination); tokenProcessor.UntokenFile(templatePath, destination); ProjectItem projectitem = proj.ProjectItems.AddFromFile(destination); } } } catch (Exception e) { Debug.WriteLine(e.Message); } }
private void AddBarDescriptor() { try { DTE dte = _applicationObject as DTE; Projects projs = dte.Solution.Projects; foreach (Project proj in projs) { VCProject vcProj = proj.Object as VCProject; if (vcProj == null) return; IVCCollection cfgs = vcProj.Configurations; bool isBlackBerry = false; foreach (VCConfiguration cfg in cfgs) { if (cfg.ConfigurationType != ConfigurationTypes.typeApplication) return; if (cfg.Platform.Name == BLACKBERRY || cfg.Platform.Name == BLACKBERRYSIMULATOR) isBlackBerry = true; } if (!isBlackBerry) continue; ProjectItem baritem = proj.ProjectItems.Item(BAR_DESCRIPTOR); if (baritem == null && !File.Exists(vcProj.ProjectDirectory + BAR_DESCRIPTOR)) { tokenProcessor = new TokenProcessor(); Debug.WriteLine("Add bar descriptor file to the project"); string templatePath = dte.Solution.ProjectItemsTemplatePath(proj.Kind); templatePath += BAR_DESCRIPTOR_PATH + BAR_DESCRIPTOR; tokenProcessor.AddReplace(@"[!output PROJECT_NAME]", proj.Name); string destination = System.IO.Path.GetFileName(templatePath); destination = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(proj.FullName), destination); tokenProcessor.UntokenFile(templatePath, destination); ProjectItem projectitem = proj.ProjectItems.AddFromFile(destination); } } } catch (Exception e) { Debug.WriteLine(e.Message); } }