我也try 在Windows和Android平台上发布.NET Maui应用程序.但我也没能用Visual Studio做到这一点.我所做的是我忽略了Visual Studio,遵循了微软提供的publish .NET MAUI apps using CLI指南
这是我从CLI到publish .NET MAUI Application for Android平台的教程
我相信您将从这些指导方针中准确地解决您的问题,因为这对我的几个.NET Maui项目都有效.
以下是用于Windows自动版本控制和发布的PowerShell脚本
$FilePath = "Platforms/Windows/Package.appxmanifest"
#Load XML Content
$xml = [xml](Get-Content $FilePath)
# Get identity Element
$IdentityElement = $xml.Package.Identity
echo "Your Current Version"
$IdentityElement.Version
echo "________________________"
# Get the current version Number
$version = $IdentityElement.Version.Split(".") | ForEach-Object { [int]$_ }
# Increment values
$response = Read-Host "Do you Update Major Version ? (Y / N) "
if($response -eq "y" -or $response -eq "Y"){
$version[0]++
}
$response = Read-Host "Do you Update Minor Version ? (Y / N) "
if($response -eq "y" -or $response -eq "Y"){
$version[1]++
}
$response = Read-Host "Do you Update Build Number ? (Y / N) "
if($response -eq "y" -or $response -eq "Y"){
$version[2]++
}
$response = Read-Host "Do you Update Revision Number ? (Y / N) "
if($response -eq "y" -or $response -eq "Y"){
$version[3]++
}
# Update version with new one
$IdentityElement.Version = "$($version[0]).$($version[1]).$($version[2]).$($version[3])"
$CLoc = Get-Location
$combined = Join-Path $CLoc $FilePath
# Save the updated xml files
$xml.Save($combined)
$resp = Read-Host "Do you want to build now? (Y/N)"
if($resp -eq "Y" -or $resp -eq "y"){
dotnet publish -f net7.0-windows10.0.19041.0 -c Release
}
Pause
这是适用于Android的PowerShell脚本
$FilePath = "Platforms/Android/AndroidManifest.xml"
$xml = [xml](Get-Content $FilePath)
$currentVersion = $xml.manifest.'versionCode'
$re = Read-Host "Do you wish to increment version number ? (Y / N)";
if($re -eq "Y" -or $re -eq "y"){
$newVersion = [int]$currentVersion + 1
$versionName = Read-Host "Give Version Name : "
$xml.manifest.'versionCode' = $newVersion.ToString()
$xml.manifest.versionName = $versionName.ToString()
}
$CLoc = Get-Location
$combined = Join-Path $CLoc $FilePath
# Save the updated xml files
$xml.Save($combined)
$resp = Read-Host "Do you want to build now? (Y/N)"
if($resp -eq "Y" -or $resp -eq "y"){
dotnet publish -f:net7.0-android -c:Release /p:AndroidSigningKeyPass=[your_pwd] /p:AndroidSigningStorePass=[your_pwd]
}
Pause