Running dotnet publish after dotnet build doesn't sign apk using keystore
- Dominant language
- C#
- Stars
- 2.1k
- Forks
- 579
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 252
Description
### Android application type
.NET Android (net7.0-android, etc.)
### Affected platform version
.NET 8 RC2 / .NET 7, MacOS Ventura 13.5.2
### Description
I noticed that when using `dotnet publish` after having issued the `dotnet build` command, will ignore the provided keystore information in the `dotnet publish` command, which seemed kinda counterintuitive. Reason why I'm using `dotnet build` first is to ensure that everything actually compiles, then subsequently run all unit tests, and if all those are successful, we create the actual signed apk.
However... when doing so while having more verbose logs, I get informed that the `_sign` build target was a no-op. See screenshot below.
### Steps to Reproduce
1. Download this zip => [SigningIssueReproApp.zip](https://github.com/xamarin/xamarin-android/files/13219649/SigningIssueReproApp.zip) (it's pretty much a new android application, but is easier to follow with the commands used below)
2. Optional: Create new keystore (see docs https://learn.microsoft.com/en-us/dotnet/maui/android/deployment/publish-cli#create-a-keystore-file), there's one already included in the zip to make things easier
3. Open terminal at the root of the repository and run `dotnet restore`
4. Run `dotnet build source/SigningIssueReproApp/SigningIssueReproApp.csproj --configuration Release --no-restore`
(generated apk gets signed by a debug.keystore)
5. Run `dotnet publish source/SigningIssueReproApp/SigningIssueReproApp.csproj --configuration Release --no-restore --output artifacts/ /property:AndroidKeyStore=True /property:AndroidSigningKeyStore=/Users/jens/Documents/Projects/SigningIssueReproApp/deploy/myapp.keystore /property:AndroidSigningKeyAlias=myapp /property:AndroidSigningKeyPass=password /property:AndroidSigningStorePass=password` (make sure to adjust the path to the keystore as the CLI apparently somehow requires an absolute path to that file)
6. Use keytool to check the certificate that was used to sign the apk in the newly created 'artifacts' directory and observe that our self-provided keystore wasn't used.
### Did you find any workaround?
A workaround that was provided to me by a colleague, which isn't exactly clean to me, is to also provide all the keystore information to `dotnet build`. I'm currently not aware about any other possible workarounds that work.
### Relevant log output
```shell
1>Target "_Sign" in file "/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets" from project "/Users/jens/Documents/Projects/SigningIssueReproApp/source/SigningIssueReproApp/SigningIssueReproApp.csproj" (target "Build" depends on it):
Skipping target "_Sign" because all output files are up-to-date with respect to the input files.
Input files:
/Users/jens/Documents/Projects/SigningIssueReproApp/source/SigningIssueReproApp/obj/SigningIssueReproApp.csproj.nuget.g.targets
/usr/local/share/dotnet/sdk/8.0.100-rc.2.23502.2/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets
obj/Release/net7.0-android/build.props
obj/Release/net7.0-android/android/bin/com.companyname.SigningIssueReproApp.apk
Output files: bin/Release/net7.0-android/com.companyname.SigningIssueReproApp-Signed.apk
1>Done building target "_Sign" in project "SigningIssueReproApp.csproj".
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.