Monday, April 11, 2011

Windows Azure - Referring DLL from GAC

Hi All,
Many times you may face requirement that, you are developing a web application and you want to host web application as a web role in Azure. While development lets say that, you have used your application specific DLL's which you added in GAC - Global assembly cache and referencing from there.

So while hosting web role on Azure, how can you make sure that, your required DLL gets added to GAC before role starts?

Following steps wil explain you the same.

  1. Add a folder in solution explorer by right clicking on project and selecting option of "New Folder".
  2. Add GACUtil.exe and associated configuration file gacutil.exe.config to this folder. You may find the GAC exe at location "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64".
  3. Add your DLL also to same folder.
  4. Add a .cmd file to same folder and write code as follows - (REM stands for comment in cmd file)

                  REM Following statement adds MY.dll into GAC
                  .\MyfolderName\gacutil /nologo /i .\MyFolderName\My.dll

                   REM Exit from command prompt
                     exit /b 0

Then go to properties of each file added above and select "Copy Always" option against "copy to output directory" option.
Under "serviceDefinition.csdef" file as following line under web role tag -
      <Task commandLine=".\MyfolderName\RegisterGAC.cmd" executionContext="elevated" taskType="simple" />

This will make sure that, your DLL gets added to GAC..


Please give food to all my fishes swimming at the bottom. It's fun!! Try it!!
Thanks for reading!!

Happy coding.

No comments:

Post a Comment