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