简体   繁体   中英

MSBuild Extension Pack: Credentials for File/Folder tasks?

Good afternoon,

say is it possible to provide credentials (username/pw) for file or folder activities (eg removecontent) with the MSBuild Extension Pack? As in.. the build user is not necessary the one I want to use to deleted/work with on certain folders/files I need to modify/delete (eg remotely on UNC shares).

Is this doable? I am somewhat lost :-/

Cheers and thanks,

-J

RemoveContent task and the other folder tasks of MSBuild Extension pack use DirectoryInfo internally.

To access remote folder DirectoryInfo handles UNC path , the problem is that you can't put the credential in a UNC path . So you can't do what you want directly using only RemoveContent task.

Workarounds :

  • The simple one : Give the right to your build agent
  • The better : Map the folder to a network drive and use this network drive in your MSBuild task. This can be done with MSBuild Exec task and net command

     <Target Name="MapAndRemove"> <!-- Map the remote folder with credential --> <Exec Command="net use Z: \\\\ServerName\\ShareName\\YourFolder {Password} /user:{User} /yes"/> <!-- Remove content in remote folder using network drive --> <MSBuild.ExtensionPack.FileSystem.Folder TaskAction="RemoveContent" Path="Z:\\"/> </Target> 
  • The harder : Write a MSBuild custom task doing what you want and that takes credential as parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM