5
votes

So I have been trying to create an APK in Release mode using the MSBuild command line executable.

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.

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" :t/ parameter, but this also fails with the same error:

"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:

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

4

4 Answers

11
votes

Try building the Android csproj file instead of the solution file.

3
votes

This works just fine for me from Visual Studio 2017 and 2019 command line prompts:

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

As already noted, build the csproj not the solution.

3
votes

You can use

/p:AndroidBuildApplicationPackage=true instead of /t:SignAndroidPackage

See Building Process - AndroidBuildApplicationPackage

1
votes

You can build the solution, you will need to specify the project and task in the target e.g:

.WithTarget("DroidAppProj:SignAndroidPackage")

Here is more documentation: Spoiler-it sux if you have a . 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