C_Sharp 板


LINE

※ 引述《tomex (tomex_ou)》之铭言: : 在vs.net 2003里头, : 一个a专案,若引用(refer)了某外部元件b : compile成功後会在/bin/有一个a.dll及b.dll : 若新增一个c专案,refer了a.dll,那个在c专案的/bin里 : 会自动复制了a.dll及b.dll。 : 然而c专案里某个d.class需用到b.dll的namespace : 那麽如何避免c专案去引用b.dll呢? : (因为b.dll在引用a.dll就存在了,若硬再refer一次,会破坏设定) : 大家听得懂吗? : 就是某段程式要用到b.dll里头的物件type,但专案若不引用b.dll就看不到! : 然而明明在引用a.dll时vs.net2003就会把b.dll复制到/bin下了呀, : 再重复挑一次很显然多余的! 不挑,vs.net2003就是会看不到该namespace! : 我曾想过在a.dll写一些空的类别,来继承b.dll里头的class : 但是b.dll若有上千上万的class,就有点烦了! : namespace又不能继承?! : 我最终目的,就是要让引用的动作全部在a专案就设定完成 : 其他专案只需引用a.dll专案即会自动copy相关的reference dll : 避免单独挑选... 抄自.Net Framework SDK 文件.NET Framework 工具 强式名称工具 (Sn.exe) 帮助以强式名称 (Strong Name) 建立组件。Sn.exe 提供了金钥管理、 签章产生和签章验证的选项。 全域组件快取工具 (Gacutil.exe) 可让您检视和管理全域组件快取的内容并下载快取。虽然 Shfusion.dll 提供了 类似功能,不过您可以从建置的指令码、Makefile 档案和批次档使用 Gacutil.exe。 STEP 1: To generate a key pair 1. Open the Visual Studio .NET Command Prompt. In Windows XP, this can be opened from Start, All Programs, Microsoft Visual Studio .NET, Visual Studio .NET Tools. 2. At the prompt, use the -k flag with sn.exe to specify an output file for your key pair. Key pair files usually have a .snk extension. An example follows: sn –k myKey.snk STEP 2:To sign your assemblies with a strong name In Solution Explorer, open the AssemblyInfo file for your project. [assembly: AssemblyVersion("1.0.1.1")] //版本随便 [assembly: AssemblyKeyFile("..\\..\\myKey.snk")] STEP 3: To install your assembly to the Global Assembly Cache 1. Sign your assembly with a strong name. 2. Open the Visual Studio .NET Command Prompt. In Windows XP, this can be opened from Start, All Programs, Microsoft Visual Studio .NET, Visual Studio .NET Tools. 3. Run gacutil.exe with the /i option to specify the assembly to be installed. The following code example demonstrates how to install an assembly named myAssembly.dll to the Global Assembly Cache: gacutil /i mypath\myAssembly.dll ~~~~~~~~~ 好像要写完整path, 忘了 STEP 4: Where can I find my global assembly? In XP C:\WINDOWS\assembly\ (选:详细资料) 资料夹内有全域组件名称,类型,版本,文化特性,公开金钥语汇基元 STEP 5: 其他专案也可以引用,In Solution Explorer 加入参考 ------------------------------------------------------------------------------ Step by Step Example 前提: 1. 本例子使用Visual Studio .Net 2003 2. 本例子DOS指令皆在Visual Studio .NET 2003 命令提示字元中执行 (开始→所有程式→Microsoft Visual Studio .NET 2003→Visual Studio .NET工具) 3.路径请自行调整 ------------------------------------------------------------------------------ 1. C:\>sn -k myKey.snk 2. 开启新的类别库专案ClassLibrary1 //类似版大的b.dll (1) In Class1.cs using System; namespace ClassLibrary1 { /// <summary> /// Class1 的摘要描述。 /// </summary> public class Class1 { private int temp; public Class1() { temp = 10; } public int Temp { get { return temp; } } } } (2)In AssemblyInfo.cs 请修改成下列此行 [assembly: AssemblyKeyFile("C:\\myKey.snk")] (3)请把Debug改成Release模式,然後建置此专案 3. 开启新的类别库专案ClassLibrary2 // 类似版大的a.dll (1)在方案总管中将Step2中刚建置的DLL加入参考 (2)In Class1.cs using System; namespace ClassLibrary2 { /// <summary> /// Class1 的摘要描述。 /// </summary> public class Class2 { private ClassLibrary1.Class1 c; public Class2() { c = new ClassLibrary1.Class1(); } public int SquareClass1() { return c.Temp * c.Temp; } } } (2)In AssemblyInfo.cs 请修改成下列此行 [assembly: AssemblyKeyFile("C:\\myKey.snk")] (3)请把Debug改成Release模式,然後建置此专案 (4)此时\bin\Release\中有ClassLibrary1.dll 及ClassLibrary2.dll 4. C:\...\ClassLibrary2\bin\Release>gacutil /i ClassLibrary1.dll 5. C:\...\ClassLibrary2\bin\Release>gacutil /i ClassLibrary2.dll 6. 开启新的Windows应用程式专案WindowsApplication1 // 类似版大的c专案 (1)在方案总管中加入参考→刚刚建置的ClassLibrary2.dll (2)In Form1.cs 拉一个Label跟Button到Form1上 (3)在button1上按两下 private void button1_Click(object sender, System.EventArgs e) { ClassLibrary2.Class2 c = new ClassLibrary2.Class2(); label1.Text = c.SquareClass1().ToString(); } (4)启动此专案 (5)按button,label从label1变成100 (6)在\bin\Release\中只有WindowsApplication1.exe 7.在C:\WINDOWS\assembly中可看到(请用档案总管不要用命令提示字元看) 全域组件名称 类型 版本 文化特性 公开金钥语汇 ClassLibrary1 1.0.1762.38750 8417f199c4a717ce ClassLibrary2 1.0.1762.38808 8417f199c4a717ce 8.写了这麽多,但这是你要的吗? ※ 编辑: chiifan 来自: 219.84.81.23 (10/28 23:14)







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BabyMother站内搜寻

TOP