intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Lesson Assemblies

Chia sẻ: Lavie Lavie | Ngày: | Loại File: PDF | Số trang:0

48
lượt xem
1
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

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.

Chủ đề:
Lưu

Nội dung Text: Lesson Assemblies

  1. Assemblies
  2. Objectives • Introduce assemblies – concept – creation – naming • Discuss deployment – main .exe – dependent assemblies 2
  3. 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
  4. 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
  5. 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
  6. Member access • Can make type member internal – allows access only within same assembly public class Stock { available only internal string name; in assembly ... } 6
  7. 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
  8. 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
  9. 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
  10. 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
  11. Assembly identity • Assembly identified by four attributes – name – culture – version – public key token 11
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. Deployment • Several actors involved in deployment – main .exe – dependent .dlls – main deployment directory – configuration file 19
  20. AppBase • Directory containing main .exe called AppBase C:\ Program Files AppBase MyApplication App.exe 20
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2