【问题标题】:Build and deploy Xamarin to an emulator through command line通过命令行构建并部署 Xamarin 到模拟器
【发布时间】:2019-06-21 14:46:01
【问题描述】:

我正在 Windows 上使用 Visual Studio Community Edition 2019 构建一个 xamarin android 应用程序。在 Visual Studio gui 中,我能够构建并部署到 android 模拟器。我愿意通过命令行在不使用 gui 的情况下执行此操作。我了解 msbuild 可以构建。我可以知道启动模拟器和部署应用程序的命令吗?

【问题讨论】:

  • 也许您可以使用adb install 将.apk 部署到设备
  • 谢谢,它对我有用。我想出了一个脚本,您可以在下面的答案中找到它。如果您有时间,请查看脚本

标签: xamarin


【解决方案1】:

我是初学者批处理脚本编写者。所以随时纠正这个:)。该脚本可用于构建 xamarin Visual Studio 项目、启动模拟器并部署 apk。我有两个批处理文件,第二个与第一个并行运行。

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
)

安装.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

【讨论】:

    【解决方案2】:

    通过命令行构建和部署到 Android 的步骤(将 Sample 替换为您的项目名称):

    1. 在终端/命令行中,运行msbuild Sample.Android/Sample.Android.csproj /verbosity:normal /t:Rebuild /t:PackageForAndroid /t:SignAndroidPackage /p:Configuration=Debug
    2. 然后,使用cd Sample.Android/bin/Debug更改目录以找到签名的APK文件,
    3. 使用ADB(Android Debug Bridge),通过此命令adb install com.tfp.sample-Signed.apkexplained here 将其安装到您的设备/模拟器。

    我又写了一个detailed explanation over here

    【讨论】:

      猜你喜欢
      • 2013-02-27
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      相关资源
      最近更新 更多