问题描述
我想通过 .Net Core MVC 应用程序上的 CSOM 库从 SharePoint 列表中获取数据.在 .Net Framework 应用程序上实现这一点绝对没有问题,因为 Microsoft.SharePoint.Client 库包含 ExecuteQuery 方法.不幸的是 .Net Core 不等价.
I want to get data from SharePoint list by CSOM library on .Net Core MVC application. There are absolutely no problem to achieve that on .Net Framework aplication because Microsoft.SharePoint.Client library contains ExecuteQuery method. Unfortunately .Net Core equivalent not.
我已经实现了异步功能
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;
...
}
但它似乎也不适用于 .Net Core,因为它会抛出
but it seems like it also won't work on .Net Core because it throws
抛出异常:>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 应用程序.
Additional information: Cannot find platform service library. For Windows Store application, please include Microsoft.SharePoint.Client.Runtime.WindowsStore.dll in the application package. For Windows Phone application, please include Microsoft.SharePoint.Client.Runtime.WindowsPhone.dll in the application package. For Windows application, please install Microsoft.SharePoint.Client.Runtime.Windows.dll in the GAC (Global Assembly Cache) or make it available for the Windows application.
有人在 .Net Core 中使用 CSOM 还是我应该改用 REST Api?
Does someone use CSOM in .Net Core or should I use REST Api instead?
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}
推荐答案
我遇到了这个问题.出于某种原因,当您引用 Microsoft.SharePointOnline.CSOM nuget 包时,它使用了 .net 框架 dll 而不是 netcore45 dll.这是我为解决此问题所做的工作:
I had this issue. For some reason when you reference the Microsoft.SharePointOnline.CSOM nuget package it used the .net framework dlls rather than the netcore45 dlls.Here's what I did to work around this:
- 下载 nuget 包 https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/
- 将其解压缩到项目中的子文件夹中,例如;依赖
引用正确的程序集
- Download the nuget package https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/
- Extract it to a subfolder in your project eg; Dependencies
Reference the correct assemblies
netcore45Microsoft.SharePoint.Client.Portable.dllnetcore45Microsoft.SharePoint.Client.Runtime.Portable.dllnet45Microsoft.SharePoint.Client.Runtime.Windows.dllnetcore45Microsoft.SharePoint.Client.Runtime.WindowsStore.dll
netcore45Microsoft.SharePoint.Client.Portable.dllnetcore45Microsoft.SharePoint.Client.Runtime.Portable.dllnet45Microsoft.SharePoint.Client.Runtime.Windows.dllnetcore45Microsoft.SharePoint.Client.Runtime.WindowsStore.dll
哦,如果你已经有了那个 nuget 包,在它上面做一个卸载包.
Oh and if you already have that nuget package do an uninstall-package on it.
这篇关于在 .Net Core 应用程序中使用 SharePoint CSOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!