Place .NET DLL in GAC
Today other team guy has asked me help as he was facing some problem in trying to place a .NET DLL in GAC where he does not have source code with him.
Potentially you just have to follow regular steps as mentioned below to place the DLL in GAC;
1. Generating the public key:
Go to visualStudio.Net command prompt and type the following command:
sn -k keyfile1.snk
Here keyfile1.snk is the keyfile we are generating.
You can store this key file in the bin folder of the assembly. In order to do this u have to go to the bin folder.
For example:
C:\foldername\assemblyname\bin sn-k keyfile1.snk
By doing this the keyfile is stored in the bin folder.
2. Than place the keyfile into the Assembly.
Go to AssemblyInfo.cs file:
[assembly: AssemblyKeyFile("C:\foldername\assemblyname\keyfile1.snk")]
3. Then build the Assembly.
4. Placing the assembly into GAC
This process is fine when you have source code with you.
What if you don't have the source code with you and you need to put it to the GAC. Here you will not be able to follow the 2 and 3rd step.
Therefore, we need this little tip to be able to sign a DLL without a source code.
These are the steps that you have to follow to sign the DLL;
1. You will need to use .NET SDK to create a new key. you can do this by either within the Visual Studio IDE or using the command prompt by typing “sn -k keyfile1.snk“. Be sure to record the path where you keep this key.
2. Using the command prompt, go to the folder with your DLL. Copy ilasm.exe and ildasm.exe to the same directory and also the previously created key file. (In this case example.snk)
Note: if you have your environment variables set up to .NET SDK then you don’t have to copy these programs or you can reference the path explicitly.
3. Type ildasm assemblyname.dll /out=assemblyname.il to decompile the DLL into IL format with the resource file that we will use later to be attached with the key file
4. Type ilasm assemblyname.il /dll/resource=assemblyname.res /key=assemblyname.snk /optimize. This command recompiles the DLL with the il file, resource file and the new key file together.
5. Validate the strong name by using “sn -v assemblyname.dll” from the command prompt.
You now have a strongly typed DLL that can be safely signed in any application without source code or recreating a build environment.
Finally, still I have a problem of pace this DLL in GAC by calling Gacutil.exe
I will have to spend some more time to fix this.
Potentially you just have to follow regular steps as mentioned below to place the DLL in GAC;
1. Generating the public key:
Go to visualStudio.Net command prompt and type the following command:
sn -k keyfile1.snk
Here keyfile1.snk is the keyfile we are generating.
You can store this key file in the bin folder of the assembly. In order to do this u have to go to the bin folder.
For example:
C:\foldername\assemblyname\bin sn-k keyfile1.snk
By doing this the keyfile is stored in the bin folder.
2. Than place the keyfile into the Assembly.
Go to AssemblyInfo.cs file:
[assembly: AssemblyKeyFile("C:\foldername\assemblyname\keyfile1.snk")]
3. Then build the Assembly.
4. Placing the assembly into GAC
This process is fine when you have source code with you.
What if you don't have the source code with you and you need to put it to the GAC. Here you will not be able to follow the 2 and 3rd step.
Therefore, we need this little tip to be able to sign a DLL without a source code.
These are the steps that you have to follow to sign the DLL;
1. You will need to use .NET SDK to create a new key. you can do this by either within the Visual Studio IDE or using the command prompt by typing “sn -k keyfile1.snk“. Be sure to record the path where you keep this key.
2. Using the command prompt, go to the folder with your DLL. Copy ilasm.exe and ildasm.exe to the same directory and also the previously created key file. (In this case example.snk)
Note: if you have your environment variables set up to .NET SDK then you don’t have to copy these programs or you can reference the path explicitly.
3. Type ildasm assemblyname.dll /out=assemblyname.il to decompile the DLL into IL format with the resource file that we will use later to be attached with the key file
4. Type ilasm assemblyname.il /dll/resource=assemblyname.res /key=assemblyname.snk /optimize. This command recompiles the DLL with the il file, resource file and the new key file together.
5. Validate the strong name by using “sn -v assemblyname.dll” from the command prompt.
You now have a strongly typed DLL that can be safely signed in any application without source code or recreating a build environment.
Finally, still I have a problem of pace this DLL in GAC by calling Gacutil.exe
I will have to spend some more time to fix this.
Comments
I read your articles very excellent and the i agree our all points because all is very good information provided this through in the post. It is very helpful for me. Keep blogging like this. Thanks.
SAP training in Chennai
Corporate Training in Chennai
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
Online Reputation Management
Digital Marketing Company in Chennai
Best Dental Clinic In Tambaram
MSBI Training in Chennai
Informatica Training in Chennai
Facility Management Companies in Chennai