日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

.NET框架程序设计--Globally Deployment Assembly全局部署程序集

發布時間:2024/1/17 asp.net 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .NET框架程序设计--Globally Deployment Assembly全局部署程序集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Globally Deployment Assembly全局部署程序集

(一)StrongName Assembly

Strongly Named Assembly是CLR唯一標識程序集的機制,包含4個特性:
·文件名(沒有擴展名)
·版本號
·語言文化
·公有密鑰標記

例如:MyTypes,Version=1.0.123.0,Culture=neutral,PublicKeyToken=1234567890123456

利用?SN.exe 產生一個公鑰/私鑰對

SN -k mycompany.keys

查看公鑰

sn -p mycompany.keys mycompany.publickey
sn -tp mycompany.publickey

Microsoft (R) .NET Framework 強名稱實用工具版本 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

公鑰為
0024000004800000940000000602000000240000525341310004000001000100830304ce5787ef
d2355d71fa73739ea27581329409f9b2d4aaa38409a0aba5b77bfa34ffe425180b86ba432a4f21
52f9f6c2aceb005d57208f7b3d48bd569110e91d7cdbdf534f20ed822650311c69ddda11fb721e
128de231a6a0661aba1eb3e306acf2dc0777fc266612c4d7491118657cc741d99090a95bdfd969
0b885ac8

公鑰標記為 91e5e7845907a9e6



創建StrongName Assembly(using System.Relfection):

[assembly:AssemblyKeyFile("mycompany.keys")]


StrongName Assembly的元數據信息:

Assembly
-------------------------------------------------------
?Token: 0x20000001
?Name : Hello
?Public Key??? : 00 24 00 00 04 80 00 00? 94 00 00 00 06 02 00 00? 00 24 00 00 52 53 41 31
????????????????????? : 00 04 00 00 01 00 01 00? 83 03 04 ce 57 87 ef d2? 35 5d 71 fa 73 73 9e a2
????????????????????? : 75 81 32 94 09 f9 b2 d4? aa a3 84 09 a0 ab a5 b7? 7b fa 34 ff e4 25 18 0b
????????????????????? : 86 ba 43 2a 4f 21 52 f9? f6 c2 ac eb 00 5d 57 20? 8f 7b 3d 48 bd 56 91 10
????????????????????? : e9 1d 7c db df 53 4f 20? ed 82 26 50 31 1c 69 dd? da 11 fb 72 1e 12 8d e2
????????????????????? : 31 a6 a0 66 1a ba 1e b3? e3 06 ac f2 dc 07 77 fc? 26 66 12 c4 d7 49 11 18
????????????????????? : 65 7c c7 41 d9 90 90 a9? 5b df d9 69 0b 88 5a c8
?Hash Algorithm : 0x00008004
?Major Version: 0x00000000
?Minor Version: 0x00000000
?Build Number: 0x00000000
?Revision Number: 0x00000000
?Locale: <null>
?Flags : [SideBySideCompatible] [PublicKey]? (00000001)

AssemblyRef #1
-------------------------------------------------------
?Token: 0x23000001
?Public Key or Token: b7 7a 5c 56 19 34 e0 89
?Name: mscorlib
?Major Version: 0x00000001
?Minor Version: 0x00000000
?Build Number: 0x00001388
?Revision Number: 0x00000000
?Locale: <null>
?HashValue Blob:
?Flags: [none] (00000000)



(二)GAC(Global Assembly Cache)


c:\windows\Assembly\GAC



使用工具GACUtil.exe來實現安裝卸載:

安裝一個StrongNameAssembly:
gacutil.exe /i myassembly.dll

卸載一個StrongNameAssembly:
gacutil.exe /u myassembly.dll

在DOS窗口下查看細節:





(三)引用StrongNameAssembly

我們發現安裝DotNetFramwork的機器會有兩份程序集文件,一份是在C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\zh-CHS中,另一份則是在GAC中。

目的是方便應用程序的引用和加載.

引用是指我們在編譯程序的時候,如果需要引用別的程序集,則編譯器會按照這樣的目錄查找:
(1)使用編譯器的/reference指定的文件的完全路徑,如果只是程序集名稱,則繼續尋找
(2)當前工作目錄
(3)CLR所在目錄(C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\zh-CHS)
(4)使用編譯器的/lib指定的目錄
(5)LIB環境變量指定的目錄


加載是指應用程序運行的時候加載需要的程序集的路徑(加載順序在前面已經提到)


利用響應文件(.rsp)來設置編譯器的命令開關:

例如,創建一個myproject.rsp文件:
/out:myproject.exe
/target:winexe
編譯的時候使用這個文件
csc @myproject.rsp file1.cs file2.cs
那么就等于我們不用這個響應文件的命令行:
csc /out:myproject.exe /target:winexe file1.cs file2.cs

在C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322里面有個csc.rsp文件

# This file contains command-line options that the C#
# command line compiler (CSC) will process as part
# of every compilation, unless the "/noconfig" option
# is specified.

# Reference the common Framework libraries
/r:Accessibility.dll
/r:Microsoft.Vsa.dll
/r:System.Configuration.Install.dll
/r:System.Data.dll
/r:System.Design.dll
/r:System.DirectoryServices.dll
/r:System.dll
/r:System.Drawing.Design.dll
/r:System.Drawing.dll
/r:System.EnterpriseServices.dll
/r:System.Management.dll
/r:System.Messaging.dll
/r:System.Runtime.Remoting.dll
/r:System.Runtime.Serialization.Formatters.Soap.dll
/r:System.Security.dll
/r:System.ServiceProcess.dll
/r:System.Web.dll
/r:System.Web.Mobile.dll
/r:System.Web.RegularExpressions.dll
/r:System.Web.Services.dll
/r:System.Windows.Forms.Dll
/r:System.XML.dll



(四)StrongNameAssembly的防篡改特性

在安裝StrongNameAssembly到GAC的時候,系統將會自動驗證程序集是否被篡改,在從GAC加載的時候又一次以不同的方式驗證,如果從別的非GAC目錄加載,也會對程序集進行嚴密驗證。

(五)延遲簽名

為了防止私有密鑰的泄漏,我們可以使用延遲簽名技術(Delayed Singning).

(1)取得公有密鑰的文件,并將下面兩個特性加入到源代碼:
[assembly:AssemlyKeyFile("MyCompanyPublicKey.keys")]
[assembly:AssemlyDelaySign(true)]
(2)生成Assembly的時候,執行下面的命令可以將Assembly安裝到GAC中(一次操作即可)
SN.exe -Vr MyAssembly.dll
(3)打包部署應用程序時,取得公有/私有密鑰對,執行命令:
SN.exe -R MyAssembly.dll MyCompanyKey.Keys
(4)執行下面的命令,恢復驗證過程進行測試:
SN.exe -Vu MyAssembly.dll

轉載于:https://www.cnblogs.com/caca/archive/2004/10/25/56346.html

總結

以上是生活随笔為你收集整理的.NET框架程序设计--Globally Deployment Assembly全局部署程序集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。