Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top