Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/building-apps/build-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ The following metadata is set:
* `IsDirectory`: `true` for `.app` and `.xcarchive` outputs; `false` for `.ipa` and `.pkg` outputs.
* `PlatformName`: The Apple platform name, such as `iOS`, `tvOS`, `macOS`, or `MacCatalyst`.
* `BundleIdentifier`: The resolved app bundle identifier.
* `ApplicationId`: The resolved app bundle identifier.
* `ApplicationTitle`: The final `CFBundleDisplayName` value.
* `ApplicationName`: The final `CFBundleDisplayName` value, falling back to `CFBundleName` when `CFBundleDisplayName` isn't set.
* `ApplicationDisplayVersion`: The final `CFBundleShortVersionString` value.
* `ApplicationVersion`: The final `CFBundleVersion` value.

The shared application metadata is read from the compiled app bundle
`Info.plist`, so values supplied by a custom manifest take precedence over
single-project properties. Values that are resolved or localized by Apple at a
later stage are returned as written in the compiled manifest; the build does
not choose a locale.

Example:

Expand Down
8 changes: 4 additions & 4 deletions docs/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,10 @@ A semi-colon delimited property that can be used to extend the
the platform build has collected `@(ApplicationArtifact)` items and before
`GetApplicationArtifacts` or `Publish` returns them.

This can be used by SDKs such as .NET MAUI to add shared application metadata
to platform-produced artifacts. Extension targets should update existing
`@(ApplicationArtifact)` items to add metadata; they should only add new items
when introducing additional artifacts.
Apple platform builds populate the common application metadata documented for
[ApplicationArtifact](build-items.md#applicationartifact) before targets in
this property execute. Extension targets can update or override that metadata,
and should only add new items when introducing additional artifacts.

Example:

Expand Down
6 changes: 6 additions & 0 deletions dotnet/SingleProject.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Info.plist in the project doesn't already contain entries for these keys):
This is only enabled if the `GenerateApplicationManifest` is set to `true`
(which is the default for all supported .NET versions)

Final application outputs expose these values as common metadata on
`@(ApplicationArtifact)`. The metadata is read back from the compiled
`Info.plist`, so explicit values in a custom manifest win even when the
corresponding single-project properties are set. `ApplicationName` uses
`CFBundleDisplayName` when present and otherwise falls back to `CFBundleName`.

Additionally, `$(ApplicationDisplayVersion)` will overwrite the value for `$(Version)`,
so the following properties will be set with the same value:

Expand Down
8 changes: 8 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/ReadAppManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ public class ReadAppManifest : XamarinTask, ITaskCallback {
[Output]
public string? CFBundleDisplayName { get; set; }

[Output]
public string? CFBundleName { get; set; }

[Output]
public string? CFBundleIdentifier { get; set; }

[Output]
public string? CFBundleShortVersionString { get; set; }

[Output]
public string? CFBundleVersion { get; set; }

Expand Down Expand Up @@ -65,7 +71,9 @@ public override bool Execute ()

CFBundleExecutable = plist.GetCFBundleExecutable ();
CFBundleDisplayName = plist?.GetCFBundleDisplayName ();
CFBundleName = plist?.GetCFBundleName ();
CFBundleIdentifier = plist?.GetCFBundleIdentifier ();
CFBundleShortVersionString = plist?.GetCFBundleShortVersionString ();
CFBundleVersion = plist?.GetCFBundleVersion ();
CLKComplicationGroup = plist?.Get<PString> (ManifestKeys.CLKComplicationGroup)?.Value;

Expand Down
39 changes: 38 additions & 1 deletion msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,9 @@ Copyright (C) 2018 Microsoft. All rights reserved.
>
<Output TaskParameter="CFBundleExecutable" PropertyName="_ExecutableName" />
<Output TaskParameter="CFBundleDisplayName" PropertyName="_CFBundleDisplayName" />
<Output TaskParameter="CFBundleName" PropertyName="_CFBundleName" />
<Output TaskParameter="CFBundleIdentifier" PropertyName="_BundleIdentifier" />
<Output TaskParameter="CFBundleShortVersionString" PropertyName="_CFBundleShortVersionString" />
<Output TaskParameter="CFBundleVersion" PropertyName="_CFBundleVersion" />
<Output TaskParameter="CLKComplicationGroup" PropertyName="_CLKComplicationGroup" />
<Output TaskParameter="MinimumOSVersion" PropertyName="_MinimumOSVersion" />
Expand Down Expand Up @@ -3540,7 +3542,42 @@ Copyright (C) 2018 Microsoft. All rights reserved.

<Target Name="CreateIpa" Condition="'$(_CanArchive)' == 'true' And '$(SdkIsDesktop)' != 'true'" DependsOnTargets="$(CreateIpaDependsOn)" />

<Target Name="GetApplicationArtifacts" DependsOnTargets="Build;$(GetApplicationArtifactsDependsOn)" Returns="@(ApplicationArtifact)" />
<PropertyGroup>
<GetApplicationArtifactsDependsOn>
Build;
_AddAppleApplicationArtifactMetadata;
$(GetApplicationArtifactsDependsOn);
</GetApplicationArtifactsDependsOn>
</PropertyGroup>

<Target Name="_AddAppleApplicationArtifactMetadata"
Condition="'@(ApplicationArtifact->Count())' != '0' And '$(_AppBundleManifestPath)' != '' And (Exists('$(_AppBundleManifestPath)') Or '$(IsRemoteBuild)' == 'true')">
<ReadAppManifest
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
AppManifest="$(_AppBundleManifestPath)"
SdkDevPath="$(_SdkDevPath)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
>
<Output TaskParameter="CFBundleDisplayName" PropertyName="_ApplicationArtifactCFBundleDisplayName" />
<Output TaskParameter="CFBundleName" PropertyName="_ApplicationArtifactCFBundleName" />
<Output TaskParameter="CFBundleShortVersionString" PropertyName="_ApplicationArtifactCFBundleShortVersionString" />
<Output TaskParameter="CFBundleVersion" PropertyName="_ApplicationArtifactCFBundleVersion" />
</ReadAppManifest>

<ItemGroup>
<ApplicationArtifact Update="@(ApplicationArtifact)">
<ApplicationId>%(ApplicationArtifact.BundleIdentifier)</ApplicationId>
<ApplicationTitle>$(_ApplicationArtifactCFBundleDisplayName)</ApplicationTitle>
<ApplicationName Condition="'$(_ApplicationArtifactCFBundleDisplayName)' != ''">$(_ApplicationArtifactCFBundleDisplayName)</ApplicationName>
<ApplicationName Condition="'$(_ApplicationArtifactCFBundleDisplayName)' == ''">$(_ApplicationArtifactCFBundleName)</ApplicationName>
<ApplicationDisplayVersion>$(_ApplicationArtifactCFBundleShortVersionString)</ApplicationDisplayVersion>
<ApplicationVersion>$(_ApplicationArtifactCFBundleVersion)</ApplicationVersion>
</ApplicationArtifact>
</ItemGroup>
</Target>

<Target Name="GetApplicationArtifacts" DependsOnTargets="$(GetApplicationArtifactsDependsOn)" Returns="@(ApplicationArtifact)" />

<PropertyGroup>
<PrepareAssemblies Condition="'$(PrepareAssemblies)' == ''">false</PrepareAssemblies>
Expand Down
16 changes: 16 additions & 0 deletions tests/dotnet/MySimpleAppWithArtifactMetadata/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.xamarin.customartifactmetadata</string>
<key>CFBundleName</key>
<string>Custom Bundle Name</string>
<key>CFBundleShortVersionString</key>
<string>9.8.7</string>
<key>CFBundleVersion</key>
<string>123</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.xamarin.customartifactmetadata</string>
<key>CFBundleName</key>
<string>Fallback Bundle Name</string>
<key>CFBundleShortVersionString</key>
<string>9.8.7</string>
<key>CFBundleVersion</key>
<string>123</string>
</dict>
</plist>
3 changes: 2 additions & 1 deletion tests/dotnet/MySimpleAppWithArtifactMetadata/shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

<ItemGroup>
<Compile Include="../*.cs" />
<None Include="../$(CustomApplicationManifest)" Link="Info.plist" Condition="'$(CustomApplicationManifest)' != ''" />
</ItemGroup>

<Target Name="AddMauiApplicationArtifactMetadata">
<Target Name="AddMauiApplicationArtifactMetadata" Condition="'$(ExpectedAugmentedPackageFormat)' != ''">
<ItemGroup>
<_MauiObservedAppArtifact Include="@(ApplicationArtifact)" Condition="'%(ApplicationArtifact.PackageFormat)' == 'app'" />
<_MauiObservedPackageArtifact Include="@(ApplicationArtifact)" Condition="'%(ApplicationArtifact.PackageFormat)' == '$(ExpectedAugmentedPackageFormat)'" />
Expand Down
66 changes: 66 additions & 0 deletions tests/dotnet/UnitTests/PostBuildTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,57 @@ public void GetApplicationArtifactsIpaTest (ApplePlatform platform, string runti
AssertApplicationArtifact (outputs, pkgPath, platform, "ipa", isDirectory: false);
}

[Test]
[TestCase (ApplePlatform.iOS, "iossimulator-arm64", null, true)]
[TestCase (ApplePlatform.TVOS, "tvossimulator-arm64", null, true)]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64", null, true)]
[TestCase (ApplePlatform.MacOSX, "osx-arm64", null, true)]
[TestCase (ApplePlatform.iOS, "iossimulator-arm64", "Info.plist", true)]
[TestCase (ApplePlatform.MacOSX, "osx-arm64", "Info.plist", false)]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64", "InfoWithoutDisplayName.plist", false)]
public void ApplicationArtifactMetadataTest (ApplePlatform platform, string runtimeIdentifiers, string? customApplicationManifest, bool generateApplicationManifest)
{
var project = "MySimpleAppWithArtifactMetadata";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);

var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["GenerateApplicationManifest"] = generateApplicationManifest ? "true" : "false";
if (customApplicationManifest is not null)
properties ["CustomApplicationManifest"] = customApplicationManifest;

var outputs = GetApplicationArtifacts (project_path, properties);
var appOutput = AssertApplicationArtifact (outputs, appPath, platform, "app", isDirectory: true);

if (customApplicationManifest is null) {
AssertApplicationMetadata (
appOutput,
"com.xamarin.mysimpleappwithartifactmetadata",
"MySimpleAppWithArtifactMetadata",
"MySimpleAppWithArtifactMetadata",
"3.14",
"3.14");
} else if (customApplicationManifest == "InfoWithoutDisplayName.plist") {
AssertApplicationMetadata (
appOutput,
"com.xamarin.customartifactmetadata",
"",
"Fallback Bundle Name",
"9.8.7",
"123");
} else {
AssertApplicationMetadata (
appOutput,
"com.xamarin.customartifactmetadata",
"$(PRODUCT_NAME)",
"$(PRODUCT_NAME)",
"9.8.7",
"123");
}
}

[Test]
[TestCase (ApplePlatform.iOS, "ios-arm64", "ipa")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64", "pkg")]
Expand Down Expand Up @@ -587,6 +638,10 @@ static JsonElement AssertApplicationArtifact (JsonElement [] outputs, string pat
Assert.That (GetMetadata (output, "IsDirectory"), Is.EqualTo (isDirectory ? "true" : "false"), "IsDirectory");
Assert.That (GetMetadata (output, "PlatformName"), Is.EqualTo (platform.AsString ()), "PlatformName");
Assert.That (GetMetadata (output, "BundleIdentifier"), Is.Not.Empty, "BundleIdentifier");
Assert.That (GetMetadata (output, "ApplicationId"), Is.EqualTo (GetMetadata (output, "BundleIdentifier")), "ApplicationId");
Assert.That (GetMetadata (output, "ApplicationName"), Is.Not.Empty, "ApplicationName");
Assert.That (GetMetadata (output, "ApplicationDisplayVersion"), Is.Not.Empty, "ApplicationDisplayVersion");
Assert.That (GetMetadata (output, "ApplicationVersion"), Is.Not.Empty, "ApplicationVersion");
Assert.That (GetMetadata (output, "ArtifactKind"), Is.Empty, "ArtifactKind");
Assert.That (GetMetadata (output, "AppBundlePath"), Is.Empty, "AppBundlePath");
Assert.That (GetMetadata (output, "CodeSigned"), Is.Empty, "CodeSigned");
Expand All @@ -605,6 +660,17 @@ static JsonElement AssertApplicationArtifact (JsonElement [] outputs, ApplePlatf
return AssertApplicationArtifact (outputs, fullPath, platform, packageFormat, isDirectory);
}

static void AssertApplicationMetadata (JsonElement output, string applicationId, string applicationTitle, string applicationName, string applicationDisplayVersion, string applicationVersion)
{
Assert.Multiple (() => {
Assert.That (GetMetadata (output, "ApplicationId"), Is.EqualTo (applicationId), "ApplicationId");
Assert.That (GetMetadata (output, "ApplicationTitle"), Is.EqualTo (applicationTitle), "ApplicationTitle");
Assert.That (GetMetadata (output, "ApplicationName"), Is.EqualTo (applicationName), "ApplicationName");
Assert.That (GetMetadata (output, "ApplicationDisplayVersion"), Is.EqualTo (applicationDisplayVersion), "ApplicationDisplayVersion");
Assert.That (GetMetadata (output, "ApplicationVersion"), Is.EqualTo (applicationVersion), "ApplicationVersion");
});
}

static string GetMetadata (JsonElement item, string name)
{
return item.TryGetProperty (name, out var value) ? value.GetString () ?? "" : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ ReadAppManifest CreateTask (ApplePlatform platform = ApplePlatform.iOS, Action<P
return task;
}

[Test]
public void ReadsApplicationMetadata ()
{
var task = CreateTask (createDictionary: (plist) => {
plist ["CFBundleDisplayName"] = "$(PRODUCT_NAME)";
plist ["CFBundleName"] = "Bundle Name";
plist ["CFBundleIdentifier"] = "com.xamarin.custom";
plist ["CFBundleShortVersionString"] = "2.3.4";
plist ["CFBundleVersion"] = "42";
});
ExecuteTask (task);
Assert.Multiple (() => {
Assert.That (task.CFBundleDisplayName, Is.EqualTo ("$(PRODUCT_NAME)"), "CFBundleDisplayName");
Assert.That (task.CFBundleName, Is.EqualTo ("Bundle Name"), "CFBundleName");
Assert.That (task.CFBundleIdentifier, Is.EqualTo ("com.xamarin.custom"), "CFBundleIdentifier");
Assert.That (task.CFBundleShortVersionString, Is.EqualTo ("2.3.4"), "CFBundleShortVersionString");
Assert.That (task.CFBundleVersion, Is.EqualTo ("42"), "CFBundleVersion");
});
}

[Test]
public void MacCatalystVersionConversion ()
{
Expand Down
Loading