.NET Core 2 Console App Dependencies Issue on Azure


Short version of the problem:

I'm having difficulties including the assemblies my .NET Core Console App depends on.

Initially, the assemblies from NuGet packages were not included in the bin folder even though I could run the app in Debug mode without any problems.

Found an article that suggested that I should add <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> in the myapp.csproj file which I did.

Doing so included the dll files for the NuGet packages in the bin folder BUT after I copied my console app to Azure to run as a WebJob, I got an error telling me that System.Data.SqlClient was missing.

After inspecting the folder where the WebJob runs, I could see that the dll for System.Data.SqlClient is actually in the folder. I concluded that it may have been an issue with version numbers. The error indicated the following:

'System.Data.SqlClient', version: '4.4.2' was not found

When I right click the dll file for this assembly and check its version, it shows version 4.6.

Any idea how to resolve this issue?

Longer Version:

I built this .NET Core 2.0 console app to run as a WebJob following this article: http://matt-roberts.me/azure-webjobs-in-net-core-2-with-di-and-configuration/

I had to create this WebJobs app manually because currently Visual Studio does not provide a way to build Azure WebJobs in .NET Core.

Because of this current limitation, I also could not Publish my WebJobs app directly from Visual Studio.

So, I tried to zip it up and upload it through Azure Portal. This is when I realized that NuGet assemblies were not included in the bin folder. The rest of the story is already up in the "Short Version" section.

I'd appreciate some suggestion in solving this issue.


When I ran dotnet publish --self-contained -r win32-x64 -c Release inside the project's root folder, I got the following error: enter image description here


Not quite sure of the WebJobs specification, but you should be able to use dotnet publish --self-contained -r win-x64 -c Release to generate executable and its dependencies. Zip them up and you should be able to deploy to Azure.

There is really no need to modify your csproj like you did.

Besides, you can use .NET IL Linker to shrink the size of the generated folder.