Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/building-apps/build-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ or linked with when building the native executable.

Native framework directory names must use the lowercase `.framework` extension.
Other capitalization, such as `.Framework` or `.FRAMEWORK`, produces warning
`MT7199` because the framework may not be linked or bundled
`MT7200` because the framework may not be linked or bundled
correctly. Rename the directory and update the reference to use `.framework`.

## ObjcBindingApiDefinition
Expand Down
29 changes: 29 additions & 0 deletions docs/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,35 @@ The validation process may not validate every entitlement, nor is it guaranteed

If the validation fails for entitlements that actually work, please file a new issue.

## ValidateSceneManifest

Choose whether to check for a `UIApplicationSceneManifest` dictionary in the
merged app manifest when building iOS and Mac Catalyst apps against SDK 27.0 or
later. The default is `true`. App extensions, frameworks, libraries, macOS, and
tvOS are not checked.

Apps using the legacy UIKit lifecycle crash at launch on iOS or macOS 27.0 or
later when built against the 27.0 SDK or later, even if their minimum deployment
target is an older OS version. See https://aka.ms/uiscene for migration instructions.

This check only inspects the manifest; it does not verify scene delegates or
custom lifecycle handlers. Scene manifests supplied by partial manifests are
included in the check. An empty dictionary is accepted for apps that configure
scenes dynamically in their app delegate.

If the check incorrectly rejects an app (for example, one that configures scenes
entirely in code), it can be disabled in the project file:

```xml
<PropertyGroup>
<ValidateSceneManifest>false</ValidateSceneManifest>
</PropertyGroup>
```

Disabling this build-time check does not disable the operating system's scene
lifecycle requirement. Verify that the app launches and behaves correctly on
OS 27.0 or later before distributing it.

## ValidateXcodeVersion

Choose whether the current Xcode version should be validated.
Expand Down
19 changes: 18 additions & 1 deletion docs/website/mtouch-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3510,7 +3510,24 @@ Where * can be:

<a name="MT7199"></a>

### MT7199: The framework '*' has an incorrectly capitalized extension. Rename it to use the lowercase '.framework' extension to ensure it is linked and bundled correctly.
### MT7199: The app's Info.plist does not contain a UIApplicationSceneManifest dictionary.

Apps built against the iOS or Mac Catalyst 27.0 SDK or later must adopt the UIKit
scene lifecycle to launch on iOS or macOS 27.0 or later. Add the scene manifest
and delegate, and migrate custom lifecycle handlers by following the instructions
at https://aka.ms/uiscene.

The check examines the merged app manifest, including partial manifests. It
does not verify the scene delegate implementation. If the check incorrectly
rejects an app that configures scenes in code, set the MSBuild property
`ValidateSceneManifest` to `false`. This only disables build-time validation;
it does not bypass the operating system's requirement.

*MSBuild task: CompileAppManifest*

<a name="MT7200"></a>

### MT7200: The framework '*' has an incorrectly capitalized extension. Rename it to use the lowercase '.framework' extension to ensure it is linked and bundled correctly.

Native framework directory names must end in lowercase `.framework`. Other
capitalization, such as `.Framework`, may prevent the framework from being linked
Expand Down
7 changes: 6 additions & 1 deletion msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,12 @@
<comment>Shown when codesign fails with 'resource fork, Finder information, or similar detritus not allowed'.
{0} - The path of the file or bundle being signed. Do not translate the attribute names, shell commands, or URL.</comment>
</data>
<data name="W7199" xml:space="preserve">
<data name="E7199" xml:space="preserve">
<value>The app's Info.plist does not contain a UIApplicationSceneManifest dictionary. Apps built with the iOS or Mac Catalyst 27.0 SDK or later must use the UIKit scene lifecycle or they will crash at launch on iOS or macOS 27.0 or later. Add a scene manifest and scene delegate, and migrate custom lifecycle handlers as described at https://aka.ms/uiscene. To skip this build-time validation, set the MSBuild property ValidateSceneManifest to false; this does not disable the operating system's requirement.</value>
<comment>Shown when an iOS or Mac Catalyst app built against SDK 27.0 or later does not declare a scene manifest.
Do not translate Info.plist, UIApplicationSceneManifest, UIKit, https://aka.ms/uiscene, ValidateSceneManifest, or false.</comment>
</data>
<data name="W7200" xml:space="preserve">
<value>The framework '{0}' has an incorrectly capitalized extension. Rename it to use the lowercase '.framework' extension to ensure it is linked and bundled correctly.</value>
<comment>Shown when a native framework's extension contains uppercase letters.
{0} - The path to the framework. Do not translate '.framework'.</comment>
Expand Down
22 changes: 22 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class CompileAppManifest : XamarinTask, IHasProjectDir, IHasResourcePrefi
public string TargetArchitectures { get; set; } = String.Empty;

public bool Validate { get; set; }

public bool ValidateSceneManifest { get; set; } = true;
#endregion

protected TargetArchitecture architectures;
Expand Down Expand Up @@ -164,6 +166,8 @@ public override bool Execute ()
AddAppManifestEntries (plist);

Validation (plist);
if (Log.HasLoggedErrors)
return false;

// write the resulting app manifest
plist.Save (CompiledAppManifest!.ItemSpec, true, true);
Expand Down Expand Up @@ -450,6 +454,8 @@ void Validation (PDictionary plist)
if (!Validate)
return;

ValidateSceneLifecycle (plist, sdkVersion);

var supportedDevices = plist.GetUIDeviceFamily ();
var macCatalystOptimizedForMac = (supportedDevices & IPhoneDeviceType.MacCatalystOptimizedForMac) == IPhoneDeviceType.MacCatalystOptimizedForMac;
if (macCatalystOptimizedForMac && !OnWindows) {
Expand Down Expand Up @@ -498,6 +504,22 @@ void Validation (PDictionary plist)
}
}

protected void ValidateSceneLifecycle (PDictionary plist, AppleSdkVersion sdkVersion)
{
if (!ValidateSceneManifest || IsAppExtension || IsFramework)
return;
if (Platform != ApplePlatform.iOS && Platform != ApplePlatform.MacCatalyst)
return;
if (sdkVersion < new AppleSdkVersion (27, 0))
return;

// An empty dictionary is valid when the app delegate supplies scene configurations dynamically.
if (plist.Get<PDictionary> ("UIApplicationSceneManifest") is not null)
return;

Log.LogError (7199, AppManifest?.ItemSpec, MSBStrings.E7199);
Comment thread
rolfbjarne marked this conversation as resolved.
Resolved
}

bool CompileMac (PDictionary plist)
{
return !Log.HasLoggedErrors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void WarnIfIncorrectFrameworkExtension (TaskLoggingHelper log, string pat
}

if (path.EndsWith (".framework", StringComparison.OrdinalIgnoreCase) && !path.EndsWith (".framework", StringComparison.Ordinal))
log.LogWarning (7199, path, MSBStrings.W7199 /* The framework '{0}' has an incorrectly capitalized extension. Rename it to use the lowercase '.framework' extension to ensure it is linked and bundled correctly. */, path);
log.LogWarning (7200, path, MSBStrings.W7200 /* The framework '{0}' has an incorrectly capitalized extension. Rename it to use the lowercase '.framework' extension to ensure it is linked and bundled correctly. */, path);
}

public override bool Execute ()
Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.props
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Copyright (C) 2020 Microsoft. All rights reserved.
<!-- It might be desirable to turn off the automatic detection if the current logic detects Info.plist that aren't the app manifest -->
<!-- One example would be when including native frameworks in the app bundle - frameworks have an Info.plist that might be picked up -->
<AppManifestDetectionEnabled Condition="'$(AppManifestDetectionEnabled)' == ''">true</AppManifestDetectionEnabled>
<ValidateSceneManifest Condition="'$(ValidateSceneManifest)' == ''">true</ValidateSceneManifest>
</PropertyGroup>

<!-- Code signing defaults -->
Expand Down
2 changes: 2 additions & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<_CompileAppManifestInputLine Include="TargetArchitectures=$(TargetArchitectures)" />
<_CompileAppManifestInputLine Include="TargetFrameworkMoniker=$(_ComputedTargetFrameworkMoniker)" />
<_CompileAppManifestInputLine Include="Validate=$(_CreateAppManifest)" />
<_CompileAppManifestInputLine Include="ValidateSceneManifest=$(ValidateSceneManifest)" />
<!-- @(_CompileAppManifestInputFile) contains additional files to use as Inputs -->
<_CompileAppManifestInputFile Include="$(_CompileAppManifestInputFile)" />
<_CompileAppManifestInputFile Include="@(_FontFilesToRegister)" />
Expand Down Expand Up @@ -738,6 +739,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
TargetArchitectures="$(TargetArchitectures)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
Validate="$(_CreateAppManifest)"
ValidateSceneManifest="$(ValidateSceneManifest)"
>
</CompileAppManifest>
</Target>
Expand Down
2 changes: 2 additions & 0 deletions tests/dotnet/MaxSupportedOSPlatformVersion/shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- This is a console executable that does not start UIKit. -->
<ValidateSceneManifest>false</ValidateSceneManifest>

<ApplicationTitle>MaxSupportedOSPlatformVersion</ApplicationTitle>
<ApplicationId>com.xamarin.maxsupportedosplatformversion</ApplicationId>
Expand Down
6 changes: 6 additions & 0 deletions tests/dotnet/MyCatalystApp/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ public override void WillTerminate (UIApplication application)
{
}
}

[Register ("SceneDelegate")]
public class SceneDelegate : UIResponder, IUIWindowSceneDelegate {
[Export ("window")]
public UIWindow? Window { get; set; }
}
}
21 changes: 19 additions & 2 deletions tests/dotnet/MyCatalystApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>MainStoryboard</string>
</dict>
</array>
</dict>
</dict>
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
Expand All @@ -12,8 +31,6 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIMainStoryboardFile</key>
<string>MainStoryboard</string>
<key>XSAppIconAssets</key>
<string>Resources/Images.xcassets/AppIcons.appiconset</string>
</dict>
Expand Down
19 changes: 12 additions & 7 deletions tests/dotnet/MySingleView/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@

namespace MySingleView {
public partial class AppDelegate : UIApplicationDelegate {
UIWindow? window;
}

[Register ("SceneDelegate")]
public class SceneDelegate : UIResponder, IUIWindowSceneDelegate {
[Export ("window")]
public UIWindow? Window { get; set; }

public override bool FinishedLaunching (UIApplication app, NSDictionary? options)
[Export ("scene:willConnectToSession:options:")]
public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
#pragma warning disable CA1422
window = new UIWindow (UIScreen.MainScreen.Bounds);
#pragma warning restore CA1422
if (scene is not UIWindowScene windowScene)
return;

var window = new UIWindow (windowScene);
Window = window;
var dvc = new UIViewController ();
var button = new UIButton (window.Bounds);
button.SetTitle ("net6!", UIControlState.Normal);
dvc.Add (button);

window.RootViewController = dvc;
window.MakeKeyAndVisible ();

return true;
}
}
}
17 changes: 17 additions & 0 deletions tests/dotnet/MySingleView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
Expand Down
40 changes: 40 additions & 0 deletions tests/dotnet/UnitTests/PartialAppManifestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,46 @@
namespace Xamarin.Tests {
public class PartialAppManifestTest : TestBaseClass {

[Test]
[TestCase (ApplePlatform.iOS, "iossimulator-arm64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")]
public void ValidateSceneManifest (ApplePlatform platform, string runtimeIdentifiers)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var projectPath = GetProjectPath ("MyPartialAppManifestApp", platform: platform);
Clean (projectPath);
var properties = GetDefaultProperties (runtimeIdentifiers);
const string target = "_CompileAppManifest";

// The shared partial manifest supplies the scene configuration.
DotNet.AssertBuild (projectPath, properties, target: target);

// AppManifestEntry is applied after partial manifests and must also be validated.
properties ["ManifestKey"] = "UIApplicationSceneManifest";
properties ["ManifestValue"] = "invalid";
var result = DotNet.AssertBuildFailure (projectPath, properties, target: target);
var errors = BinLog.GetBuildLogErrors (result.BinLogPath).ToArray ();
Assert.That (errors.Length, Is.EqualTo (1), "Errors");
Assert.That (errors [0].Message, Does.Contain ("https://aka.ms/uiscene"), "Migration instructions");

// A failed compilation must not leave an output that bypasses validation on the next build.
DotNet.AssertBuildFailure (projectPath, properties, target: target);

properties ["ValidateSceneManifest"] = "false";
DotNet.AssertBuild (projectPath, properties, target: target);

// Re-enabling validation must invalidate the previously successful output.
properties ["ValidateSceneManifest"] = "true";
result = DotNet.AssertBuildFailure (projectPath, properties, target: target);
errors = BinLog.GetBuildLogErrors (result.BinLogPath).ToArray ();
Assert.That (errors.Length, Is.EqualTo (1), "Re-enabled errors");
Assert.That (errors [0].Message, Does.Contain ("https://aka.ms/uiscene"), "Re-enabled validation");

properties.Remove ("ManifestKey");
properties.Remove ("ManifestValue");
DotNet.AssertBuild (projectPath, properties, target: target);
}

[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
public void Build (ApplePlatform platform, string runtimeIdentifiers)
Expand Down
2 changes: 2 additions & 0 deletions tests/dotnet/UnitTests/TemplateProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public void VeryManyRegisteredAssemblies (ApplePlatform platform)
<TargetFramework>{platform.ToFramework ()}</TargetFramework>
<OutputType>Exe</OutputType>
<ApplicationId>com.microsoft.VeryManyRegisteredAssemblies</ApplicationId>
<!-- This test executes a console entry point, not a UIKit application. -->
<ValidateSceneManifest>false</ValidateSceneManifest>
<MonoBundlingExtraArgs>--registrar:static --optimize:remove-dynamic-registrar</MonoBundlingExtraArgs>
<MtouchExtraArgs>$(MonoBundlingExtraArgs)</MtouchExtraArgs>
<LinkMode>Full</LinkMode>
Expand Down
2 changes: 2 additions & 0 deletions tests/dotnet/UnitTests/TestBaseClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ protected string GenerateProject (ApplePlatform platform, string name, string ru
sb.AppendLine ($" <PropertyGroup>");
sb.AppendLine ($" <TargetFramework>{platform.ToFramework ()}</TargetFramework>");
sb.AppendLine ($" <OutputType>Exe</OutputType>");
// These generated projects use console entry points and do not start UIKit.
sb.AppendLine ($" <ValidateSceneManifest>false</ValidateSceneManifest>");
sb.AppendLine ($" <ApplicationTitle>{name}</ApplicationTitle>");
sb.AppendLine ($" <ApplicationId>com.xamarin.testproject.{name}</ApplicationId>");
sb.AppendLine ($" </PropertyGroup>");
Expand Down
Loading
Loading