Managing binary dependencies in .NET can be a complicated task. For small projects, checking the dependencies into source control tends to work just fine. So does requesting that all developers have various binaries available in their GAC. Grow much bigger, or add more projects, and managing that starts to get very difficult.
The Java world has had a solution to this problem for a long time, in the form of Maven and Ivy. Remote servers store the binaries, and the build tool automatically downloads them on demand. WebGAC adds this functionality to .NET, but without requiring you to switch build tools, or maintain a separate configuration file. Dependencies are specified just the same way as normal, but if you don't have them when building your project, WebGAC will fetch them for you automatically.
WebGAC requires a remote server that support WebDAV to store dependencies. Whilst this may sound like a big requirement, it is actually just a few lines of configuration for a standard Apache web server.
- Install an Apache web server somewhere
- In your apache.conf file, create a virtual directory called "webgac" (note that you can use any name for
this directory - these instructions just call it this for the sake of simplicity). The configuration for
this virtual directory should look something like:
DavLockDB /usr/local/apache2/var/DavLock <Location /webgac> Dav On </Location>
- Ensure that within your web root, the directory webgac exists and is accessible by the user running Apache
- Restart Apache
- WARNING: At this stage, you've configured an open read/write Apache DAV server. This means that anyone with access to your server can read and write files. For anything more than local experimentation (hopefully behind a firewall), please refer to the mod_dav documentation for details on securing the server. The WebGAC client by default supports Basic authentication, so it is recommended to enable this.
- Download the latest installer from the Downloads section.
- Run the installer
- Load Visual Studio, and select Tools -> Configure WebGAC...
- Select Add, and enter the address of your new WebGAC server, such as http://localhost/webgac
- Ok the changes
To make a binary available via the WebGAC, you'll need to upload the file. In this example, we'll walk through publishing the nunit.framework.dll file via WebGAC.
- Download the NUnit binaries
- In Visual Studio, select Tools -> Browse WebGAC...
- Click "Upload..."
- Click the ellipsis next to the file entry box, and select the nunit.framework.dll file.
- Click "Upload"
Each project file that uses the WebGAC needs to have an additional set of MSBuild targets enabled to activate
WebGAC functionality. To do this, open your .csproj file in a text editor, and underneath the line
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />, add a new line that
<Import Project="$(MSBuildExtensionsPath)\WebGAC\WebGAC.targets" />. Reload the project in Visual Studio.
Finally, you can start enjoying the WebGAC.
- Right click on your project in the Visual Studio Solution Explorer, and select "Add WebGAC Reference..."
- In the dialog that appears, nunit.framework should appear. Expand the node, and select the version.
- Click "Add"
- The reference should be added to your project, and it should be ready to use!