I’m building a xamarin android app using visual studio community edition 2019 on windows. Inside visual studio gui I am able to build and deploy to android emulator. I’m willing to do this without using the gui, through command line . I understand msbuild can build. May I know the command to start the emulator and deploy the app?
            Asked
            
        
        
            Active
            
        
            Viewed 3,153 times
        
    1
            
            
        - 
                    1maybe you could use `adb install` to deploy .apk to the device – Leo Zhu Jun 24 '19 at 02:35
- 
                    Thank you, it worked for me. I came up with a script which you could find below in my answer. If you find time, please review the script – Ram Jun 24 '19 at 11:50
2 Answers
2
            
            
        Steps to Build & Deploy to Android through the command line (replace Sample with your project name):
- In your terminal/command line, run this msbuild Sample.Android/Sample.Android.csproj /verbosity:normal /t:Rebuild /t:PackageForAndroid /t:SignAndroidPackage /p:Configuration=Debug
- Then, change directory using cd Sample.Android/bin/Debugto find the the signed APK file,
- Using ADB(Android Debug Bridge), install it to your device/emulator with this command adb install com.tfp.sample-Signed.apk, explained here.
I have written a more detailed explanation over here.
 
    
    
        Saamer
        
- 4,687
- 1
- 13
- 55
0
            
            
        I'm a beginner batch scrip writer. So feel free to correct this:). This scripts work for me to build the xamarin visual studio project, start the emulator and deploy the apk. I have two batch files, the second one runs in parallel with the first one.
cmd.bat:
"C:\Program Files\Android\android-sdk\platform-tools\adb.exe" start-server
"C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" /p:Configuration=Debug /p:Platform="any cpu" /v:m "E:\App2\App2.sln"
@echo off
if %ERRORLEVEL%% == 0 (
start /min call "E:\App2\Build Commands\install.bat" ""
"C:\Program Files\Android\android-sdk\emulator\emulator.EXE" -no-boot-anim -avd lollypop -prop monodroid.avdname=lollypop
exit
) else (
pause
)
install.bat:
"C:\Program Files\Android\android-sdk\platform-tools\adb.exe" wait-for-device
"C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" -r /t:Install /v:m "E:\App2\App2.Android\App2.Android.csproj" /p:AdbTarget=-e
@echo off
if %ERRORLEVEL% == 0 exit else pause
 
    
    
        Ram
        
- 44
- 1
- 13