问题
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.
I've made Async function
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;
...
}
but it seems like it also won't work on .Net Core because it throws
Exception thrown: 'System.InvalidOperationException' in >System.Private.CoreLib.ni.dll
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.
Does someone use CSOM in .Net Core or should I use REST Api instead?
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}
回答1:
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:
- 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
netcore45\Microsoft.SharePoint.Client.Portable.dll netcore45\Microsoft.SharePoint.Client.Runtime.Portable.dll net45\Microsoft.SharePoint.Client.Runtime.Windows.dll netcore45\Microsoft.SharePoint.Client.Runtime.WindowsStore.dll
Oh and if you already have that nuget package do an uninstall-package on it.
来源:https://stackoverflow.com/questions/42186888/using-sharepoint-csom-inside-net-core-application