• 程序集强命名与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);
         }
    }

  • 相关阅读:
    Android Studio在android Emulator中运行的项目黑屏
    【.NET开发福音】使用Visual Studio将JSON格式数据自动转化为对应的类
    ASP.NET Core获取请求完整的Url
    解决Cannot find module '@angular/compiler-cli'
    必备三件套:xshell6+xftp6+navicat
    关于bertTokenizer
    关于warm up(transformers.get_linear_schedule_with_warmup)
    一文弄懂pytorch搭建网络流程+多分类评价指标
    python实现多分类评价指标
    如何使用flask将模型部署为服务
  • 原文地址:https://www.cnblogs.com/zhuor/p/1054423.html
Copyright © 2020-2023  润新知