public override void Execute(Caliburn.Micro.ActionExecutionContext context) { try { if (files != null) { foreach (var file in files) { references.Add(file); } } if (assemblyNames != null) { foreach (var assemblyName in assemblyNames) { references.Add(new AssemblyReference(assemblyName)); } } OnCompleted(null); } catch (Exception ex) { OnCompleted(ex); } }
/// <summary>导入某类型,导入程序集引用及命名空间引用,主要处理泛型</summary> /// <param name="item"></param> /// <param name="type"></param> void ImportType(TemplateItem item, Type type) { String name = null; try { name = type.Assembly.Location; } catch { } if (!String.IsNullOrEmpty(name) && !AssemblyReferences.Contains(name)) { AssemblyReferences.Add(name); } name = type.Namespace; if (!item.Imports.Contains(name)) { item.Imports.Add(name); } if (type.IsGenericType && !type.IsGenericTypeDefinition) { Type[] ts = type.GetGenericArguments(); foreach (Type elm in ts) { if (!elm.IsGenericParameter) { ImportType(item, elm); } } } }
private void AddDefaultAssemblyReferences() { AssemblyReferences.Add(Core.References.Assemblies.System); AssemblyReferences.Add(Core.References.Assemblies.System_Xml); AssemblyReferences.Add(Core.References.Assemblies.System_Core); AssemblyReferences.Add(Xamarin.References.Assemblies.Xamarin_iOS); }
/// <summary> /// Adds a reference to the supplied Assembly name to the compilers reference collection. /// </summary> /// <param name="assembly"></param> public static void AddAssemblyReference(String assembly) { if (!AssemblyReferences.Contains(assembly)) { AssemblyReferences.Add(assembly); } }
/// <summary> /// Adds a reference to the supplied Assembly to the compilers reference collection. /// </summary> /// <param name="assembly"></param> public static void AddAssemblyReference(Assembly assembly) { if (!AssemblyReferences.Contains(assembly.GetName().Name)) { AssemblyReferences.Add(assembly.GetName().Name); } }
private void AddDefaultAssemblyReferences() { AssemblyReferences.Add(SlnGen.Xamarin.References.Assemblies.Mono_Android); AssemblyReferences.Add(SlnGen.Core.References.Assemblies.System); AssemblyReferences.Add(SlnGen.Core.References.Assemblies.System_Core); AssemblyReferences.Add(SlnGen.Core.References.Assemblies.System_Xml_Linq); AssemblyReferences.Add(SlnGen.Core.References.Assemblies.System_Xml); }
/// <summary> /// Adds the default assembly references. /// This method is called in the project constructor. Override to customize. /// </summary> protected virtual void AddDefaultAssemblyReferences() { AssemblyReferences.Add(References.Assemblies.System); AssemblyReferences.Add(References.Assemblies.System_Core); AssemblyReferences.Add(References.Assemblies.System_Xml_Linq); AssemblyReferences.Add(References.Assemblies.Microsoft_CSharp); AssemblyReferences.Add(References.Assemblies.System_Data); AssemblyReferences.Add(References.Assemblies.System_Net_Http); AssemblyReferences.Add(References.Assemblies.System_Xml); }
/// <summary> /// Defines a new .NET module that references mscorlib version 4.0.0.0. /// </summary> /// <param name="name">The name of the module.</param> public ModuleDefinition(string name) : this(new MetadataToken(TableIndex.Module, 0)) { Name = name; CorLibTypeFactory = CorLibTypeFactory.CreateMscorlib40TypeFactory(this); AssemblyReferences.Add((AssemblyReference)CorLibTypeFactory.CorLibScope); MetadataResolver = new DefaultMetadataResolver(new DotNetFrameworkAssemblyResolver()); TopLevelTypes.Add(new TypeDefinition(null, "<Module>", 0)); }
IProjectTransformConfiguration IProjectTransformConfiguration.AddAssemblyReference(string assemblyPath) { if (assemblyPath == null) { throw new ArgumentNullException(nameof(assemblyPath)); } if (!File.Exists(assemblyPath)) { throw new FileNotFoundException(assemblyPath); } AssemblyReferences.Add(assemblyPath); return(this); }
// Make sure we have a CLR dependency, add it if not... private void FixupClrVersion() { AssemblyReference CLRPlatformAssembly = AssemblyReferences.Find(Constants.CLRPlatformAssemblyName); if (CLRPlatformAssembly == null) { CLRPlatformAssembly = new AssemblyReference(); CLRPlatformAssembly.IsPrerequisite = true; AssemblyReferences.Add(CLRPlatformAssembly); } if (CLRPlatformAssembly.AssemblyIdentity == null || String.IsNullOrEmpty(CLRPlatformAssembly.AssemblyIdentity.Version)) { CLRPlatformAssembly.AssemblyIdentity = new AssemblyIdentity(Constants.CLRPlatformAssemblyName, Util.GetClrVersion(_targetFrameworkVersion)); } }
internal Workspace(string cshellFile) { CShellFile = Path.GetFullPath(cshellFile); CShellFileName = Path.GetFileNameWithoutExtension(cshellFile); this.engine = new ScriptingEngine(); assemblies = new AssemblyReferences(engine); //files = new FileReferences("Files"); RootFolder = Path.GetDirectoryName(cshellFile); RootFolder = Path.GetFullPath(RootFolder); //make sure we add the CShell assembly var cshellCoreAssembly = Assembly.GetExecutingAssembly(); assemblies.Add(new AssemblyReference(cshellCoreAssembly) { Removable = false }); engine.Evaluate("using CShell; using CShell.Sinks;"); }
/// <summary> /// Defines a new .NET module. /// </summary> /// <param name="name">The name of the module.</param> /// <param name="corLib">The reference to the common object runtime (COR) library that this module will use.</param> public ModuleDefinition(string name, AssemblyReference corLib) : this(new MetadataToken(TableIndex.Module, 0)) { Name = name; var importer = new ReferenceImporter(this); corLib = (AssemblyReference)importer.ImportScope(corLib); CorLibTypeFactory = new CorLibTypeFactory(corLib); AssemblyReferences.Add(corLib); OriginalTargetRuntime = DetectTargetRuntime(); MetadataResolver = new DefaultMetadataResolver(CreateAssemblyResolver()); TopLevelTypes.Add(new TypeDefinition(null, "<Module>", 0)); }
/// <summary> /// Initializes a new instance of the <see cref="ProjectFile"/> class /// based on the given <paramref name="xmlContent"/>. /// /// </summary> /// <param name="xmlContent">The contents of a MSBuild project file.</param> public ProjectFile(string xmlContent) { var projectFileDocument = XDocument.Parse(xmlContent); var packageReferenceElements = projectFileDocument.Descendants("PackageReference"); foreach (var packageReferenceElement in packageReferenceElements) { PackageReferences.Add(new PackageReference(packageReferenceElement.Attribute("Include").Value, packageReferenceElement.Attribute("Version").Value)); } var assemblyReferenceElements = projectFileDocument.Descendants("Reference"); foreach (var assemblyReference in assemblyReferenceElements) { AssemblyReferences.Add(new AssemblyReference(assemblyReference.Attribute("Include").Value)); } }
public InteractivePackage AddAssemblyReference( FilePath assemblyReferencePath) { if (assemblyReferencePath.IsNull) { return(this); } if (AssemblyReferences.Contains(assemblyReferencePath)) { return(this); } return(new InteractivePackage( Identity, IsExplicit, AssemblyReferences.Add(assemblyReferencePath), SupportedVersionRange)); }
private HashSet <string> CacheReferences(string assembly, Dictionary <string, List <string> > references) { if (AssemblyReferences.TryGetValue(assembly, out var result)) { return(result); } AssemblyReferences.Add(assembly, Empty); result = new HashSet <string>(); if (references.TryGetValue(assembly, out var list)) { foreach (var ref1 in list) { result.Add(ref1); foreach (var ref2 in CacheReferences(ref1, references)) { result.Add(ref2); } } } AssemblyReferences[assembly] = result; return(result); }
public Project WithAssemblyReference(AssemblyReference assemblyReference) { AssemblyReferences.Add(assemblyReference); return(this); }
private TemplateItem ProcessDirective(Directive directive, TemplateItem item) { #region 包含include if (String.Equals(directive.Name, "include", StringComparison.OrdinalIgnoreCase)) { String name = directive.GetParameter("name"); // 可能采用了相对路径 if (!File.Exists(name)) { name = Path.Combine(Path.GetDirectoryName(item.Name), name); } String content = null; TemplateItem ti = FindTemplateItem(name); if (ti != null) { ti.Included = true; content = ti.Content; } else { // 尝试读取文件 if (File.Exists(name)) { ti = new TemplateItem(); ti.Name = name; ti.Content = File.ReadAllText(name); Templates.Add(ti); ti.Included = true; content = ti.Content; } } // 允许内容为空 //if (String.IsNullOrEmpty(content)) throw new TemplateException(directive.Block, String.Format("加载模版[{0}]失败!", name)); return(ti); } #endregion if (String.Equals(directive.Name, "assembly", StringComparison.OrdinalIgnoreCase)) { String name = directive.GetParameter("name"); if (!AssemblyReferences.Contains(name)) { AssemblyReferences.Add(name); } } else if (String.Equals(directive.Name, "import", StringComparison.OrdinalIgnoreCase)) { item.Imports.Add(directive.GetParameter("namespace")); } else if (String.Equals(directive.Name, "template", StringComparison.OrdinalIgnoreCase)) { if (!item.Processed) { // 由模版指令指定类名 String name = directive.GetParameter("name"); if (!String.IsNullOrEmpty(name)) { item.ClassName = name; } //item.BaseClassName = directive.GetParameter("inherits"); if (directive.TryGetParameter("inherits", out name)) { item.BaseClassName = name; } item.Processed = true; } else { throw new TemplateException(directive.Block, "多个模版指令!"); } } else if (String.Equals(directive.Name, "var", StringComparison.OrdinalIgnoreCase)) { String name = directive.GetParameter("name"); String type = directive.GetParameter("type"); if (item.Vars.ContainsKey(name)) { throw new TemplateException(directive.Block, "模版变量" + name + "已存在!"); } Type ptype = TypeX.GetType(type, true); if (ptype == null) { throw new TemplateException(directive.Block, "无法找到模版变量类型" + type + "!"); } // 因为TypeX.GetType的强大,模版可能没有引用程序集和命名空间,甚至type位于未装载的程序集中它也会自动装载,所以这里需要加上 ImportType(item, ptype); item.Vars.Add(name, ptype); } return(null); }
/// <summary> /// Loads all assembly sources/xml doc and references /// </summary> public List <NAssemblySource> Load(Config config) { // Preload references foreach (var assemblyRef in config.References) { if (!File.Exists(assemblyRef)) { Logger.Error("Assembly reference file [{0}] not found", assemblyRef); } else { AssemblyReferences.Add(AssemblyDefinition.ReadAssembly(assemblyRef, new ReaderParameters(ReadingMode.Deferred))); } } var configPath = Path.GetDirectoryName(Path.GetFullPath(config.FilePath)); configPath = configPath ?? Environment.CurrentDirectory; // Load all sources foreach (var source in config.Sources) { // Setup full path if (!string.IsNullOrEmpty(source.AssemblyPath)) { source.AssemblyPath = Path.Combine(configPath, source.AssemblyPath); } if (!string.IsNullOrEmpty(source.DocumentationPath)) { source.DocumentationPath = Path.Combine(configPath, source.DocumentationPath); } source.MergeGroup = source.MergeGroup ?? "default"; Load(source); } var finalSources = new List <NAssemblySource>(); // Check that all source assemblies have valid Xml associated with it foreach (var assemblySource in AssemblySources.Where(node => node.Assembly != null)) { int countXmlDocFound = 0; NDocumentApi docFound = null; string assemblyName = ((AssemblyDefinition)assemblySource.Assembly).Name.Name; var docSources = new List <NAssemblySource>(); if (assemblySource.Document != null) { docSources.Add(assemblySource); } docSources.AddRange(AssemblySources.Where(node => node.Assembly == null)); foreach (var doc in docSources) { var node = doc.Document.Document.SelectSingleNode("/doc/assembly/name"); if (assemblyName == node.InnerText.Trim()) { docFound = doc.Document; countXmlDocFound++; } } if (countXmlDocFound == 0) { Logger.Fatal("Unable to find documentation for assembly [{0}]", assemblyName); } else if (countXmlDocFound > 1) { Logger.Fatal("Cannot load from multiple ([{0}]) documentation sources for assembly [{1}]", countXmlDocFound, assemblyName); } assemblySource.Document = docFound; finalSources.Add(assemblySource); } return(finalSources); }
public void Parse() { using (var stream = new FileStream(FilePath, FileMode.Open)) { var per = new PEReader(stream); if (!per.HasMetadata) { Name = Name.ToLowerInvariant() + ".dll"; return; //per.PEHeaders.PEHeader.ImportTableDirectory. } var mdr = per.GetMetadataReader(); //mdr.GetModuleReference foreach (var af in mdr.AssemblyFiles.Select(mdr.GetAssemblyFile)) { } foreach (var ar in mdr.AssemblyReferences.Select(mdr.GetAssemblyReference)) { AssemblyReferences.Add(mdr.GetString(ar.Name)); } foreach (var xt in mdr.ExportedTypes.Select(mdr.GetExportedType)) { if (xt.Implementation.Kind == HandleKind.AssemblyReference) { var ar = mdr.GetAssemblyReference((AssemblyReferenceHandle)xt.Implementation); var arn = mdr.GetString(ar.Name); List <string> types; if (!TypeForwarding.TryGetValue(arn, out types)) { TypeForwarding[arn] = types = new List <string>(); } types.Add(mdr.GetString(xt.Name)); } } foreach (var tr in mdr.TypeReferences.Select(mdr.GetTypeReference)) { if (tr.ResolutionScope.Kind == HandleKind.AssemblyReference) { var ar = mdr.GetAssemblyReference((AssemblyReferenceHandle)tr.ResolutionScope); var arn = mdr.GetString(ar.Name); var trn = mdr.GetString(tr.Name); if (trn.StartsWith("Assembly") && trn.EndsWith("Attribute")) { continue; } List <string> types; if (!TypeReferencing.TryGetValue(arn, out types)) { TypeReferencing[arn] = types = new List <string>(); } types.Add(trn); } else { //Console.WriteLine("{0}", tr.ResolutionScope.Kind); } } foreach (var td in mdr.TypeDefinitions.Select(mdr.GetTypeDefinition)) { var tdn = mdr.GetString(td.Name); if ((td.Attributes & TypeAttributes.Public) == TypeAttributes.Public && !tdn.StartsWith("<")) { TypeDefinitions.Add(tdn); } foreach (var md in td.GetMethods().Select(mdr.GetMethodDefinition)) { var imp = md.GetImport(); if (!imp.Module.IsNil) { var mr = mdr.GetModuleReference(imp.Module); var mrn = mdr.GetString(mr.Name); if (!mrn.EndsWith(".dll")) { mrn = mrn + ".dll"; } if (!DllImports.Contains(mrn)) { DllImports.Add(mrn); } } } } } }
public void AddReference(AssemblyReference reference) => AssemblyReferences = AssemblyReferences.Add(reference);
public void AddMetadataReference(Type type) { AssemblyReferences.Add(MetadataReference.CreateFromFile(type.GetTypeInfo().Assembly.Location)); }