[dotnet] Detect, compile and publish Info.plist into the app. (#8752)
* [dotnet] Detect, compile and publish Info.plist into the app. * Automatically detect any property lists in the root project directory, and include them into the build. * Introduce the existing build targets to detect and compile Info.plist into the .NET build. * Add documentation for default inclusion. This document will grow over time as more file types are automatically included. * Add some tests. * [dotnet] Adjust default inclusion behavior. * Use a single platform-specific variable to control all types of platform-specific inclusions. * [dotnet] Move the default inclusion to .targets instead of .props, so that .NET's default inclusion logic is already imported. .NET sets EnableDefaultItems in their .targets: https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets#L16
This commit is contained in:
Родитель
580bcd8c18
Коммит
ab6b418483
|
@ -0,0 +1,20 @@
|
|||
# Default complication includes in iOS, tvOS, watchOS and macOS projects
|
||||
|
||||
Default compilation includes for .NET Core projects is explained here:
|
||||
[Default compilation includes in .NET Core projects][1]
|
||||
|
||||
This document explains how default compilation includes is implemented for
|
||||
iOS, tvOS, watchOS and macOS projects.
|
||||
|
||||
Default inclusion can be completely disabled by setting
|
||||
`EnableDefaultItems=false`. It can also be disabled per-platform by setting
|
||||
the platform-specific variables `EnableDefaultiOSItems=false`,
|
||||
`EnableDefaulttvOSItems=false`, `EnableDefaultwatchOSItems=false`, or
|
||||
`EnableDefaultmacOSItems=false`.
|
||||
|
||||
## Property lists
|
||||
|
||||
All \*.plist files in the root directory are included by default (as `None`
|
||||
items).
|
||||
|
||||
[1]: https://docs.microsoft.com/en-us/dotnet/core/tools/csproj#default-compilation-includes-in-net-core-projects
|
|
@ -1,5 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<!-- Default inclusion -->
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Enable default inclusion behavior unless told otherwise, but default to the value for EnableDefaultItems -->
|
||||
<!-- We have a public property for each platform, and unify them into a single private property for our own build logic -->
|
||||
<EnableDefaultiOSItems Condition=" '$(_PlatformName)' == 'iOS' And '$(EnableDefaultiOSItems)' == '' ">$(EnableDefaultItems)</EnableDefaultiOSItems>
|
||||
<EnableDefaulttvOSItems Condition=" '$(_PlatformName)' == 'tvOS' And '$(EnableDefaulttvOSItems)' == '' ">$(EnableDefaultItems)</EnableDefaulttvOSItems>
|
||||
<EnableDefaultwatchOSItems Condition=" '$(_PlatformName)' == 'watchOS' And '$(EnableDefaultwatchOSItems)' == '' ">$(EnableDefaultItems)</EnableDefaultwatchOSItems>
|
||||
<EnableDefaultmacOSItems Condition=" '$(_PlatformName)' == 'macOS' And '$(EnableDefaultmacOSItems)' == '' ">$(EnableDefaultItems)</EnableDefaultmacOSItems>
|
||||
<_EnableDefaultXamarinItems Condition=" '$(_PlatformName)' == 'iOS' ">$(EnableDefaultiOSItems)</_EnableDefaultXamarinItems>
|
||||
<_EnableDefaultXamarinItems Condition=" '$(_PlatformName)' == 'tvOS' ">$(EnableDefaulttvOSItems)</_EnableDefaultXamarinItems>
|
||||
<_EnableDefaultXamarinItems Condition=" '$(_PlatformName)' == 'watchOS' ">$(EnableDefaultwatchOSItems)</_EnableDefaultXamarinItems>
|
||||
<_EnableDefaultXamarinItems Condition=" '$(_PlatformName)' == 'macOS' ">$(EnableDefaultmacOSItems)</_EnableDefaultXamarinItems>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Default plist file inclusion -->
|
||||
<ItemGroup Condition="'$(_EnableDefaultXamarinItems)' == 'true' ">
|
||||
<None Include="*.plist">
|
||||
<Link>$([MSBuild]::MakeRelative ('$(MSBuildProjectDirectory)', '%(Identity)'))</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Declare the XI/XM framework bundled with this version of the SDK. See Microsoft.NETCoreSdk.BundledVersions.props -->
|
||||
<PropertyGroup>
|
||||
<!-- Runtime pack identifiers -->
|
||||
|
|
|
@ -73,6 +73,8 @@
|
|||
<!-- We re-use ComputeFilesToPublish & CopyFilesToPublishDirectory to copy files to the .app -->
|
||||
<!-- ComputeFilesToPublish will run ILLink -->
|
||||
<CreateAppBundleDependsOn>
|
||||
_DetectAppManifest;
|
||||
_CompileAppManifest;
|
||||
_ComputeLinkerArguments;
|
||||
ComputeFilesToPublish;
|
||||
_ComputePublishLocation;
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
<Compile Include="..\..\..\tools\common\StringUtils.cs">
|
||||
<Link>external\StringUtils.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\tools\common\ApplePlatform.cs">
|
||||
<Link>external\ApplePlatform.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="external\" />
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Xamarin.Utils;
|
||||
|
||||
namespace Xamarin.Tests {
|
||||
[TestFixture]
|
||||
public class DotNetProjectTest {
|
||||
|
@ -35,28 +38,34 @@ namespace Xamarin.Tests {
|
|||
[Test]
|
||||
public void BuildMySingleView ()
|
||||
{
|
||||
var platform = ApplePlatform.iOS;
|
||||
var project_path = GetProjectPath ("MySingleView");
|
||||
Clean (project_path);
|
||||
var result = DotNet.AssertBuild (project_path);
|
||||
AssertThatLinkerExecuted (result);
|
||||
AssertAppContents (platform, Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net5.0", "ios-x64", "MySingleView.app"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildMyCocoaApp ()
|
||||
{
|
||||
var platform = ApplePlatform.MacOSX;
|
||||
var project_path = GetProjectPath ("MyCocoaApp");
|
||||
Clean (project_path);
|
||||
var result = DotNet.AssertBuild (project_path);
|
||||
AssertThatLinkerExecuted (result);
|
||||
AssertAppContents (platform, Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net5.0", "osx-x64", "MyCocoaApp.app"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildMyTVApp ()
|
||||
{
|
||||
var platform = ApplePlatform.TVOS;
|
||||
var project_path = GetProjectPath ("MyTVApp");
|
||||
Clean (project_path);
|
||||
var result = DotNet.AssertBuild (project_path);
|
||||
AssertThatLinkerExecuted (result);
|
||||
AssertAppContents (platform, Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net5.0", "tvos-x64", "MyTVApp.app"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -86,5 +95,23 @@ namespace Xamarin.Tests {
|
|||
Assert.That (output, Does.Contain ("Building target \"_RunILLink\" completely."), "Linker did not executed as expected.");
|
||||
Assert.That (output, Does.Contain ("Hello SetupStep"), "Custom steps did not run as expected.");
|
||||
}
|
||||
|
||||
void AssertAppContents (ApplePlatform platform, string app_directory)
|
||||
{
|
||||
string info_plist_path;
|
||||
switch (platform) {
|
||||
case ApplePlatform.iOS:
|
||||
case ApplePlatform.TVOS:
|
||||
case ApplePlatform.WatchOS:
|
||||
info_plist_path = Path.Combine (app_directory, "Info.plist");
|
||||
break;
|
||||
case ApplePlatform.MacOSX:
|
||||
info_plist_path = Path.Combine (app_directory, "Contents", "Info.plist");
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException ($"Unknown platform: {platform}");
|
||||
}
|
||||
Assert.That (info_plist_path, Does.Exist, "Info.plist");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче