Download presentation
Presentation is loading. Please wait.
Published byEthelbert McDaniel Modified over 8 years ago
1
Assemblies
2
2 Objectives Introduce assemblies –concept –creation –naming Discuss deployment –main.exe –dependent assemblies
3
3 Assembly An assembly is a logical group of types –unit of deployment, versioning, and security in the CLR assembly of financial types Advisor Bond Stock Invest
4
4 Assembly contents Assembly contains several parts –IL –description of contained types in the metadata –description of assembly in the manifest IL.ver 1.2.3.4.publickey... description of Invest, Stock, Bond, Advisor classes code for Invest, Stock, Bond, Advisor classes metadata manifest
5
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 in assembly internal class Advisor {... } available in all assemblies public class Stock {... }
6
6 Member access Can make type member internal –allows access only within same assembly available only in assembly public class Stock { internal string name;... }
7
7 Finance.dll Single file assembly Assembly can be single dll or exe file –simple to create –simple to deploy –most common case Advisor Bond Stock Invest single file assembly
8
8 source filesassembly Assembly creation Compiler outputs assembly when target type is: –exe –winexe –library compiler Finance.dll Advisor.cs Stock.cs Bond.cs Invest.cs csc /target:library /out:Finance.dll Invest.cs Stock.cs Bond.cs Advisor.cs
9
9 Module Can create module with compiler /target:module switch –does not create assembly –typically has.netmodule extension Assets.netmodule Stock.cs Bond.cs source filesmodule compiler csc /target:module /out:Assets.netmodule Stock.cs Bond.cs
10
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 Finance.dll Advisor.cs Invest.cs additional source files two files, one assembly csc /target:library /out:Finance.dll /addmodule:Assets.netmodule Invest.cs Advisor.cs compiler Assets.netmodule
11
11 Assembly identity Assembly identified by four attributes –name –culture –version –public key token
12
12 Name Assembly name based on name of file containing manifest –set automatically when assembly created assembly name is Finance compiler Finance.dll csc /target:library /out:Finance.dll...
13
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
14
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
15
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 sn -k Lib.snk [assembly: AssemblyKeyFile("Lib.snk")] generate keys, specify output file apply keys to assembly
16
16 Dependent assemblies Typical for application to consist of multiple assemblies –main.exe and supporting.dll s Finance.dll Advisor Bond Stock Invest App.exe Main main.exe supporting.dll
17
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.exeApp.cs csc /target:exe /out:App.exe /reference:Finance.dll App.cs compiler
18
18 Dependent assembly reference Identity of dependent assemblies recorded in manifest –information used during runtime assembly binding –ensures binding to same assembly at runtime.assembly extern Finance {.publickeytoken....ver 1.2.3.4 }... dependent assembly recorded App.exe
19
19 Deployment Several actors involved in deployment –main.exe –dependent.dll s –main deployment directory –configuration file
20
20 AppBase Directory containing main.exe called AppBase C:\ Program Files MyApplication App.exe AppBase
21
21 Application configuration file Application can have configuration file –used to help manage deployment –file name is application name with.config added –placed in AppBase... App.exe.config file in AppBase directory
22
22 Deploying dependent assemblies Several options for deployment of dependent assemblies –AppBase –directory below AppBase specified in config file –local or remote location specified by URI in config file –global assembly cache
23
23 AppBase deployment AppBase automatically searched for needed assemblies C:\ Program Files MyApplication App.exe AppBase Finance.dll dependent assembly
24
24 Private path Can specify subdirectories of AppBase be searched –use probing privatePath in config file C:\ Program Files MyApplication AppBase MyAssemblies App.exe.config Finance.dll dependent assembly App.exe
25
25 Codebase Can specify arbitrary URI for strongly named assembly –use codeBase element in config file –useful to redirect to new version of needed assembly C:\ Program Files MyApplication App.exe.config App.exe MyAssemblies Finance.dll not under AppBase dependent assembly
26
26 Global assembly cache (gac) Strongly named assembly can go in global assembly cache –typically stored under C:\Windows\assembly –need admin privileges to install –automatically searched for needed assemblies –use gacutil tool to manipulate cache Convenient way to store shared assembly –but complicates deployment, backup, and uninstall gacutil /i Finance.dll install gacutil /u Finance,Version=1.2.3.4,PublicKeyToken=362cfdd636584143 uninstall
27
27 Summary Assembly is the component of the CLR –unit of deployment and versioning Assembly identity made of four components –name –culture –version –public key token Application typically made of several assemblies –must reference dependent assemblies at compile time –several options for runtime assembly deployment
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.