我正在将一个库从.NET Framework 4.6.1移植到.NET Standard 2.0中。在框架中, NamedPipeServerStream
构造函数可以取一个 PipeSecurity
参数,但这在 Core 中不是一个选项。如何设置 NamedPipeServerStream
在核心中?
显然,这是一个已知的问题System.IO.Pipes.AccessControl包不工作 #26869. 在上一篇文章中提到了一个变通方法,建议使用 NamedPipeServerStream.NetFrameworkVersion。 nuget包,它将暴露 NamedPipeServerStreamConstructors.New(...)
它应该反映所有完整的.NET框架构造函数的行为。
下面是一个来自nuget的代码示例。github
using System.IO.Pipes;
var pipeSecurity = new PipeSecurity();
pipeSecurity.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
using var serverStream = NamedPipeServerStreamConstructors.New(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity);