[英]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.