简体   繁体   English

使用 MSBuild 命令行错误创建 APK(PackageForAndroid 或 SignAndroidPackage)

[英]Creating an APK using MSBuild command line error (PackageForAndroid or SignAndroidPackage)

So I have been trying to create an APK in Release mode using the MSBuild command line executable.所以我一直在尝试使用 MSBuild 命令行可执行文件在发布模式下创建一个 APK。

Here is the contents of my batch file which I created:这是我创建的批处理文件的内容:

ECHO Building DsdMobile Solution... >CON
cd "C:\Ross\DEVELOPMENT\HANDHELD\Android\Dsd Mobile MaterialDesign"

"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" DsdMobile.sln /P:Configuration=Release /v:quiet /t:Clean /nologo

"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" DsdMobile.sln /P:Configuration=Release /v:quiet /t:Rebuild,PackageForAndroid /nologo

The first line I change the directory to my solution location.第一行我将目录更改为我的解决方案位置。 Next, I do a Clean接下来,我做一个清洁

Last, I do a Rebuild and PackageForAndroid (which I am expecting a...apk file in my bin release folder. An apk is never created and I get an error.最后,我做了一个 Rebuild 和 PackageForAndroid(我希望在我的 bin 发布文件夹中有一个...apk 文件。一个 apk 从未创建,我得到一个错误。

The build is successful, but I get an error:构建成功,但出现错误:

"C:Ross\Development\Handheld\Android\Dsd Mobile MaterialDesign\DsdMobile.sln.metaproj : error MSB4057: The target "PackageForAndroid" does not exists in the project. [C:\Ross\DEVELOPMENT\HANDHELD\Android\Dsd Mobile MaterialDesign\DsdMobile.sln]

I have also tried to use SignAndroidPackage 's :t/ parameter, but this also fails with the same error:我也尝试过使用SignAndroidPackage:t/参数,但这也失败并出现相同的错误:

"C:Ross\Development\Handheld\Android\Dsd Mobile MaterialDesign\DsdMobile.sln.metaproj : error MSB4057: The target "SignAndroidPackage" does not exists in the project. [C:\Ross\DEVELOPMENT\HANDHELD\Android\Dsd Mobile MaterialDesign\DsdMobile.sln]

The resource I have been using was from a PowerShell script:我一直在使用的资源来自 PowerShell 脚本:

https://gist.github.com/postb99/8319234 https://gist.github.com/postb99/8319234

尝试构建Android csproj文件而不是解决方案文件。

You can build the solution, you will need to specify the project and task in the target eg: 您可以构建解决方案,需要在目标中指定项目和任务,例如:

.WithTarget("DroidAppProj:SignAndroidPackage")

Here is more documentation: Spoiler-it sux if you have a . 这是更多文档:Spoiler-it sux(如果有)。 in your project name: https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe?view=vs-2017 在您的项目名称中: https : //docs.microsoft.com/zh-cn/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe?view=vs-2017

This works just fine for me from Visual Studio 2017 and 2019 command line prompts: 在Visual Studio 2017和2019命令行提示符下,这对我来说很好用:

msbuild /t:SignAndroidPackage /p:Configuration=Release Application.Android.csproj

As already noted, build the csproj not the solution. 如前所述,构建csproj而不是解决方案。

You can use 您可以使用

/p:AndroidBuildApplicationPackage=true instead of /t:SignAndroidPackage /p:AndroidBuildApplicationPackage=true而不是/t:SignAndroidPackage

See Building Process - AndroidBuildApplicationPackage 请参阅构建过程-AndroidBuildApplicationPackage

If you want to build the.sln rather than the.csproj, from the command line, you can do /t:MyAndroidProject:SignAndroidPackage where "MyAndroidProject" == the name of your Android project.如果要从命令行构建 .sln 而不是 .csproj,可以执行/t:MyAndroidProject:SignAndroidPackage ,其中“MyAndroidProject”== Android 项目的名称。

That will apply the target only to the specified csproj rather than trying to execute the target on every solution in the project.这会将目标仅应用于指定的 csproj,而不是尝试在项目中的每个解决方案上执行目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从命令行构建时,MSBuild警告MSB3884 - MSBuild Warning MSB3884 when building from command line msbuild命令行尚不支持WebPublishMethod(FileSystem) - WebPublishMethod(FileSystem) is not yet supported on msbuild command line Visual Studio生成解决方案,但命令行中的MSBuild失败 - Visual Studio builds solution but MSBuild from the command line fails 使用 Microsoft Azure 逻辑应用企业集成工具的 MSBuild 错误 - MSBuild error using Microsoft Azure Logic Apps Enterprise Integration Tools 从命令行MSBuild,但没有app_offline.htm? - MSBuild from command line, but no app_offline.htm? MSBuild退出,出现代码1错误 - MSBuild exited with code 1 error MSBuild:错误 MSB3073 命令“setlocal VCEnd”以代码 1 退出 - MSBuild: error MSB3073 The command 'setlocal VCEnd' exited with code 1 MSBuild SonarQube Runner:“无法找到代码覆盖率命令行工具”仍然使用版本1.0.1 - MSBuild SonarQube Runner: “Failed to locate the code coverage command line tool” still with version 1.0.1 如何从命令行使用 MSBuild VS2015 构建所有配置? - How can I build all configurations with MSBuild VS2015 from the command line? Msbuild.exe中的静态枚举类出错 - Error in Msbuild.exe for static enum class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM