Τετάρτη 16 Μαΐου 2018

How to GAC a dll with PowerShell in VSTS

Introduction

When we install an application on a machine, it is necessary to have already installed all required external dependencies. Registering in GAC the dlls is a nice way to deal with this problem. In VSTS where we expect deployment to happen without human intervention, having a way to register those dlls into GAC will give elegance and clearence to our deployment process.
In this article we will explain how to use GAC It!, a VSTS custom extension which registers all dlls in one folder.
 

Core Code

The PowerShell script is built around procedure

System.EnterpriseServices.Internal.Publish.GacInstall(filename)

which registers the given file. 
Unfortunately, in case of an error, it doesn't give back any meaningful message. That's why we have to check whether the dll is indeed registered, by trying to load it.
Generally, gacutil.exe is a better way to GAC dlls but it must be copied first on the target machine and cannot be an integral part of an extension.

How to GAC It!

To call the powershell script is very simple 

Copy all dll files you want into a folder. GAC It! can search recursively into subfolders.

Then add a new Task with GAC It! It gets the following parameters:
  1.  p_DllPath (string, mandatory): the complete path of the folder which contains the dlls
  2. p_FileMask (string, default *.dll): Use filemask if you want to register only the dlls with specific names. It is useful when you want to register just one dll.
  3. p_Recurse (boolean, default true): If we want to include subfolders.

 Example

It follows an example about how to use the task. Enjoy!

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου