发布到 Azure 应用服务后无法加载文件或程序集

Could not load file or assembly after publishing to Azure app service

我在 运行我的应用程序(发布在 Azure 应用程序服务上:

时突然看到这个错误

Could not load file or assembly 'Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified. at SharePointLibrary.SPClient.GetAllUsers() at ADVWKSP.Managers.UserManager.GetUsers() in C:\Users\bassie\source\repos\TFS\ADVWKSP\ADVWKSP\Managers\UserManager.cs:line 21

它在我的机器上 运行 没问题,以前在发布后 运行 没问题,但现在它突然开始抱怨这个文件丢失了。

我检查了 Kudu,我只能看到 SharePoint.Client.Runtime:

为什么?我如何确保所有必需的库都与项目一起发布。为什么这突然停止工作?

azure web app 的托管环境包含 .Net framework 2.0.Net framework 4.5 的标准安装。

如果您的应用程序引用了不是在 .Net 框架中构建的程序集,您必须 "include" them with your deploy package。 即使这些都是 Microsoft 程序集。

将引用程序集的 复制本地 属性 设置为 True 可能会修复它。

1.In 解决方案资源管理器找到您的项目对库的引用。

2.Right 单击并选择属性。

3.In 属性 window 将 Copy Local 设置为 True。

正如您所说,它可以在 IIS Express 上本地运行,请尝试将您的网站内容手动部署到 Azure ,看看它是否可以运行。

添加以下参数

/deployonbuild=false

到 msbuild 命令行解决了这个问题。