Adding “unknown” file types to your publication package

I’ve been making some updates to a web services project recently (I say recently it was actually months ago but for some reason I haven’t managed to publish this post until now) and the time has come to deploy it to a test environment.  This in itself brought a few challenges but the one that I want to discuss just now is the issue of including unknown file types in your publication package. I’ve tagged these as unknown as they’re files that Visual Studio seems to ignore when you elect to publish your project.  The frustrating thing is that you can set these files to be output when you build your project but when you publish your project they are nowhere to be seen.

In the scenario that I found myself in the files were .lic (licence) files.  The project I was working on used a couple of third party dlls which required their licence files to be present within /bin/Licenses in order for them to work, and no matter what I tried I couldn’t get these files to be included within the published directory.  After what felt like an eternity searching Google for help and trying out a huge number of incorrect suggestions I eventually found what I was looking for and thought I would store the answer here, in my blog, for future reference.  Unfortunately I now can’t find the page I found the solution on otherwise I would have linked to it from here so if the original author happens across this post then I apologise in advance for not giving you credit.

Anyway, for clarity, my project bin directory looks like this in Visual Studio (licence file names excluded to protect the innocent):

Image showing bin directory in Visual Studio 2013

Now, I’d normally never do anything like this with the bin directory, instead preferring to reference third-party dlls from a solution level folder so that they can be checked into my source control provider, included within as many of my solution’s projects as required, automatically included in the bin folder at compilation time and made freely available to any other developers that need to work on the application at the same time as me.



Here’s how to include these unknown file types in your publication package:

Navigate to the <system.web><compilation> section of your web.config file and add the following block of XML tailored to suit your needs:

<!-- This section is required to ensure the contents of the bin/Licenses folder get included in the publish-->
<remove extension=".lic"/>
<add extension=".lic" type="System.Web.Compilation.ForceCopyBuildProvider" />

The ForeCopyBuildProvider argument will (as you would expect) force copy any files with a .lic (or whatever you specify) extension into your publish package.

Hopefully this will be of some use to some of you and as always, comments are welcome.