• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Cci.AssemblyIdentity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.Cci.AssemblyIdentity的典型用法代码示例。如果您正苦于以下问题:C# AssemblyIdentity类的具体用法?C# AssemblyIdentity怎么用?C# AssemblyIdentity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AssemblyIdentity类属于Microsoft.Cci命名空间,在下文中一共展示了AssemblyIdentity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: GetLocation

    /// <summary>
    /// Returns the original location of the corresponding assembly if available, otherwise returns the location of the shadow copy.
    /// If the corresponding assembly is not in the GAC, null is returned.
    /// </summary>
    public static string/*?*/ GetLocation(AssemblyIdentity assemblyIdentity, IMetadataHost metadataHost) {
      lock (GlobalLock.LockingObject) {
#if COMPACTFX
        var gacKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"\Software\Microsoft\.NETCompactFramework\Installer\Assemblies\Global");
        foreach (var gacName in gacKey.GetValueNames()) {
          if (IdentityMatchesString(assemblyIdentity, gacName)) {
            var values = gacKey.GetValue(gacName) as string[];
            if (values == null || values.Length == 0) continue;
            return values[0];
          }
        }
        return null;
#else
        if (!GlobalAssemblyCache.FusionLoaded) {
          GlobalAssemblyCache.FusionLoaded = true;
          System.Reflection.Assembly systemAssembly = typeof(object).Assembly;
          //^ assume systemAssembly != null;
          string/*?*/ systemAssemblyLocation = systemAssembly.Location;
          //^ assume systemAssemblyLocation != null;
          string dir = Path.GetDirectoryName(systemAssemblyLocation);
          //^ assume dir != null;
          GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll"));
        }
        IAssemblyEnum assemblyEnum;
        CreateAssemblyEnum(out assemblyEnum, null, null, ASM_CACHE.GAC, 0);
        if (assemblyEnum == null) return null;
        IApplicationContext applicationContext;
        IAssemblyName currentName;
        while (assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0) {
          //^ assume currentName != null;
          AssemblyName cn = new AssemblyName(currentName);
          if (assemblyIdentity.Equals(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(cn.Name), cn.Culture, cn.Version, cn.PublicKeyToken, ""))) {
            string codeBase = cn.CodeBase;
            if (codeBase != null && codeBase.StartsWith("file://")) {
              Uri u = new Uri(codeBase, UriKind.Absolute);
              return u.LocalPath;
            }
            return cn.GetLocation();
          }
        }
        return null;
#endif
      }
    }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:48,代码来源:GlobalAssemblyCache.cs


示例3: UnifyAssembly

        public override AssemblyIdentity UnifyAssembly(AssemblyIdentity assemblyIdentity)
        {
            Dictionary<String, Byte[]> assembliesToUnify = new Dictionary<string, Byte[]>{
                {"System", new Byte[]{0xb7,0x7a,0x5c,0x56,0x19,0x34,0xe0,0x89}},
                {"System.Drawing", new Byte[]{0xb0,0x3f,0x5f,0x7f,0x11,0xd5,0x0a,0x3a}},
                {"System.Windows.Forms", new Byte[]{0xb7,0x7a,0x5c,0x56,0x19,0x34,0xe0,0x89}},
            };
            Byte[] publicKeyToken;

            if (assembliesToUnify.TryGetValue(assemblyIdentity.Name.Value, out publicKeyToken) && IteratorHelper.EnumerablesAreEqual<Byte>(publicKeyToken, assemblyIdentity.PublicKeyToken))
            {
                assemblyIdentity = new AssemblyIdentity(
                    assemblyIdentity.Name,
                    assemblyIdentity.Culture,
                    CoreAssemblySymbolicIdentity.Version, // roll forward to the version of mscorlib
                    assemblyIdentity.PublicKeyToken,
                    assemblyIdentity.Location);
            }

            return base.UnifyAssembly(assemblyIdentity);
        }
开发者ID:dsgouda,项目名称:buildtools,代码行数:21,代码来源:HostEnvironment.cs


示例4: ResolvingAssemblyReference

        // TODO: Something similar for ResolvingModuleReference?
        public override void ResolvingAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly)
        {
            List<String> paths = new List<string>();
            paths.Add(Path.GetDirectoryName(referringUnit.Location));
            paths.AddRange(_assemblyPaths);

            foreach (String assemblyFile in _referencedAssemblies)
            {
                if (Path.GetFileNameWithoutExtension(assemblyFile).Equals(referencedAssembly.Name.Value, StringComparison.OrdinalIgnoreCase))
                {
                    if (TryLoadAssembly(referringUnit, referencedAssembly, assemblyFile))
                    {
                        return;
                    }
                }
            }

            foreach (String path in paths)
            {
                String file = Path.Combine(path, referencedAssembly.Name.Value + ".dll");
                if (TryLoadAssembly(referringUnit, referencedAssembly, file))
                {
                    return;
                }

                file = Path.Combine(path, referencedAssembly.Name.Value + ".exe");
                if (TryLoadAssembly(referringUnit, referencedAssembly, file))
                {
                    return;
                }

                file = Path.Combine(path, referencedAssembly.Name.Value + ".winmd");
                if (TryLoadAssembly(referringUnit, referencedAssembly, file))
                {
                    return;
                }
            }

            throw new Exception(String.Format("Cannot find: {0}. Check assembly dependency paths.", referencedAssembly.ToString()));
        }
开发者ID:dsgouda,项目名称:buildtools,代码行数:41,代码来源:HostEnvironment.cs


示例5: Map

    public IAssemblyReference Map(R.IAssemblySymbol assembly) {
      Contract.Requires(assembly != null);
      Contract.Ensures(Contract.Result<IAssemblyReference>() != null);

      IAssemblyReference cciAssembly = null;
      if (!assemblySymbolCache.TryGetValue(assembly, out cciAssembly)) {
        var an = assembly.Identity;
        IEnumerable<byte> pkt = an.PublicKeyToken.AsEnumerable();
        if (pkt == null)
          pkt = new byte[0];
        var identity = new Microsoft.Cci.AssemblyIdentity(
          this.nameTable.GetNameFor(an.Name),
          an.CultureName == null ? "" : an.CultureName, // REVIEW: This can't be right
          an.Version,
          pkt,
          an.Location == null ? "unknown://location" : an.Location
          );
        cciAssembly = new Microsoft.Cci.Immutable.AssemblyReference(this.host, identity);
        assemblySymbolCache[assembly] = cciAssembly;
      }
      Contract.Assume(cciAssembly != null);
      return cciAssembly;
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:23,代码来源:ReferenceMapper.cs


示例6: ResolvingAssemblyReference

 /// <summary>
 /// This method is called when the assembly reference is being resolved and its not already loaded by the Read/Write host.
 /// </summary>
 /// <param name="referringUnit">The unit that is referencing the assembly.</param>
 /// <param name="referencedAssembly">Assembly identity for the assembly being referenced.</param>
 public virtual void ResolvingAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly) {
   if (!string.IsNullOrEmpty(referencedAssembly.Location)) {
     this.LoadUnit(referencedAssembly);
   } else {
     AssemblyIdentity ai = this.ProbeAssemblyReference(referringUnit, referencedAssembly);
     if (ai != null && !String.IsNullOrEmpty(ai.Location)) {
       this.LoadUnit(ai);
     }
   }
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:15,代码来源:Core.cs


示例7: AssemblyStore

 internal AssemblyStore(
   AssemblyIdentity assemblyIdentity,
   uint internedId,
   uint rootNamespaceInternedId
 ) {
   this.AssemblyIdentity = assemblyIdentity;
   this.InternedIdWithCount = internedId;
   this.RootNamespaceInternedId = rootNamespaceInternedId;
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:9,代码来源:Core.cs


示例8: ModuleIdentity

 /// <summary>
 /// Allocates an object that identifies a .NET module that forms part of an assembly.
 /// Can be just the name of the module along with the identifier of the assembly, but can also include the location where the module is stored.
 /// </summary>
 /// <param name="name">The name of the identified module.</param>
 /// <param name="location">The location where the module is stored. Can be the empty string if the location is not known. The location need not be a file path.</param>
 /// <param name="containingAssembly">The identifier of the assembly to which the identified module belongs. May be null.</param>
 public ModuleIdentity(IName name, string location, AssemblyIdentity/*?*/ containingAssembly)
   : base(name, location) {
   Contract.Requires(name != null);
   Contract.Requires(location != null);
   this.containingAssembly = containingAssembly;
 }
开发者ID:RUB-SysSec,项目名称:Probfuscator,代码行数:13,代码来源:Units.cs


示例9: UnifyAssembly

 public AssemblyIdentity UnifyAssembly(AssemblyIdentity assemblyIdentity) {
   throw new NotImplementedException();
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:3,代码来源:Core.cs


示例10: LoadAssembly

 /// <summary>
 /// The assembly that matches the given reference, or a dummy assembly if no matching assembly can be found.
 /// </summary>
 public virtual IAssembly LoadAssembly(AssemblyIdentity assemblyIdentity) {
   IUnit/*?*/ unit;
   lock (GlobalLock.LockingObject) {
     this.unitCache.TryGetValue(assemblyIdentity, out unit);
   }
   IAssembly/*?*/ result;
   if (unit != null)
     result = unit as IAssembly;
   else {
     if (string.IsNullOrEmpty(assemblyIdentity.Location) || string.Equals(assemblyIdentity.Location, "unknown://location", StringComparison.OrdinalIgnoreCase)) {
       result = Dummy.Assembly;
       lock (GlobalLock.LockingObject) {
         this.unitCache.Add(assemblyIdentity, result);
       }
     } else {
       unit = this.LoadUnitFrom(assemblyIdentity.Location);
       result = unit as IAssembly;
       if (result != null && this.UnifyAssembly(result).Equals(assemblyIdentity))
         lock (GlobalLock.LockingObject) {
           this.unitCache[assemblyIdentity] = result;
           this.coreIdentities.Add(result.CoreAssemblySymbolicIdentity);
         }
     }
   }
   if (result == null) result = Dummy.Assembly;
   return result;
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:30,代码来源:Core.cs


示例11: ProbeAssemblyReference

    public virtual AssemblyIdentity ProbeAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly) {
      AssemblyIdentity result;

      if (!string.IsNullOrEmpty(referringUnit.Location)) {
        // probe for in the same directory as the referring unit
        var referringDir = Path.GetDirectoryName(Path.GetFullPath(referringUnit.Location));
        result = this.Probe(referringDir, referencedAssembly);
        if (result != null) return result;
      }

      // Probe in the libPaths directories
      foreach (string libPath in this.LibPaths) {
        Contract.Assume(libPath != null);
        result = this.Probe(libPath, referencedAssembly);
        if (result != null) return result;
      }

      // Check GAC
#if !COMPACTFX
      if (this.SearchInGAC) {
        string/*?*/ gacLocation = GlobalAssemblyCache.GetLocation(referencedAssembly, this);
        if (gacLocation != null) {
          return new AssemblyIdentity(referencedAssembly, gacLocation);
        }
      }
#endif

      // Check platform location
      var platformDir = Path.GetDirectoryName(Path.GetFullPath(GetLocalPath(typeof(object).Assembly.GetName())))??"";
      var coreVersion = this.CoreAssemblySymbolicIdentity.Version;
      if (coreVersion.Major == 1) {
        if (coreVersion.Minor == 0)
          platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v1.0.3705");
        else if (coreVersion.Minor == 1)
          platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v1.1.4322");
      } else if (coreVersion.Major == 2) {
        platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v3.5");
        result = this.Probe(platformDir, referencedAssembly);
        if (result != null) return result;
        platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v3.0");
        result = this.Probe(platformDir, referencedAssembly);
        if (result != null) return result;
        platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v2.0.50727");
      } else if (coreVersion.Major == 4) {
        platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v4.0.30319");
      }

      result = this.Probe(platformDir, referencedAssembly);
      if (result != null) return result;

      // Give up
      return new AssemblyIdentity(referencedAssembly, "unknown://location");
    }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:53,代码来源:Core.cs


示例12: Probe

 /// <summary>
 /// Looks in the specified <paramref name="probeDir"/> to see if a file
 /// exists, first with the extension "dll" and then with the extension "exe".
 /// Returns null if not found, otherwise constructs a new AssemblyIdentity
 /// </summary>
 private AssemblyIdentity/*?*/ Probe(string probeDir, AssemblyIdentity referencedAssembly) {
   string path = Path.Combine(probeDir, referencedAssembly.Name.Value + ".dll");
   if (File.Exists(path)) return new AssemblyIdentity(referencedAssembly, path);
   path = Path.Combine(probeDir, referencedAssembly.Name.Value + ".exe");
   if (File.Exists(path)) return new AssemblyIdentity(referencedAssembly, path);
   return null;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:12,代码来源:Core.cs


示例13: lock

    // Interning of module and assembly
    // enables fast comparision of the nominal types. The interned module id takes into account the unification policy applied by the host.
    // For example if mscorlib 1.0 and mscorlib 2.0 is unified by the host both of them will have same intered id, otherwise not.
    // Interned id is 32 bit integer. it is split into 22 bit part and 10 bit part. First part represents the assembly and other part represents module.
    // Simple module which are not part of any assembly is represented by 0 in assembly part and number in module part.
    // Main module of the assembly is represented with something in the assembly part and 0 in the module part.
    // Other modules of the multimodule assembly are represented with assembly part being containing assembly and module part distinct for each module.
    // Note that this places limit on number of modules that can be loaded to be 2^20 and number of modules loaded at 2^12

    uint IInternFactory.GetAssemblyInternedKey(AssemblyIdentity assemblyIdentity) {
      lock (GlobalLock.LockingObject) {
        AssemblyStore assemblyStore = this.GetAssemblyStore(assemblyIdentity);
        return assemblyStore.InternedId;
      }
    }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:15,代码来源:Core.cs


示例14: LoadAssembly

 /// <summary>
 /// The assembly that matches the given reference, or a dummy assembly if no matching assembly can be found.
 /// </summary>
 public virtual IAssembly LoadAssembly(AssemblyIdentity assemblyIdentity) {
   IUnit/*?*/ unit;
   lock (GlobalLock.LockingObject) {
     this.unitCache.TryGetValue(assemblyIdentity, out unit);
   }
   if (unit == null) {
     if (assemblyIdentity.Location == "" || assemblyIdentity.Location == "unknown://location") {
       unit = Dummy.Assembly;
       this.unitCache.Add(assemblyIdentity, unit);
     } else {
       unit = this.LoadUnitFrom(assemblyIdentity.Location);
       var assembly = unit as IAssembly;
       if (assembly != null && this.UnifyAssembly(assembly.AssemblyIdentity).Equals(assemblyIdentity))
         this.unitCache[assemblyIdentity] = unit;
     }
   }
   IAssembly/*?*/ result = unit as IAssembly;
   if (result == null) result = Dummy.Assembly;
   return result;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:23,代码来源:Core.cs


示例15: ProbeAssemblyReference

 /// <summary>
 /// Given the identity of a referenced assembly (but not its location), apply host specific policies for finding the location
 /// of the referenced assembly.
 /// </summary>
 /// <param name="referringUnit">The unit that is referencing the assembly. It will have been loaded from somewhere and thus
 /// has a known location, which will typically be probed for the referenced assembly.</param>
 /// <param name="referencedAssembly">The assembly being referenced. This will not have a location since there is no point in probing
 /// for the location of an assembly when you already know its location.</param>
 /// <returns>
 /// An assembly identity that matches the given referenced assembly identity, but which includes a location.
 /// If the probe failed to find the location of the referenced assembly, the location will be "unknown://location".
 /// </returns>
 /// <remarks>
 /// Default implementation of ProbeAssemblyReference. Override this method to change its behavior.
 /// </remarks>
 //^ [Pure]
 public virtual AssemblyIdentity ProbeAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly) {
   return new AssemblyIdentity(referencedAssembly, "unknown://location");
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:19,代码来源:Core.cs


示例16: GetCoreAssemblySymbolicIdentity

 /// <summary>
 /// Returns the identity of the assembly containing the core system types such as System.Object, by asking
 /// each of the loaded units for its opinion on the matter and returning the opinion with the highest version number.
 /// If none of the loaded units have an opinion, the identity of the runtime executing the compiler itself is returned.
 /// </summary>
 protected virtual AssemblyIdentity GetCoreAssemblySymbolicIdentity() {
   var coreAssemblyName = typeof(object).Assembly.GetName();
   string loc = GetLocalPath(coreAssemblyName);
   if (this.unitCache.Count > 0) {
     AssemblyIdentity/*?*/ result = null;
     foreach (IUnit unit in this.unitCache.Values) {
       AssemblyIdentity coreId = unit.CoreAssemblySymbolicIdentity;
       if (coreId.Name.Value.Length == 0) continue;
       if (result == null || result.Version < coreId.Version) result = coreId;
     }
     if (result != null) {
       //The loaded assemblies have an opinion on the identity of the core assembly. By default, we are going to respect that opinion.
       if (result.Location.Length == 0) {
         //However, they do not know where to find it. (This will only be non empty if one of the loaded assemblies itself is the core assembly.)
         if (loc.Length > 0) {
           //We don't know where to find the core assembly that the loaded assemblies want, but we do know where to find the core assembly
           //that we are running on. Perhaps it is the same assembly as the one we've identified. In that case we know where it can be found.
           var myCore = new AssemblyIdentity(this.NameTable.GetNameFor(coreAssemblyName.Name), "", coreAssemblyName.Version, coreAssemblyName.GetPublicKeyToken(), loc);
           if (myCore.Equals(result)) return myCore; //myCore is the same as result, but also has a non null location.
         }
         //TODO: if the core assembly being referenced is not the same as the one running the host, probe in the standard places to find its location.
         //put this probing logic in a separate, overridable method and use it in LoadAssembly and LoadModule.
         //Hook it up with the GAC.
       }
       return result;
     }
   }
   //If we get here, none of the assemblies in the unit cache has an opinion on the identity of the core assembly.
   //Usually this will be because this method was called before any assemblies have been loaded.
   //In this case, we have little option but to choose the identity of the core assembly of the platform we are running on.
   return new AssemblyIdentity(this.NameTable.GetNameFor(coreAssemblyName.Name), "", coreAssemblyName.Version, coreAssemblyName.GetPublicKeyToken(), loc);
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:37,代码来源:Core.cs


示例17: GetAssemblyStore

 AssemblyStore GetAssemblyStore(AssemblyIdentity assemblyIdentity) {
   IName assemblyName = assemblyIdentity.Name;
   foreach (AssemblyStore aStore in this.AssemblyHashtable.GetValuesFor((uint)assemblyName.UniqueKey)) {
     if (assemblyIdentity.Equals(aStore.AssemblyIdentity)) {
       return aStore;
     }
   }
   uint value = this.CurrentAssemblyInternValue;
   this.CurrentAssemblyInternValue += 0x00001000;
   AssemblyStore aStore1 = new AssemblyStore(assemblyIdentity, value, this.CurrentNamespaceInternValue++);
   this.AssemblyHashtable.Add((uint)assemblyName.UniqueKey, aStore1);
   return aStore1;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:13,代码来源:Core.cs


示例18: GetAssemblyIdentity

    public static AssemblyIdentity GetAssemblyIdentity(EnvDTE.Project project, MetadataReaderHost host) {
      Contract.Requires(project != null);
      Contract.Requires(host != null);

      if (!ProjectIsAvailable(project))
        return null;

      VSServiceProvider.Current.Logger.WriteToLog("Getting the assembly identity for project: " + project.Name);

      string location_RootDir = null;
      string location_RelativeAssemblyDir = null;
      string location_FileName = null;
      string location = null;
      IName iName = null;
      string culture = "";//TODO: Find out where to get culture information.
      Version version = new Version();
      AssemblyIdentity result = null;
      try {
        var activePropCount = 
          project.ConfigurationManager != null && project.ConfigurationManager.ActiveConfiguration != null && project.ConfigurationManager.ActiveConfiguration.Properties != null ?
          project.ConfigurationManager.ActiveConfiguration.Properties.Count : 0;
        for (int i = activePropCount; 1 <= i; i--) {
          var prop = project.ConfigurationManager.ActiveConfiguration.Properties.Item(i);
          if (prop == null) continue;
          if (prop.Name == "OutputPath") {
            location_RelativeAssemblyDir = prop.Value as string;
            break;
          }
        }
        var propCount = project.Properties != null ? project.Properties.Count : 0;
        for (int i = propCount; 1 <= i; i--) {
          var prop = project.Properties.Item(i);
          if (prop == null) continue;
          switch (prop.Name) {
            case "AssemblyName":
              iName = host.NameTable.GetNameFor(prop.Value as string);
              break;
            case "AssemblyVersion":
              var stringVersion = prop.Value as string;
              if (!Version.TryParse(stringVersion, out version))
              {
                  version = new Version();
              }
              Contract.Assume(version != null);
              break;
            case "FullPath":
              location_RootDir = prop.Value as string;
              break;
            case "OutputFileName":
              location_FileName = prop.Value as string;
              break;
            default:
              break;
          }
        }
      } catch (COMException comEx) {
        VSServiceProvider.Current.Logger.WriteToLog("COM Exception while trying to access project's properties.");
        VSServiceProvider.Current.Logger.WriteToLog("Message: " + comEx.Message);
        if (comEx.Message.Contains(COMExceptionMessage_ProjectUnavailable)) {
          VSServiceProvider.Current.Logger.WriteToLog("Returning null.");
          return null;
        } else if (((uint)comEx.ErrorCode) == 0x80020009) {
          VSServiceProvider.Current.Logger.WriteToLog("Returning null.");
          return null;
        } else {
          throw comEx;
        }
      }

      //Check if we got enough information from VS to build the location
      if (location_FileName == null
        || location_RelativeAssemblyDir == null
        || location_RootDir == null) {
        VSServiceProvider.Current.Logger.WriteToLog("Couldn't find path to the project's output assembly.");
        return null;
      }

      //Set the location of the output assembly
      location = Path.Combine(location_RootDir, location_RelativeAssemblyDir, location_FileName);

      //Check that the output assembly exists
      if (!File.Exists(location)) {
        VSServiceProvider.Current.Logger.WriteToLog("Project output assembly could not be found at the location given by Visual Studio: " + location);
      }

      //Check our other information from VS
      if (iName == null
        || string.IsNullOrEmpty(location)) {
        VSServiceProvider.Current.Logger.WriteToLog("Couldn't gather sufficient information from the project to construct an assembly identity.");
        return null;
      }

      //Success
      Contract.Assert(version != null);
      Contract.Assert(culture != null);
      result = new AssemblyIdentity(iName, culture, version, Enumerable<byte>.Empty, location);
      host.AddLibPath(Path.Combine(location_RootDir, location_RelativeAssemblyDir, "CodeContracts"));
      host.AddLibPath(Path.Combine(location_RootDir, location_RelativeAssemblyDir, @"..\Debug\CodeContracts"));

      return result;
//.........这里部分代码省略.........
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:101,代码来源:ProjectTracker.cs


示例19: GetAssemblyStore

    AssemblyStore GetAssemblyStore(AssemblyIdentity assemblyIdentity) {
      Contract.Requires(assemblyIdentity != null);
      Contract.Ensures(Contract.Result<AssemblyStore>() != null);

      IName assemblyName = assemblyIdentity.Name;
      foreach (AssemblyStore aStore in this.AssemblyHashtable.GetValuesFor((uint)assemblyName.UniqueKey)) {
        if (assemblyIdentity.Equals(aStore.AssemblyIdentity)) return aStore;
      }
      uint value = this.CurrentAssemblyInternValue;
      this.CurrentAssemblyInternValue += 0x00001000;
      AssemblyStore aStore1 = new AssemblyStore(assemblyIdentity, value, this.CurrentNamespaceInternValue++);
      this.AssemblyHashtable.Add((uint)assemblyName.UniqueKey, aStore1);
      return aStore1;
    }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:14,代码来源:Core.cs


示例20: GetCoreAssemblySymbolicIdentity

 /// <summary>
 /// Returns the identity of the assembly containing the core system types such as System.Object, by asking
 /// each of the loaded units for its opinion on the matter and returning the opinion with the highest version number.
 /// If none of the loaded units have an opinion, the identity of the runtime executing the compiler itself is returned.
 /// </summary>
 protected virtual AssemblyIdentity GetCoreAssemblySymbolicIdentity() {
   Contract.Ensures(Contract.Result<AssemblyIdentity>() != null);
   AssemblyIdentity/*?*/ result = null;
   IUnit referringUnit = Dummy.Unit;
   if (this.unitCache.Count > 0) {
     var dummyVersion = new Version(255, 255, 255, 255);
     lock (GlobalLock.LockingObject) {
       foreach (IUnit unit in this.unitCache.Values) {
         Contract.Assume(unit != null);
         AssemblyIdentity coreId = unit.CoreAssemblySymbolicIdentity;
         if (coreId.Name.Value.Length == 0) continue;
         this.coreIdentities.Add(coreId);
         if (result == null || result.Version == dummyVersion ||
            (result.Version < coreId.Version && coreId.Version != dummyVersion) ||
             result.Version == coreId.Version && unit.UnitIdentity.Equals(coreId)) {
           result = coreId;
           referringUnit = unit;
         }
       }
     }
   }
   if (result == null) {
     //If we get here, none of the assemblies in the unit cache has an opinion on the identity of the core assembly.
     //Usually this will be because this method was called before any assemblies have been loaded.
     //In this case, we have little option but to choose the identity of the core assembly of the platform we are running on.
     var coreAssemblyName = typeof(object).Assembly.GetName();
     var version = coreAssemblyName.Version;
     Contract.Assume(version != null);
     var publicKeyToken = coreAssemblyName.GetPublicKeyToken();
     Contract.Assume(publicKeyToken != null);
     result = new AssemblyIdentity(this.NameTable.GetNameFor(coreAssemblyName.Name), "", version, publicKeyToken, "");
   }
   if (result.Location.Length == 0) {
     //We either found a plausible identity by polling the assemblies in the unit cache, or we used the identity of our own core assembly.
     //However, we defer to ProbeAssemblyReference to find an actual location for the assembly.
     //(Note that if result.Location.Length > 0, then the core assembly has already been loaded and we thus know the location and don't have to probe.)
     this.coreAssemblySymbolicIdentity = result; //in case ProbeAssemblyReference wants to know the core identity
     result = this.ProbeAssemblyReference(referringUnit, result);
   }
   return this.coreAssemblySymbolicIdentity = result;
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:46,代码来源:Core.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cci.BlobBuilder类代码示例发布时间:2022-05-26
下一篇:
C# Syntax.Name类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap