2

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.

UPDATE:

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

Sam
  • 26,817
  • 58
  • 206
  • 383

1 Answers1

1

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.

Reference

https://learn.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli#self-contained-deployment-with-third-party-dependencies

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Thanks for your reply but it didn't work. Getting Project is targeting runtime 'win32-x64' but did not resolve any runtime-specific packages for the 'Microsoft.NETCore.App' package. This runtime may not be supported by .NET Core. error. Put a screen shot in original post. – Sam Dec 31 '17 at 18:02
  • Updated and added the reference. You need to specify `RuntimeIdentifiers`. – Lex Li Dec 31 '17 at 18:16
  • Still doesn't like it. Added `win10-x64;osx.10.11-x64` in the `PropertyGroup` that contains `TargetFramework` and `OutputType`. Then issued `dotnet publish --self-contained -r win32-x64 -c Release` in the root of the project as well as the one level up where the `csproj` file is but still getting the same error. – Sam Dec 31 '17 at 19:17
  • @Sam get started from an empty project as the article indicates first. – Lex Li Dec 31 '17 at 19:19
  • I made a mistake by saying `win32-x64`. It should be `win-x64` if you check the reference. – Lex Li Dec 31 '17 at 21:34
  • This worked! I wasn't crazy about creating a fresh new copy of my app but I did and `dotnet publish --self-contained -r win-x64 -c Release` created a nice `Publish` folder with all the necessary assemblies in it. I uploaded it to Azure and now it's running nicely. Thank you very much! – Sam Dec 31 '17 at 21:40