Deploying ASP.NET Core to App Service on Linux

When you attempt to deploy an ASP.NET Core project to App Service on Linux, you may run into an error during the build process – Object reference not set to an instance of an object. When you try to deploy the project to App Service on Windows, everything works, so where is the issue?

So apparently, when you include a Solution (.sln) file with your project, Kudu is going to have a hard time to parse it on App Service on Linux since it requires to load some assemblies to parse the .sln, however those are not present on ASL yet. There are multiple ways to go around this:

You can either remove the .sln file from the whole repository, which will result in the build to succeed, the application will deploy and we are safe and sound, however, it will be harder to use Visual Studio, since it kind of requires the solution file to be present.

If you don’t want to do that, you can include a custom deployment script with your code by adding a .deployment file into the project’s root and specifying the deployment script in it:

Then you need to also include the script along with the .deployment file, the script can look like this (this is what gets autogenerated when you don’t include the solution file, don’t forget to rename the WebApplication1 to your .csproj):

And last, but not least, you can build the source code somewhere else, like in Visual Studio Team Services, and then just publish it to he App Service on Linux.

Additionally, it is quite important to mention, that you will need to set the startup command for the container in order for the application to start successfully, else it is going to attempt searching for .csproj in the root, which it won’t be able to find and therefore the container will keep crashing (you will see it in the logs). The startup command will look like this: dotnet /home/site/wwwroot/WebApplication1.dll


Author: Jan Hajek

I am Honza, hi.

3 thoughts on “Deploying ASP.NET Core to App Service on Linux”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.