tags:

views:

227

answers:

2

I am trying to copy files to a remote server, the account I am running my build server doesn't have permissions though. How can I do it using different credentials?

+5  A: 

Try Exec task to execute RunAs.exe which would run the xcopy.exe

zvolkov
and how would you specify that user's password in msbuild?
arconaut
you're right, I forgot RunAs _asks_ for password vs accepting it as a param :(I guess you could do use /savecred but that would require you doing it manually the first time, on the build machine and under the credentials of the build service.
zvolkov
+2  A: 

It's best to create a quick extension of CallTarget task that uses Impersonator by Uwe Keim, like this:

public class Impersonate : CallTarget
{
    [Required]
    public string UserName { get; set; }

    [Required]
    public string Domain { get; set; }

    [Required]
    public string Password { get; set; }

    public override bool Execute()
    {
        using (new Impersonator(this.UserName, this.Domain, this.Password))
        {
            return base.Execute();
        }
    }
}

Then call will look like this:

<Target Name="DoSms">
    <....>
</Target>

<Target Name="Impersonate">
    <Impersonate Targets="DoSms" UserName="username" Password="password" Domain="domain"/>
</Target>
Professor AK