Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

Git Deploy to Azure Web App While Keeping Assemblies out of Version Control

Tags: git, git-deploy, azure, website, web-app

Visual Studio -> GitHub -> Azure Web App

How do we keep all assemblies (dll files) and other build results out of version control?

Sure, we can do this...

git rm --cached *.dll
git rm --cached bin\*
git rm --cached obj\*

...but it might cause a few problems.

error MSB3030: Could not copy the file someFile.dll because it was not found.

That's because we ran git rm --cached *.dll, which means that any assemblies that we need to deploy are still going to be part of the project without being deployed to Azure.

To fix that, we could exclude any *.dll files from our *.csproj. The problem though is that we need to reference these assemblies, they aren't part of the framework, and NuGet doesn't handle them appropriately.

Don't Do This:

Exclude From Project

If we did do that, we might receive an error similar to this, because the Azure Web App is missing the assemblies that we excluded from the project.

Server Error in '/' Application.

Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8876. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlServerCe.SqlCeException: Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8876. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.

That's happening because we have an assembly on our local machine, that we've excluded from version control and excluded from our project. The Azure Web App needs it.

To resolve this, look at the location of each assembly that the *.csproj references. If we're using Visual Studio, here's how.

  1. Open the Solution Explorer.
  2. Expand the References node.
  3. Press F4 to open the Properties Window.
  4. Click through all the references to see the path of each.

Here are some examples. Ideally, we can have NuGet handle most if not all of them.

NuGet handles this assembly.

We know because the Path points to the packages directory. We don't have to add it to version control.

NuGet handles it.

The framework handles this assembly.

We don't have to add it to version control, because it's in \Reference Assemblies\Microsoft\Framework\...

The Framework handles it.

We must handle these.

NuGet doesn't add these to the packages directory nor framework doesn't contain these. So, we need to add them to our version control, include them in our csproj, and set the properties to

Build Action: None
Copy to Output Directory: Do Not Copy

We must add these assemblies to version control.

The result, oddly enough is to add the assembly to the bin on build.

Build Action:None Result

Now, our repository does contain some assemblies, and there doesn't seem to be any way around this. If you know a way to keep assemblies out of the repository in situation like that, please chat me up on Twitter.