Automating deploy using Msbuild

Asked

Viewed 181 times

1

I’m creating a bat to compile and publish a Visual Studio project using MSBuild.

However, I need to inform a user and password for the MSBuild. What I am doing, is to solitar in the bat the user and password. However, I would not like to see the password when typing in cmd. Basically it would be as it is already the net use that when necessary it asks user and password.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

@echo off
set /p username="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 @rray’s reply 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 Studio\2017\Community\MSBuild\15.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
  • Can use powershell?

  • Yeah, I’d just have to rewrite using the powershell

1 answer

1


An alternative with powershell is to request the input value to add the argument -AsSecureString. Testing on ISE will open an input box but as a script the characters will be replaced by asterisks.

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?

  • I’ll test it here

  • With the powershell, what would the call to Msbuild look like?

  • 1

    @PabloTondolodeVargas https://stackoverflow.com/a/871605

  • I edited my question with your suggestions, I managed to call Msbuild, only the password is not going correctly.

  • I found my mistake and the solution, thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.