当前位置: 首页>>代码示例>>C#>>正文


C# System.Reflection.AssemblyName.GetPublicKeyToken方法代码示例

本文整理汇总了C#中System.Reflection.AssemblyName.GetPublicKeyToken方法的典型用法代码示例。如果您正苦于以下问题:C# System.Reflection.AssemblyName.GetPublicKeyToken方法的具体用法?C# System.Reflection.AssemblyName.GetPublicKeyToken怎么用?C# System.Reflection.AssemblyName.GetPublicKeyToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.AssemblyName的用法示例。


在下文中一共展示了System.Reflection.AssemblyName.GetPublicKeyToken方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileProject

        public Assembly CompileProject(string projectFileName)
        {
            Assembly existing;
            if (Compilations.TryGetValue(Path.GetFullPath(projectFileName), out existing))
            {
                return existing;
            }

            var project = new Microsoft.Build.BuildEngine.Project();
            project.Load(projectFileName);

            var projectName = Environment.NameTable.GetNameFor(project.EvaluatedProperties["AssemblyName"].Value);
            var projectPath = project.FullFileName;
            var compilerOptions = new SpecSharpOptions();
            var assemblyReferences = new List<IAssemblyReference>();
            var moduleReferences = new List<IModuleReference>();
            var programSources = new List<SpecSharpSourceDocument>();
            var assembly = new SpecSharpAssembly(projectName, projectPath, Environment, compilerOptions, assemblyReferences, moduleReferences, programSources);
            var helper = new SpecSharpCompilationHelper(assembly.Compilation);

            Compilations[Path.GetFullPath(projectFileName)] = assembly;

            assemblyReferences.Add(Environment.LoadAssembly(Environment.CoreAssemblySymbolicIdentity));
            project.Build("ResolveAssemblyReferences");
            foreach (BuildItem item in project.GetEvaluatedItemsByName("ReferencePath"))
            {
                var assemblyName = new System.Reflection.AssemblyName(item.GetEvaluatedMetadata("FusionName"));
                var name = Environment.NameTable.GetNameFor(assemblyName.Name);
                var culture = assemblyName.CultureInfo != null ? assemblyName.CultureInfo.Name : "";
                var version = assemblyName.Version == null ? new Version(0, 0) : assemblyName.Version;
                var token = assemblyName.GetPublicKeyToken();
                if (token == null) token = new byte[0];
                var location = item.FinalItemSpec;
                var identity = new AssemblyIdentity(name, culture, version, token, location);
                var reference = Environment.LoadAssembly(identity);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("ProjectReference"))
            {
                var name = Environment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(item.FinalItemSpec));
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var reference = CompileProject(location);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("Compile"))
            {
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var name = Environment.NameTable.GetNameFor(location);
                var programSource = new SpecSharpSourceDocument(helper, name, location, File.ReadAllText(location));
                programSources.Add(programSource);
            }

            return assembly;
        }
开发者ID:dbremner,项目名称:specsharp,代码行数:56,代码来源:MSBuildCompiler.cs

示例2: Parse

        public static AssemblyIdentity Parse(INameTable nameTable, string formattedName)
        {
            var name = new System.Reflection.AssemblyName(formattedName);
            return new AssemblyIdentity(nameTable.GetNameFor(name.Name),
                                        name.CultureName,
                                        name.Version,
                                        name.GetPublicKeyToken(),
#if COREFX
                                        "");
#else
                                        name.CodeBase);
#endif
        }
开发者ID:jango2015,项目名称:buildtools,代码行数:13,代码来源:AssemblyIdentityHelpers.cs

示例3: Load

 private static System.Reflection.Assembly Load(string assemblyNameVal) {
     System.Reflection.AssemblyName assemblyName = new System.Reflection.AssemblyName(assemblyNameVal);
     byte[] publicKeyToken = assemblyName.GetPublicKeyToken();
     System.Reflection.Assembly asm = null;
     try {
         asm = System.Reflection.Assembly.Load(assemblyName.FullName);
     }
     catch (System.Exception ) {
         System.Reflection.AssemblyName shortName = new System.Reflection.AssemblyName(assemblyName.Name);
         if ((publicKeyToken != null)) {
             shortName.SetPublicKeyToken(publicKeyToken);
         }
         asm = System.Reflection.Assembly.Load(shortName);
     }
     return asm;
 }
开发者ID:karayakar,项目名称:MCSD_SharePoint_Applications,代码行数:16,代码来源:_Farm_Solution2.g.cs

示例4: ResolveAssemblyRef

        public MiniAssembly ResolveAssemblyRef(MetadataToken token, bool throwOnError)
        {
            System.Diagnostics.Contracts.Contract.Requires(token.Table == MDTables.Tables.AssemblyRef);
            PEFileReader peFile = this.PEFileReader;
            MDTables metaData = peFile.MetaData;

            metaData.SeekToMDToken(token);
            peFile.B.ReadUInt64();  // Skip 4 parts of the version number.
            peFile.B.ReadUInt32();  // AssemblyFlags
            byte[] publicKeyOrToken = metaData.ReadBlob(); // Public key or token
            String assemblySimpleName = metaData.ReadString(); // simple name
            String cultureName = metaData.ReadString();  // assembly culture
            if (!String.IsNullOrEmpty(cultureName))
                throw new BadImageFormatException(Res.UnexpectedlyLoadingASatellite, FullName);

            if (assemblySimpleName == "mscorlib" && (cultureName.Length == 0 || cultureName == "neutral"))
                return new MiniAssembly(typeof(Object).Assembly);

            MiniAssembly loadedAssembly = Open(assemblySimpleName, _dependencyDirs, throwOnError);

            if (loadedAssembly != null)
            {
                // Check whether the reference to the assembly matches what we actually loaded.
                // We don't respect the "throwOnError" parameter here because if someone does
                // violate this, they've either severely messed up their deployment, or they're
                // attempting a security exploit.
                System.Reflection.AssemblyName loadedAssemblyName = 
                    new System.Reflection.AssemblyName(loadedAssembly.FullName);

                if (!Utils.PublicKeyMatches(loadedAssemblyName, publicKeyOrToken))
                {
                    throw new FileLoadException(String.Format(CultureInfo.CurrentCulture, Res.AssemblyLoadRefDefMismatch, 
                        assemblySimpleName, publicKeyOrToken, loadedAssemblyName.GetPublicKeyToken()));
                }

                if (!String.IsNullOrEmpty(loadedAssemblyName.CultureInfo.Name))
                {
                    throw new FileLoadException(String.Format(CultureInfo.CurrentCulture, Res.AssemblyLoadRefDefMismatch,
                        assemblySimpleName, String.Empty, loadedAssemblyName.CultureInfo.Name));
                }
            }
            return loadedAssembly;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:43,代码来源:MiniAssembly.cs

示例5: HostEnvironment

    internal HostEnvironment()
      : base(new NameTable(), new InternFactory(), 0, null, true) {
      this.peReader = new PeReader(this);
      string/*?*/ loc = typeof(object).Assembly.Location;
      if (loc == null) loc = "";
      System.Reflection.AssemblyName coreAssemblyName = new System.Reflection.AssemblyName(typeof(object).Assembly.FullName);
      this.coreAssemblySymbolicIdentity =
        new AssemblyIdentity(this.NameTable.GetNameFor(coreAssemblyName.Name), "", coreAssemblyName.Version, coreAssemblyName.GetPublicKeyToken(), loc);
      this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(loc, this)));
      loc = typeof(Microsoft.SmallBasic.Library.ConsoleTextColor).Assembly.Location;
      if (loc == null) loc = "";
      //System.Reflection.AssemblyName runtimeName = new System.Reflection.AssemblyName(typeof(Microsoft.SmallBasic.Library.ConsoleTextColor).Assembly.FullName);
      //this.smallBasicRuntimeAssemblyIdentity =
      //  new AssemblyIdentity(this.NameTable.GetNameFor(runtimeName.Name), "", runtimeName.Version, runtimeName.GetPublicKeyToken(), loc);
      this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(loc, this)));

    }
开发者ID:mestriga,项目名称:Microsoft.CciSamples,代码行数:17,代码来源:Program.cs

示例6: HostEnvironment

 internal HostEnvironment(int pointerSizeInBits)
     : base(new NameTable(), new InternFactory(), (byte)(pointerSizeInBits / 8), null, false)
 {
     Debug.Assert(pointerSizeInBits == 32 || pointerSizeInBits == 64);
       this.peReader = new PeReader(this);
       string loc = typeof(object).Assembly.Location;
       System.Reflection.AssemblyName mscorlibName = new System.Reflection.AssemblyName(typeof(object).Assembly.FullName);
       var tempMscorlibIdentity = new AssemblyIdentity(this.NameTable.GetNameFor(mscorlibName.Name), "", mscorlibName.Version, mscorlibName.GetPublicKeyToken(), loc);
       this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(tempMscorlibIdentity.Location, this), out this.mscorlibIdentity));
       loc = typeof(Microsoft.Research.Vcc.Runtime).Assembly.Location;
       System.Reflection.AssemblyName runtimeName = new System.Reflection.AssemblyName(typeof(Microsoft.Research.Vcc.Runtime).Assembly.FullName);
       var tempVccRuntimeAssemblyIdentity = new AssemblyIdentity(this.NameTable.GetNameFor(runtimeName.Name), "", runtimeName.Version, runtimeName.GetPublicKeyToken(), loc);
       this.RegisterAsLatest(this.peReader.OpenAssembly(BinaryDocument.GetBinaryDocumentForFile(tempVccRuntimeAssemblyIdentity.Location, this), out this.vccRuntimeAssemblyIdentity));
 }
开发者ID:edgar-pek,项目名称:VCDryad,代码行数:14,代码来源:Host.cs


注:本文中的System.Reflection.AssemblyName.GetPublicKeyToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。