Outils de développement pour .NET Framework

8QGHU&RQVWUXFWLRQ (Q&RQVWUXFWLRQ Didier Donsez 8QLYHUVLWp-RVHSK)RXULHU *UHQREOH ,0$,0$*/65$'(/( 'LGLHU'RQVH]#LPDJIU 'LGLHU'RQVH]#LHHHRUJ

Didier Donsez, 2003, Outils de développement pour 1 .NET  2 Petit rappel sur .NET et #

I .NET • Développement Multi langage • C#, C++, Java Script, Eiffel, Component Pascal, APL, Cobol, Oberon, Perl, Python, Scheme, Smalltalk, Standard ML, Haskell, Mercury, Oberon et Java/J++ • CIL (Common Intermediate Language) • CTS ()

7 • CLI (Common Language Infrastructure) ( 1   U X

R • CLR (CLI Runtime implémenté par ) S  W Q

H • JIT, pré-JIT (à l’installation, ou développement) P H S S O I H C# : le langage « Post-Java » Y p G  H

G • « Syncrétisation » de Java et de C++  V O L W X 2

 I  Standardisation ECMA (European Computer Manufacturers Association)  

 · http://www.ecma.ch    ] H V

Q • ECMA-334 CLI (Format COFF, CTS, Metadata, …) R '  U H L

G • ECMA-335 C# L '  3 1RQ0LFUR6RIW .NET

I Motivations • .NET sur des OS non Windows (Unix, , MacOS X, …) • Implémentations libres • Outils libres I Project 7 ( 1  

U • ROTOR (MicroSoft) sauf Linux (Shared Sources) X R S  W Q H • project (Ximian) P H S S R O H

Y • DotGNU ( Foundation) p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  4 Implémentations

I MicroSoft · Commerciales · .NET CLR · Compact .NET CLR • Code partagé • « Rotor » : Shared Source CLI 7 ( 1   U 3.6 Mloc ( 10,721 fichiers) X R S  W Q

H KWWSPVGQPLFURVRIWFRPQHWVVFOL P H S S

R • GC moins performant, JIT différent O H Y p G 

H • Une sous partie du Runtime (pas de WebForm, ADO, ASP.NET, …) G  V O L W X 2   I

 Mono      ] H

V I Q DotGNU Portable .NET R '  U H L G L '  5 8QGHU&RQVWUXFWLRQ Compilateurs (Q&RQVWUXFWLRQ

I MicroSoft

I Mono • Compilateur et JIT efficace • Peu de processeurs 7 ( 1   U

X I R DotGNU S  W Q H P H

S • GCC Front End S R O H Y p G

 • Linux et dizaine d’OS H G  V O L W X • Nombreux processeurs 2         ] H V Q R '  U H L G L '  6 Outils du SDK

I Assembly Generation Utility (al.exe) I Assembly Registration Utility (gac.exe) I MSIL Assembler (.exe) I MSIL Disassembler (ildasm.exe) I C++ Compiler (cl.exe) I C# Compiler (csc.exe)

7 I

( Visual Basic Compiler (vbc.exe) 1   U X

R I J# Compiler (en extra) S  W Q H

P I

H PE File Format Viewer (dumpbin.exe) S S R O H

Y I Type Exporter (tlbexp.exe) p G  H G  I V

O Type Library Importer (tlbimp.exe) L W X 2  

 I XML Schema Definition Tool (xsd.exe)      ] I H Shared Name Utility (sn.exe) V Q R '  U I Web Service Utility (wsdl.exe) H L G L '  7 Décompilateurs

I MSIL Disassembler (Ildasm.exe) · a companion tool to the MSIL Assembler (Ilasm.exe). Ildasm.exe takes a portable executable (PE) file that contains Microsoft intermediate language (MSIL) code and creates a text file suitable as input to Ilasm.exe. 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  8 Décompilateurs 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  9 8QGHU&RQVWUXFWLRQ Ofuscateur (Q&RQVWUXFWLRQ

I · (http://www.preemptive.com/dotfuscator) 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  10 8QGHU&RQVWUXFWLRQ Profilage (Q&RQVWUXFWLRQ

I Identification • des points chauds (ERWWOHQHFNKRWVSRW) • des fuites mémoires … I Outils 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  11 Profilage

I Il existe un namespace

$SSOLFDWLRQ ICorProfilerInf o 7 ( 1   U X R S  W Q

H 5XQWLPH 3URILOHU P H S S R O H Y p G  H G  V O L W X 2         ] ICorProfilerCallba H V Q R

' ck  U H L G L '  12 Génération (ou émission) dynamique de code

I Motivations • AOP, Dynamic Proxy (Réseau, BD, …), …

I namespace System.Reflection.Emit • Permet la contruction d’assemblies, modules, classes à la 7 ( 1

 volée  U X R S  W Q H I Voir P H S S R O H

Y • http://www.dina.dk/~sestoft/rtcg/rtcg.pdf p G  H G  V O L

W • Rechercher Cisternino & Kennedy, Language independent X 2   

 program generation     ] H V Q R '  U H L G L '  13 Exemple de Génération de code (i)

private static 7\SH CreateHelloWorld(AppDomain appDomain, AssemblyBuilderAccess access) {

$VVHPEO\1DPH assemblyName = new AssemblyName(); assemblyName.Name= "EmittedAssembly";

// Create the dynamic . $VVHPEO\%XLOGHU assembly = appDomain.DefineDynamicAssembly(assemblyName, access); 7 ( 1  

U // Create a dynamic module X R S  W module= assembly.DefineDynamicModule("EmittedModule"); Q 0RGXOH%XLOGHU H P H S S R O H

Y // Define a public class named "HelloWorld" in the assembly. p G  H G

 helloWorldClass = module.DefineType("HelloWorld", TypeAttributes.Public);

V 7\SH%XLOGHU O L W X 2     

 // Define a private String field named "Greeting" in the type.   ] H V

Q )LHOG%XLOGHU greetingField= helloWorldClass.DefineField( R '  U H

L "Greeting", typeof(String), FieldAttributes.Private); G L '  14 Exemple de Génération de code (ii)

// Create the constructor. Type[] constructorArgs = { typeof(String) }; &RQVWUXFWRU%XLOGHU constructor = helloWorldClass.DefineConstructor( MethodAttributes.Public, CallingConventions.Standard, constructorArgs);

// GenerateIL for the method. The constructor calls its superclass constructor. // The constructor stores its argument in the privatefield. 7 ( 1

 constructorIL= constructor.GetILGenerator();  ,/*HQHUDWRU U X R S  W constructorIL. ( );

Q (PLW 2S&RGHV/GDUJB H P H

S ConstructorInfo superConstructor = typeof(Object).GetConstructor(new Type[0]); S R O H Y

p constructorIL.Emit(2S&RGHV&DOO, superConstructor); G  H G  V

O constructorIL.Emit( ); L 2S&RGHV/GDUJB W X 2  

 constructorIL.Emit(2S&RGHV/GDUJB);     

] constructorIL.Emit( , greetingField);

H 2S&RGHV6WIOG V Q R '

 constructorIL.Emit( );

U 2S&RGHV5HW H L G L '  15 Exemple de Génération de code (iii)

// Create the GetGreeting method. 0HWKRG%XLOGHU getGreetingMethod= helloWorldClass.DefineMethod("GetGreeting", MethodAttributes.Public, typeof(String), null);

// GenerateIL for GetGreeting. ,/*HQHUDWRU methodIL= getGreetingMethod.GetILGenerator(); 7

( methodIL.Emit(OpCodes.Ldarg_0); 1   U X

R methodIL.Emit(OpCodes.Ldfld, greetingField); S  W Q H P

H methodIL.Emit(OpCodes.Ret); S S R O H Y p G  H G  V

O // Bake theclass HelloWorld. L W X 2  

 return(helloWorldClass. ());

 &UHDWH7\SH     ]

H } V Q R '  U H L G L '  16 Execution

I Assembly Loader I Security I Class Loader I IL to Native Compiler · Native.exe+GC Table 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  17 Test

I Unitaire · CLR · NUnit

· ASP.NET 7

( · NUnitWeb 1   U X R

S http://kristopherjohnson.net/cgi-bin/twiki/view/KJ/NUnitWeb  W Q H P H

S · Web Services S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  18 Normes de programmation

I C# · ??? · Style Checkers ?? I VB 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  19 8QGHU&RQVWUXFWLRQ Sécurité (Q&RQVWUXFWLRQ

I Gestion de certificats I Signature de code I Code sellé ?? VHDOHG non réversible I Vérifieur de code

7 I Pré-vérifieur de code ( 1   U X R S

 • Vérifie en autre la présence de unmanaged section W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  20 Gestion de projets

I Makefile • nmake (.NET SDK) I Tâches (optionnelles) ANT • Le .NET SDK doit être installé; variables d’environnement configurées • compilateur C# • assembleur d’IL 7 (

1 • générateur de stub/skel SOAP en C#, VB, ..   U X R S 

W • Exemple Q H P H

S •

Y unsafe="false" targetType="exe" incremental="false" definitions="RELEASE" p G  H

G excludes="src/unicode_class.cs"  V O L W

X mainClass = "MainApp" destFile="NetApp.exe" /> 2      

 I

 NAnt (http://nant.sourceforge.net/) ] H V Q R · Un portage de ANT sur .NET '  U H L G L '  21 Convertisseurs Java vers C# / .NET

I Aztec J2CS, ArtinSoft JLCA, DotNetJ, … I Microsoft JCLA (Java Language Conversion Assistant) · Assistant pour VisualStudio .NET de Convertion · Java ou J++ vers J# ou C# 90 % de appels au JDK 1.1.4 convertis 7

( -DYDWHFKQRORJ\ 8SJUDGHWR- 8SJUDGHWR& 1   U X R S  W Q

H Java language Java language C# language P H S S

R Applet Not converted Windows Form control O H Y p G  H

G JavaBean JavaBean C# class  V O L W X 2

 AWT frame AWT frame Windows Form       

] WFC Form WFC Form Windows Form H V Q R '

 Compiled library Compiled library Not converted U H L G L

' Resource file ResXfile ResXfile  22 Migration J2EE vers .NET

I J2EE I .NET · Servlets, JSP · ASP .NET

· EJB · Session Bean · Entity Bean

7 CMP ( 1  

U BMP X R S  W Q

H • JDBC P H

S · ADO .NET S R O H Y

p · Transact SQL G 

H • Procédures Stockés G  V O L W

X · Oracle PL/SQL, ¼ 2  

 · Web Services      ] H V Q R '  U H L G L '  23 Ateliers (CASE)

I MicroSoft VisualStudio .NET

I MicroSoft WebMatrix • Gratuit (intègre Cassini (Web Server) • Pas de complétion au codage ! 7 ( 1   U X R S  W Q H P

H I

S Eclipse + plugin S R O H Y p G  H G  V O L W X 2   I  Autres (Inprise ??)      ] H V Q R '  U H L G L '  24 Mono Project (Ximian) KWWSZZZJRPRQRFRP I Motivation • Effort pour créer une version libre de .NET Framework. • Pour Linux (donc MacOSX) I Outils • Compileur C# 7 ( 1  

U • Runtime X R S  W Q

H · JIT (Linux/) P H S S

R · Interpreteur (Linux/x86, Linux/PPC, S390 + en cours pour O H Y p G

 StrongARM, SPARC) H G  V O L W X

2 • Bibliothèques de classes.        

] • Implémentations de ADO.NET et ASP.NET H V Q R '  U H L G L '  25 8QGHU&RQVWUXFWLRQ DotGNU (Q&RQVWUXFWLRQ 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  26 Serveurs HTTP

I Motivations · Support aux ASP .NET

I Serveurs · MicroSoft IIS 7 ( 1  

U · MS Cassini (Gratuit) X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  27 CORBA et .NET

I Il y a assez d’info dans la CLI pour créer des stubs et de squelettes (Miguel de Icaza) 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  28 J2EE et .NET

I DotNetJ • Permet à des clients .NET d’accéder à une application J2EE/EJB via des .NET Remoting · 2 options de Canal .NET Remoting Canal IIOP Canal personnalisé (ObjectWeb/CAROL) 7 ( 1   U X R S 

W • Testé avec JOnAS (en partenariat avec ObjectWeb) Q H P H S S R O H Y p G  · Remarque : H G  V O L W

X • Les WebServices ne permettent pas le passage d’objets par référence 2         ] H V Q R '  U H L G L '  29 Web Services et .NET

I SOAP I WSDL I UDDI I XSD 7 ( 1   U X R S 

W I

Q Interopérabilité H P H S S R

O · Apache AXIS, WebLogic, WebSphere ¼ H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  30 Outils SDK pour les WS

I wsdl.exe • Génère un stub SOAP à partir d’un WSDL ZVGO ODQJXDJHYE KWWSORFDOKRVWSPFDOFSPFDOFDVP["ZVGO ZVGO ODQJXDJHFV KWWSORFDOKRVWSPFDOFSPFDOFDVP["ZVGO I VRDSVXGVH[H 7 (

1 *ÚQÙUHXQ:6'/ÑSDUWLHGHV0HWDGDWD   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  31 Bases de Données et .NET

I API DataSet

I SGBD · SQL Server 7 ( 1   U X R S  W Q H

P · MSDE ( MS SQL Server 2000 Desktop Engine ) H S S R O H

Y · Gratuit pour les tests p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  32 .NET et Temps Réel

I Voir article Lutz, M.H.; Laplante, P.A, ‘&DQGWKH 1(7IUDPHZRUNUHDG\ IRUUHDOWLPH"’, IEEE Software Volume: 20, Issue: 1, Jan/Feb 2003, pp 74- 80 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  33 Embarqué et Nomade

I .NET compact Framework • .NET pour cibles Windows CE

I .NET SmartCard (KWWSZZZKLYHPLQGHGFRP 7 ( 1  

U • Implémentation de la CLI pour les cartes à puce X R S  W Q H P H S S R O H Y p I G

 .NET Framework for X-Box H G  V O L W X • cible les consoles de jeu 2        

] • Disponibilité ??? H V Q R '  U H L G L '  34 .NET Compact Framework

I .NET Compact Framework • Version allégé de .NET FrameWork • Cible les profiles CDC et CDLC • fonctionnement offline · Exemple: cache de ligne SQL (ADO) · RTE

7 • Core CLI, réseau, XML, Web Services, ADO .NET ( 1   U X

R • Garbage collector : simple Mark and Sweep S  W Q H • JIT MSILÆNatif P H S S R

O au premier appel H Y p G

 Cache de code JIT H G  V O L W

X • Environnement matériel 2    

 · StrongARM, MIPS, x86, SH4, Xscale, ¼    ] H

V · Windows CE Q R '  U H

L · RAM : 1.5 Mo minimum G L '  35 .NET SmartCard KWWSZZZKLYHPLQGHGFRP

I Implémentation de la CLI adapté à la carte I Multi-applications I Développement Multi-langage : C#, J#, VB, Jscript, Perl, … I Caractéristiques · Isolation · de .NET 7

( · Transactions 1   U X

R · Multi-niveaux ? S  W Q H

P · Garbage Collector H S S R

O · Mark and Sweep (sans marquage en EEPROM) H Y p G 

H · Communication G  V O L W

X · Inter-applications 2   

 Channel : flux d’octets bidirectionnel     ]

H · Terminal-Application V Q R

' APDU, .NET Remoting, Javacard 2.2 RMI  U H L G L '  36 OlyMars

I ~Entity Bean CMP 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  37 Extra

I API par COM+ • Utilise des wrappers • Transaction (coordinateur MTS), Sécurité, … 7 ( 1   U X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  38 Bibliographie

I Beaucoup d’ouvrages sur C# et .NET · http://www.oreilly.com/dotnet · ¼ I David Stutz, Ted Neward, Geoff Shilling, Shared Source CLI Essentials, O'Reilly, March 2003 7 ( 1  

U (est.), ISBN 0-596-00351-x X R S  W Q H P H S S R O H Y p G  H G  V O L W X 2         ] H V Q R '  U H L G L '  39 Sites

I http://microsoft.com/net I http://www.dotnetguru.org I http://www.go-mono.com I http://dotgnu.org

7 I http://www.ecma.org ( 1   U X R S  W Q H P H S S R O I

H http://www.codeproject.com/dotnet Y p G  H G 

V • Fournit pas mal d’exemples O L W X 2         ] H V Q R '  U H L G L '