开发者

MSBuild Extension Pack: Credentials for File/Folder tasks?

Good afternoon,

say is it possible to provide credentials (username/pw) for file or folder activities (e.g. removecontent) with the MSBuild Extensi开发者_Go百科on 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 (e.g. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜