Automating deploy using MSBuild

1

I'm creating a batch to compile and publish a Visual Studio project using MSBuild .

However, I need to enter a username and password for MSBuild . What I'm doing, is solitaire in bat the user and password. However, I would not like to see the password when typing in cmd. Basically it would be like already net use that when required it prompts the user and password.

@echooffset/pusername="UserName: "
set /p password="Password: "
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe Syns.sln /p:Configuration=Produção;DeployOnBuild=true;PublishProfile=prod.pubxml /MaxCpuCount:8 /p:AllowUntrustedCertificate=True /p:UserName=%username% /p:Password=%password%

Following the @rray response I rewrote the script using powershell, now I can get the password in a more secure way

Write-Host "UserName:"
$username = Read-Host

Write-Host "Password:"
$password = Read-Host -AsSecureString
$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))


$msbuild = "C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild.0\Bin\MSBuild.exe"
$collectionOfArgs = @("D:\Projetos\Syns\Syns\Syns.sln", 
                      "/p:Configuration=Prod;DeployOnBuild=true;PublishProfile=prod.pubxml", 
                      "/MaxCpuCount:8", 
                      "/p:AllowUntrustedCertificate=True", 
                      "/p:UserName=$username", 
                      "/p:Password=$password")

& $msbuild $collectionOfArgs
    
asked by anonymous 29.11.2017 / 18:28

1 answer

1

An alternative to powershell is when you request the input value to add the -AsSecureString argument. When testing test in ISE will open an inbox but as a script the characters will be replaced by asterics.

Write-Host "Informe sua senha:"
$senhaCodificada = Read-Host -AsSecureString
$senhaTextoPuro = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($senhaCodificada))

Based on:

Powershell SecureString Encrypt / Decrypt To Plain Text Not Working

How can I use powershell's read-host function to accept a password for an external service?

    
29.11.2017 / 18:45