YOMEDIA
![](images/graphics/blank.gif)
ADSENSE
Lesson Assemblies
48
lượt xem 1
download
lượt xem 1
download
![](https://tailieu.vn/static/b2013az/templates/version1/default/images/down16x21.png)
Objectives of the lesson Assemblies is Introduce assemblies (concept, creation, naming); Discuss deployment (main.exe, dependent assemblies). It includes Assembly contents; Type access; Member access; Single file assembly; Assembly creation and something else.
AMBIENT/
Chủ đề:
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Lesson Assemblies
- Assemblies
- Objectives • Introduce assemblies – concept – creation – naming • Discuss deployment – main .exe – dependent assemblies 2
- Assembly • An assembly is a logical group of types – unit of deployment, versioning, and security in the CLR Invest assembly of Stock financial types Bond Advisor 3
- Assembly contents • Assembly contains several parts – IL – description of contained types in the metadata – description of assembly in the manifest IL code for Invest, Stock, Bond, Advisor classes metadata description of Invest, Stock, Bond, Advisor classes manifest .ver 1.2.3.4 .publickey ... 4
- Type access • Two access levels available for types – internal allows access only within same assembly (default) – public allows access from all assemblies available only internal class Advisor in assembly { ... } available in all public class Stock assemblies { ... } 5
- Member access • Can make type member internal – allows access only within same assembly public class Stock { available only internal string name; in assembly ... } 6
- Single file assembly • Assembly can be single dll or exe file – simple to create – simple to deploy – most common case Finance.dll single file Invest assembly Stock Bond Advisor 7
- Assembly creation • Compiler outputs assembly when target type is: – exe – winexe – library Invest.cs Stock.cs compiler Finance.dll Bond.cs Advisor.cs source files csc /target:library assembly /out:Finance.dll Invest.cs Stock.cs Bond.cs Advisor.cs 8
- Module • Can create module with compiler /target:module switch – does not create assembly – typically has .netmodule extension Stock.cs compiler Assets.netmodule Bond.cs source files csc /target:module module /out:Assets.netmodule Stock.cs Bond.cs 9
- Multi-file assembly • Can create multi-file assembly – use /addmodule compiler switch to add module to assembly – can also use more powerful assembly linker al.exe Invest.cs Assets.netmodule compiler Advisor.cs Finance.dll additional csc /target:library two files, source files /out:Finance.dll one assembly /addmodule:Assets.netmodule Invest.cs Advisor.cs 10
- Assembly identity • Assembly identified by four attributes – name – culture – version – public key token 11
- Name • Assembly name based on name of file containing manifest – set automatically when assembly created compiler Finance.dll csc /target:library assembly name /out:Finance.dll is Finance ... 12
- Culture • Assembly can specify optional target culture – typical to have separate assembly for each supported culture – assembly will be culture neutral if culture not specified • Culture typically specified using AssemblyCulture attribute – in System.Reflection namespace [assembly: AssemblyCulture("fr-CA")] French-Canada 13
- Version • Assembly can be given a four part version number – major version – minor version – build number – revision • Version typically specified using AssemblyVersion attribute – in System.Reflection namespace [assembly: AssemblyVersion("1.2.3.4")] major.minor.build.revision 14
- Public key token • Public/private key pair used to give assembly a strong name – used in deployment to provide unique identity – hash of public key called token used since public key is long • Procedure: – generate public/private key pair with strong name tool sn.exe – apply to assembly with AssemblyKeyFile attribute – attribute is in System.Reflection namespace generate keys, sn -k Lib.snk specify output file apply keys to [assembly: AssemblyKeyFile("Lib.snk")] assembly 15
- Dependent assemblies • Typical for application to consist of multiple assemblies – main .exe and supporting .dlls App.exe Finance.dll Invest Stock Main Bond Advisor main .exe supporting .dll 16
- Compile time assembly reference • Can use type defined in other assembly – must compile with option /r[eference]: • Compiler searches for referenced assemblies – current directory – CLR system directory – directories specified by /lib:dir1[,dir2...] switch – directories specified by LIB environment variable App.cs compiler App.exe csc /target:exe /out:App.exe /reference:Finance.dll App.cs 17
- Dependent assembly reference • Identity of dependent assemblies recorded in manifest – information used during runtime assembly binding – ensures binding to same assembly at runtime App.exe dependent assembly .assembly extern Finance recorded { .publickeytoken ... .ver 1.2.3.4 } ... 18
- Deployment • Several actors involved in deployment – main .exe – dependent .dlls – main deployment directory – configuration file 19
- AppBase • Directory containing main .exe called AppBase C:\ Program Files AppBase MyApplication App.exe 20
![](images/graphics/blank.gif)
ADSENSE
CÓ THỂ BẠN MUỐN DOWNLOAD
Thêm tài liệu vào bộ sưu tập có sẵn:
![](images/icons/closefanbox.gif)
Báo xấu
![](images/icons/closefanbox.gif)
LAVA
AANETWORK
TRỢ GIÚP
HỖ TRỢ KHÁCH HÀNG
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn
![](https://tailieu.vn/static/b2013az/templates/version1/default/js/fancybox2/source/ajax_loader.gif)