How do I tell Web Deploy to exclude a particular DLL file from a web deployment package?
This answer https://stackoverflow.com/a/27404527 offers the advice to exclude the DB2 database driver IBM.Data.DB2.dll from the bin folder of a web application. Otherwise you get an BadImageFormatException in IIS because Visual Studio package the wrong version of the DLL with the web app. I just ran into this issue and tried to follow the advice.
Unfortunately I could not convice Web Deploy to omit this particular DLL. I read this blog post
and added this
<ItemGroup>
<ExcludeFromPackageFiles Include="$(OutputPath)IBM.Data.DB2.dll">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
but without success. I can still find the DB driver unter _PublishedWebsites\MyWebApp\bin\IBM.Data.DB2.dll in the Binaries folder.
I tried to address my issue again after some time and now it works. Here is the solution. I put it in a file called projectname.wpp.targets alongside the project definition file projectname.csproj.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExcludeFromPackageFiles Include="bin\IBM.Data.DB2.dll">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
</Project>