1

I'm moving NuGet packages to may local network folder with this command

move-Item xyz.nupkg -Dest $env:nugetsDir

I have a problem in that the file is not inheriting permission from destination folder and my friend is getting "access denied" error when trying to use my package. The problem is NOT occurring when and move the file manually, with mouse.

Pawcio
  • 399
  • 5
  • 15
  • Better use robocopy for this. – f6a4 Jan 13 '20 at 12:31
  • 2
    If you use copy-item the permissions on the file will inherit from the parent folder. Move-item will maintain the permissions of the origianl location of the file. This is not a powershell issue, it is normal NTFS behaviour. – Shamus Berube Jan 13 '20 at 13:12

1 Answers1

0

I found Robocopy unintuitive, so I created custom program based on this solution.

using System.IO;
using cnc.console.options;
using System.Security.AccessControl;

namespace FilesMove {
    class Program {

        //...

        static void Main(string[] args) {   
            ops.parseArguments(args);
            var src = ops.get<SourceOption>(0);
            var dst = ops.get<DestinationOption>(0);
            var dstFile = Path.Combine(dst, Path.GetFileName(src));
            File.Move(src, dstFile);

            if (ops.isSet<InheritPermissionsOption>()) {
                var outAcc = new FileSecurity();
                outAcc.SetAccessRuleProtection(false, false);
                File.SetAccessControl(dstFile, outAcc);
            }
        }

    }
}
Pawcio
  • 399
  • 5
  • 15