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.
@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?
– rray
Yeah, I’d just have to rewrite using the powershell
– Pablo Tondolo de Vargas