private void UpdateProjectTemplateCsVb(XmlDocument xmlDoc, string ProjectName, IAssemblyReferenceCollection References) { string text2 = "CSHARP"; if (LanguageManager.ActiveLanguage.Name == "Visual Basic") text2 = "VisualBasic"; XmlNode node0 = xmlDoc.SelectSingleNode("/VisualStudioProject/" + text2); node0.Attributes["ProjectGuid"].Value = Guid.NewGuid().ToString().ToUpper(); string text3 = "/VisualStudioProject/" + text2 + "/Build/Settings"; XmlNode node1 = xmlDoc.SelectSingleNode(text3); node1.Attributes["AssemblyName"].Value = ProjectName; node1.Attributes["RootNamespace"].Value = ProjectName; switch (_projectType) { case 1: node1.Attributes["OutputType"].Value = "Library"; break; case 2: node1.Attributes["OutputType"].Value = "WinExe"; break; case 3: node1.Attributes["OutputType"].Value = "Exe"; break; } string text4 = "/VisualStudioProject/" + text2 + "/Files/Include"; XmlNode node2 = xmlDoc.SelectSingleNode(text4); node2.RemoveAll(); foreach (string filePath in _projectFiles) { if ((filePath != null) && (filePath != string.Empty)) { XmlNode node3 = xmlDoc.CreateElement("", "File", ""); XmlAttribute attribute1 = xmlDoc.CreateAttribute("RelPath"); XmlAttribute attribute2 = xmlDoc.CreateAttribute("SubType"); XmlAttribute attribute3 = xmlDoc.CreateAttribute("BuildAction"); attribute1.Value = filePath; node3.Attributes.Append(attribute1); if (filePath.EndsWith(".cs") || filePath.EndsWith(".vb")) { attribute2.Value = "Code"; node3.Attributes.Append(attribute2); attribute3.Value = "Compile"; } else // gotta be a resource { attribute3.Value = "EmbeddedResource"; } node3.Attributes.Append(attribute3); node2.AppendChild(node3); } } string text6 = "/VisualStudioProject/" + text2 + "/Build/References"; XmlNode node4 = xmlDoc.SelectSingleNode(text6); node4.RemoveAll(); if (References != null) { StringCollection collection1 = new StringCollection(); foreach (IAssemblyReference name1 in References) { if (!collection1.Contains(name1.Name)) { XmlNode node5 = xmlDoc.CreateElement("", "Reference", ""); XmlAttribute attribute4 = xmlDoc.CreateAttribute("Name"); attribute4.Value = name1.Name; node5.Attributes.Append(attribute4); XmlAttribute attribute5 = xmlDoc.CreateAttribute("AssemblyName"); attribute5.Value = name1.Name; node5.Attributes.Append(attribute5); if (name1 != null && name1.Resolve() != null) { XmlAttribute attribute6 = xmlDoc.CreateAttribute("HintPath"); attribute6.Value = Path.GetFileName(name1.Resolve().Location); node5.Attributes.Append(attribute6); } node4.AppendChild(node5); collection1.Add(name1.Name); } } } }
/// <summary> /// Generates Visual Studio project files /// </summary> /// <param name="ProjectName"></param> /// <param name="ProjectPath"></param> /// <param name="References"></param> /// <remarks>This code was provided by Jens Andersson, [email protected]</remarks> private void GenerateVisualStudioProject(string ProjectName, string ProjectPath, IAssemblyReferenceCollection References) { if (_projectType < 1 || _projectType > 3) return; System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); string projectExt; string template = assembly.GetName().Name; ILanguage language = LanguageManager.ActiveLanguage; if (language.Name == "C#") { projectExt = ".csproj"; template += ".VSProjects.CSharpProject.xml"; } else if (language.Name == "Visual Basic") { projectExt = ".vbproj"; template += ".VSProjects.VBProject.xml"; } else if (language.Name == "MC++") { projectExt = ".vcproj"; if (_projectType == 1) template += ".VSProjects.CppProject_dll.xml"; else template += ".VSProjects.CppProject_exe.xml"; } else { WriteLine("Cannot create project file, " + language.Name + " language is not supported."); return; } Stream stream1 = assembly.GetManifestResourceStream(template); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(stream1); if (language.Name == "MC++") UpdateProjectTemplateCpp(xmlDoc, ProjectName, References); else UpdateProjectTemplateCsVb(xmlDoc, ProjectName, References); string fileName; fileName = Path.Combine(ProjectPath, ProjectName + projectExt); xmlDoc.Save(fileName); WriteLine(fileName); }
private void UpdateProjectTemplateCpp(XmlDocument xmlDoc, string ProjectName, IAssemblyReferenceCollection References) { string text1 = "/VisualStudioProject"; XmlNode node1 = xmlDoc.SelectSingleNode(text1); node1.Attributes["ProjectGUID"].Value = Guid.NewGuid().ToString().ToUpper(); node1.Attributes["Name"].Value = ProjectName; node1.Attributes["RootNamespace"].Value = ProjectName; string text2 = "/VisualStudioProject/Files"; XmlNode node2 = xmlDoc.SelectSingleNode(text2); node2.RemoveAll(); Hashtable folders = new Hashtable(); foreach (string filePath in _projectFiles) { if ((filePath != null) && (filePath != string.Empty)) { string pathName = Path.GetDirectoryName(filePath); if (folders[pathName] == null) { if (pathName.Length == 0) { folders[pathName] = node2; } else { XmlNode pathNode = xmlDoc.CreateElement("", "Filter", ""); XmlAttribute nameAttr = xmlDoc.CreateAttribute("Name"); nameAttr.Value = pathName; pathNode.Attributes.Append(nameAttr); node2.AppendChild(pathNode); folders[pathName] = pathNode; } } XmlNode fileNode = xmlDoc.CreateElement("", "File", ""); XmlAttribute pathAttr = xmlDoc.CreateAttribute("RelativePath"); pathAttr.Value = filePath; fileNode.Attributes.Append(pathAttr); XmlNode node3 = (XmlNode)folders[pathName]; node3.AppendChild(fileNode); } } string text4 = "/VisualStudioProject/References"; XmlNode node4 = xmlDoc.SelectSingleNode(text4); node4.RemoveAll(); if (References != null) { StringCollection collection1 = new StringCollection(); foreach (IAssemblyReference name1 in References) { if (!collection1.Contains(name1.Name)) { XmlNode refNode = xmlDoc.CreateElement("", "AssemblyReference", ""); XmlAttribute pathAttr = xmlDoc.CreateAttribute("RelativePath"); pathAttr.Value = Path.GetFileName(name1.Resolve().Location); refNode.Attributes.Append(pathAttr); node4.AppendChild(refNode); collection1.Add(name1.Name); } } } }
public static bool Compare(this IAssemblyReferenceCollection source, IAssemblyReferenceCollection n, Func<IAssemblyReference, IAssemblyReference, Action<string, string>, bool> checkitem, Action<string, string> errAct) { return Compare<IAssemblyReference>(source,n,checkitem,errAct); }
public static bool Compare(this IAssemblyReferenceCollection source, IAssemblyReferenceCollection n, Func<IAssemblyReference, IAssemblyReference, bool> checkitem) { return Compare<IAssemblyReference>(source,n,checkitem); }
public static bool Compare(this IAssemblyReferenceCollection source, IAssemblyReferenceCollection n) { return Compare<IAssemblyReference>(source,n); }
internal IntermediateAssemblyReferenceDictionary(IAssemblyReferenceCollection references) { this.references = references; }
public virtual IAssemblyReferenceCollection TransformAssemblyReferenceCollection(IAssemblyReferenceCollection value) { IAssemblyReference[] array = new IAssemblyReference[value.Count]; for (int i = 0; i < value.Count; i++) { array[i] = this.TransformAssemblyReference(value[i]); } IAssemblyReferenceCollection target = new AssemblyReferenceCollection(); target.AddRange(array); return target; }