如何在.NET Core中修改文件访问控制

我正在尝试更改.NET Core中文件的权限。 但是,似乎FileInfo不再具有任何SetAccessControl

 // Create a new FileInfo object. FileInfo fInfo = new FileInfo(FileName); // Get a FileSecurity object that represents the // current security settings. FileSecurity fSecurity = fInfo.GetAccessControl(); // Add the FileSystemAccessRule to the security settings. fSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType)); // Set the new access settings. fInfo.SetAccessControl(fSecurity); 

目标只是将执行权添加到文件的当前所有者(不是Windows或Unix特定function)。

有关如何在.NET Core上执行此操作的任何线索?

FileSecurity类现在是.NET Core的System.IO.FileSystem.AccessControl包的一部分。 不再有File.GetAccessControl方法,因此您需要自己实例化FileSecurity实例。