zoukankan      html  css  js  c++  java
  • 程序集强命名与GAC

    1、新建项目Other,在其中创建如下类:
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Other.全局应用缓存
    {
        public class GAC
         {
             public string CallGAC()
             {
                 return "GAC end";
             }
         }
    }

    2、强命名程序集:
    在项目Other上,击右键,签名,为程序集签名,新建或者浏览密钥文件
    也可以在SDK 命令提示中创建密钥,sn -k D:\CompanyA.keys,在此引用。vs2003:[assembly: AssemblyKeyFile

    ("D:\CompanyA.keys")]
    编译,此时Other.dll已经是强命名程序集

    3、共享程序集Other.dll:
    将程序集(如:E:\个人文件夹\Code\企业级应用解决方案\Other\bin\Debug\Other.dll)直接拖入全局应用程序缓存(如:

    C:\WINDOWS\assembly)
    也可是在SDK 命令提示中完成,如:GACUtil /i E:\个人文件夹\Code\企业级应用解决方案\Other\bin\Debug\Other.dll

    4、调用共享程序集Other.dll
    新建Web项目MyWebProject,添加引用刚才创建的程序集Other.dll,比如:E:\个人文件夹\Code\企业级应用解决方案

    \Other\bin\Debug\Other.dll,此时MyWebProject的web.config中有了:


       <compilation debug="true">
        <assemblies>
         <add assembly="Other, Version=1.0.0.0, Culture=neutral,

    PublicKeyToken=43FC64574884C304"/></assemblies></compilation></system.web>
    调用代码如下:

    public partial class _Default : System.Web.UI.Page
    {
         protected void Page_Load(object sender, EventArgs e)
         {

         }
         protected void Button1_Click(object sender, EventArgs e)
         {
             //使用反射,不需要引用
             System.Reflection.Assembly assembly = System.Reflection.Assembly.Load("Other, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43FC64574884C304");
             this.Response.Write("利用反射,从GAC中载入程序集" + assembly.GlobalAssemblyCache);

         }
         protected void Button2_Click(object sender, EventArgs e)
         {
             //必须引用,网站MyWebProject部署之后,可以删除调E:\个人文件夹\Code\企业级应用解决方案

    \Other\bin\Debug\Other.dll
             Other.全局应用缓存.GAC gac = new Other.全局应用缓存.GAC();
             string result = gac.CallGAC();
             this.Response.Write(result);
         }
    }

  • 相关阅读:
    文件读取
    命名实体识别训练集汇总(一直更新)
    基于PyTorch的Seq2Seq翻译模型详细注释介绍(一)
    python if elif else 区别
    乱码
    dataframe添加元素指定为列表,不同for循环命名空间下的变量重复问题
    tensorflow兼容处理 tensorflow.compat.v1
    Kerberos
    Hadoop集群datanode磁盘不均衡的解决方案
    Saltstack
  • 原文地址:https://www.cnblogs.com/zhuor/p/1054423.html
Copyright © 2011-2022 走看看