在 .Net Core 应用程序中使用 SharePoint CSOM

Fr3*_*c3l 5 .net sharepoint asp.net-core

我想通过 .Net Core MVC 应用程序上的 CSOM 库从 SharePoint 列表中获取数据。在 .Net Framework 应用程序上实现这一点绝对没有问题,因为 Microsoft.SharePoint.Client 库包含 ExecuteQuery 方法。不幸的是 .Net Core 不是。

我已经做了异步功能

public async Task<ActionResult> GetRequests()
    {
        ClientContext context = new ClientContext("https://xxx/sites/xxx/");
        List certificatesList = context.Web.Lists.GetByTitle("Items");
        CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
        ListItemCollection items = certificatesList.GetItems(query);
        context.Load(items);
        Task spTask = context.ExecuteQueryAsync();
        await Task.WhenAll(spTask);
        var result = items;
        ...

    }
Run Code Online (Sandbox Code Playgroud)

但它似乎也不适用于 .Net Core,因为它会抛出

抛出异常:>System.Private.CoreLib.ni.dll 中的“System.InvalidOperationException”

附加信息:找不到平台服务库。对于 Windows Store 应用程序,请在应用程序包中包含 Microsoft.SharePoint.Client.Runtime.WindowsStore.dll。对于 Windows Phone 应用程序,请在应用程序包中包含 Microsoft.SharePoint.Client.Runtime.WindowsPhone.dll。对于 Windows 应用程序,请在 GAC(全局程序集缓存)中安装 Microsoft.SharePoint.Client.Runtime.Windows.dll 或使其可用于 Windows 应用程序。

有人在 .Net Core 中使用 CSOM 还是我应该使用 REST Api?

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  }
Run Code Online (Sandbox Code Playgroud)

小智 0

我有这个问题。由于某种原因,当您引用 Microsoft.SharePointOnline.CSOM nuget 包时,它使用 .net Framework dll 而不是 netcore45 dll。以下是我为解决此问题所做的操作:

  1. 下载nuget包https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/
  2. 将其解压到项目中的子文件夹中,例如;依赖关系
  3. 引用正确的程序集

    netcore45\Microsoft.SharePoint.Client.Portable.dll netcore45\Microsoft.SharePoint.Client.Runtime.Portable.dll netcore45\Microsoft.SharePoint.Client.Runtime.Windows.dll netcore45\Microsoft.SharePoint.Client.Runtime.WindowsStore.dll

哦,如果你已经有那个 nuget 包,请对其进行卸载包。