简体   繁体   English

.NET Core 2控制台应用程序依存关系在Azure上的问题

[英].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. 我在包括.NET Core控制台应用程序所依赖的程序集时遇到了困难。

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. 最初,即使我可以在Debug模式下运行应用程序而没有任何问题,NuGet程序包中的程序集也不包含在bin文件夹中。

Found an article that suggested that I should add <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> in the myapp.csproj file which I did. 找到了一篇文章,建议我在myapp.csproj文件中添加<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

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. 在将控制台应用程序复制到Azure以作为WebJob运行之后,这样做将bin文件夹中NuGet软件包的dll文件包括在bin文件夹中,但出现错误告诉我System.Data.SqlClient丢失。

After inspecting the folder where the WebJob runs, I could see that the dll for System.Data.SqlClient is actually in the folder. 检查了WebJob所在的文件夹后,我可以看到System.Data.SqlClientdll实际上在该文件夹中。 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 找不到'System.Data.SqlClient'版本:'4.4.2'

When I right click the dll file for this assembly and check its version, it shows version 4.6. 当我右键单击该程序集的dll文件并检查其版本时,它显示版本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/ 我根据本文构建了此.NET Core 2.0控制台应用程序,以作为WebJob运行: 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. 我必须手动创建此WebJobs应用程序,因为当前Visual Studio无法提供在.NET Core中构建Azure WebJobs的方法。

Because of this current limitation, I also could not Publish my WebJobs app directly from Visual Studio. 由于当前的限制,我也无法直接从Visual Studio发布WebJobs应用程序。

So, I tried to zip it up and upload it through Azure Portal. 因此,我尝试将其压缩并通过Azure门户上传。 This is when I realized that NuGet assemblies were not included in the bin folder. 这是我意识到NuGet程序集未包含在bin文件夹中的时候。 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: 当我在项目的根文件夹中运行dotnet publish --self-contained -r win32-x64 -c Release ,出现以下错误: 在此处输入图片说明

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. 不太确定WebJobs规范,但是您应该能够使用dotnet publish --self-contained -r win-x64 -c Release生成可执行文件及其依赖项。 Zip them up and you should be able to deploy to Azure. 压缩它们,您应该可以部署到Azure。

There is really no need to modify your csproj like you did. 确实不需要像您一样修改csproj

Besides, you can use .NET IL Linker to shrink the size of the generated folder. 此外,您可以使用.NET IL Linker缩小生成的文件夹的大小。

Reference 参考

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM