140 likes | 148 Views
Learn to compile C# console programs using csc.exe, manage assemblies, handle .DLL versioning, sign assemblies for security, and deploy C# applications efficiently.
E N D
Working with assemblies Compiling a C# program : console program : use the csc.exe (C Sharp Compiler) to generate an .exe file not a "true" exe, needs the .NET CLR virtual machine in order to be translated from MSIL to binary (machine language) this .exe is called an assembly
.DLL files usage : suppose you wrote a test.cs file containing one or more classes use the VS cmd.exe tool (that good old ugly DOS interface) generates test.exe csc test.cs
.DLL files in order to generate a .DLL file : in order to generate a .netmodule file csc /t:library test.cs csc /t:module test.cs use .netmodule files to create assemblies containing files from different .NET languages
DLL versioning "the .DLL Hell" : updating a .DLL file might corrupt existing applications several versions of a .DLL can now exist Assembly manifest : meta data about the assembly : just copy/paste an assembly to an appplication bin directory.
Assembly signing code security and management : sharing assemblies : copy the .ddl file to the current project directory add a project reference to the current project problem with .dll updates (versioning)
Assembly signing highly shared assemblies (C# standard Class Library) use another system : located in the GAC (Global Assembly Cache) C:\WINNT\assembly directory security issues !
Assembly signing an assembly to be installed in the GAC must have a strong name (encryption by public/private keys, RSA Algorithm) how to sign an assembly : produce a public/private key pair sign the assembly register the assembly to the GAC
producing a key pair .NET utility tools (access by the dedicated command prompt) sn.exe (strong name) sn –k filename.snk generates a binary file
signing an assembly al.exe (assembly linker) uses a module (.net module file) al /out:filename.dll module /keyfile:keyfilename al /out:toto.dll class1.netmodule /keyfile:titi.snk generates the strong named toto.dll assembly
registering to the GAC gacutil.exe (assembly linker) use the /i command to install the assembly gacutil /i assembly.dll
using the assembly info file strong name signing is possible via the assembly info file attributes : in a VS Project : AssemblyInfo.cs file attributes : [assembly: AssemblyTitle("….")] [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile(keyfilename)]
using the assembly info file application directory .cs source files .snk key file obj bin Debug .dll output Release
using the assembly info file if a mykeys.snk file is use to give a string name : the following [assembly:AssemblyKeyFile("..\\..\\mykeys.snk")] attribute is written in the AssemblyInfo.cs file the assembly has still to be installed in the GAC with gacutil.exe