Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add/update assemblies to the GAC via a Nuget Package?

Nuget, without a doubt is an extremely effective packaging and distribution system. However, there are some instances where managing the assembly files becomes cumbersome. This is particularly apparent for web applications where many (30+) sub-applications in a site are setup to inherit references. A single point of inheritance is desirable in my case due to the ease in which the library can be updated for all child projects. It has become problematic for me to reliably store these assemblies in the root directory. In an effort to help manage this I would like to use the GAC for these particular libraries..

Is there a way to install/update these libraries to the GAC via a nuget package script? I can always resort to traditional means but I would like to take advantage of Nuget for this if possible. The assembly would be added to the server GAC but the purpose of the package would be to allow developers to easily install the assembly to their local GAC and maintain the same reference between local/server environments.

like image 757
NickSuperb Avatar asked Nov 06 '13 16:11

NickSuperb


People also ask

Which assembly can be put into GAC?

GAC is a folder in Windows directory to store the . NET assemblies that are specifically designated to be shared by all applications executed on a system. Assemblies can be shared among multiple applications on the machine by registering them in global Assembly cache(GAC). The GAC is automatically installed with the .

Are assemblies that are stored under GAC?

The Global Assembly Cache (GAC) is a central repository for storing shared assemblies. The GAC allows multiple versions of the same assembly to be installed concurrently and also prevents different assembly vendors from overwriting each other's assemblies.

How to add an assembly to the GAC?

The first step involved in adding an assembly is to strong-name the assembly. A strong name is basically assigned to an assembly or a component to distinguish it from other assemblies and components existing in the GAC. A strong name consists of an assembly identity (name, version, and so on), a public key, and a digital signature.

What is the purpose of a GAC package?

The assembly would be added to the server GAC but the purpose of the package would be to allow developers to easily install the assembly to their local GAC and maintain the same reference between local/server environments. Show activity on this post.

What is the Global Assembly Cache (GAC)?

The global assembly cache (GAC) stores assemblies that several applications share. Install an assembly into the global assembly cache with one of the following components: You can install only strong-named assemblies into the global assembly cache.

How to install a DLL file in GAC?

Click Start > All Programs > Administrative Tools > Microsoft .NET Framework 2.0/4.0 Configuration. 2. Click Manage the Assembly Cache. 3. Select Add an Assembly to the Assembly Cache. 4. Browse and select your DLL, which you want to install it in GAC 5. Click Open. This will deploy the selected assemblies into the Global Assembly Cache (GAC). 6.


1 Answers

You can install assemblies to the GAC with a PowerShell script from PowerShell GAC, so your install.ps1 script can definitely do this.

However a word of caution is warranted; doing this is probably not going to give most people the behavior they want. Each project is going to use a strong name reference to a specific version. Just because one project updates the package doesn't mean the other projects will update their packages, nor will they use the newer version in the GAC - they'll use the one they are strongly bound to unless the assembly contains a binding policy specifying the new version replaces the old one, in which case the version the project uses won't match the version nuget believes is installed!

Thus it can become very difficult to reason about exactly which version of the assembly is being used. Normally, you can just look at the nuget installed packages and immediately know what you've got.

In my case, we are using nuget to keep binaries outside of Git, but some of the binaries involve the WinForms designer which gets very, very angry if the assemblies are not in the GAC. We had endless issues over and over until we just bit the bullet and put the assemblies in the GAC. Now it works flawlessly. So we are registering our private custom assemblies in the GAC via nuget so it will automatically download and register them, but we have one solution and guarantee that all projects upgrade at the same time.

like image 190
russbishop Avatar answered Oct 12 '22 11:10

russbishop