-----------------------------------------------------------

New Message on cochindotnet

-----------------------------------------------------------
From: Nasha
Message 1 in Discussion


Hi All,
 
Lot of us have 
been asked this question in our interviews. So here are the steps to 
create a multifile assembly using ".netmodules" 
.

Step 
1:



1.      
Create a console 
application Named MultiFile1. 

2.      
Add a class to 
this application named MyClass.

3.      
Remove the 
"Main" method from the class.

4.      
Add a new method 
to the class named "MultiFile1_Method"

5.      
Go to the visual 
studio command prompt, go to the directory where this class resides.

6.      
Compile the 
class with this command : csc /t:module MyClass.cs

7.      
This is will 
create a file with extension ".netmodule" named MyClass.netmodule.

 

Code 
:

 

using System;

namespace MultiFile1
{
 class 
MyClass
 {
 public void 
MultiFile1_Method()
  {
   Console.WriteLine("This 
is a method from MultiFile1"); 

   Console.ReadLine();
  }
 }
}

 

 

Step 2: 


  
        
    Add another class to the 
    project named MyClient.cs
        
    Change the namespace of 
    the class from "Multifile1" to "MultiFile2"
        
    Add the reference to the 
    "MultiFile1" namespace.
        
    Add the main method to 
    the class. 
        
    Call the method 
    "MultiFile1_Method" of Myclass in the Main.
        
    Go to the visual studio 
    command prompt, go to the directory where this class 
    resides.
        
    Compile the class with 
    this command : csc /addmodule:MyClass.netmodule /t:module 
    MyClient.cs
        
    This is will create a 
    file with extension ".netmodule" named 
    MyClient.netmodule.   
        Code 
:
 

  using System;
using 
  MultiFile1;
   
  namespace 
  MultiFile2
{
   
   public class 
  MyClient
 {
  public 
  MyClient()
  {
  }
  public static void 
  Main() 
  {
   MultiFile1.MyClass oMyClass = 
  new 
  MyClass();
   oMyClass.MultiFile1_Method();
  }
 }
}


Step 3:

 

1.      
Go to the visual studio 
command prompt, go to the directory where these classes 
reside

2.    Create the assembly with the 
following command : 

                    
al MyClass.netmodule MyClient.netmodule /main:MultiFile2.MyClient.Main 
/out:MyAssembly.exe /target:exe<o:p></o:p>

3.    MyAssembly.exe will be 
created.

<o:p>4.   O</o:p>pen 
the exe with ildasm and you will refernces to the two .netmodules that we 
created .

 

 

MyAssembly opened in ildasm 
:

 

  .module extern 
  MyClient.netmodule
.assembly extern mscorlib
{
  
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 
  )                         
  // .z\V.4..
  .hash = (E6 8E F4 00 2B 3C 3C 88 D6 32 F2 72 A3 22 FA 
  C8   // 
  ....+<<..2.r."..
           
  A7 7B 24 07 
  )                                     
  // .{$.
  .ver 1:0:5000:0
}
.assembly MyAssembly
{
  
  // --- The following custom attribute is added automatically, do not uncomment 
  -------
  //  .custom instance void 
  [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(bool,
  
  //                                                                                
  bool) = ( 01 00 00 01 00 00 ) 
  .hash algorithm 0x00008004
  
  .ver 0:0:0:0
}
.file 
  MyClass.netmodule
    .hash = (92 EC 2F E8 F2 90 4B 2D 54 C6 
  AC 4C C5 69 CF 92   // 
  ../...K-T..L.i..
             
  37 2B A1 2F 
  )                                     
  // 7+./
.file MyClient.netmodule
    .hash = (7B 4E 77 76 
  94 24 D9 3D 26 B4 3C 98 BA B1 49 3E   // 
  {Nwv.$.=&.<...I>
             
  9C 45 90 0A 
  )                                     
  // .E..
.class extern public 
  MultiFile2.MyClient
{
  .file MyClient.netmodule
  .class 
  0x02000002
}
.module MyAssembly.exe
// MVID: 
  {0B92C2A4-6956-4ED7-A40D-BAB2D6C505D4}
.imagebase 0x00400000
.subsystem 
  0x00000003
.file alignment 512
.corflags 0x00000001
// Image base: 
  0x071f0000


-- 
Please mail me your comments for my 
articles. I hope this step from my end is helpful to all of 
us.

Regards,

Namratha (Nasha).
 
 
 
 

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/cochindotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to