[dotnet/msbuild] Fix packaging and archiving support in .NET. Partial fix for #10413. (#12244)

* Rearrange some MSBuild logic so that the packaging/archiving code for macOS
  can also be used for Mac Catalyst.
* Make the .NET build logic package/archive when requested to do so.
* Add tests.

Partial fix for https://github.com/xamarin/xamarin-macios/issues/10413.
This commit is contained in:
Rolf Bjarne Kvinge 2021-07-29 15:33:08 +02:00 коммит произвёл GitHub
Родитель 7c66aa3829 aebc0117dc
Коммит 63f28c0c5c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
15 изменённых файлов: 279 добавлений и 137 удалений

Просмотреть файл

@ -171,6 +171,9 @@
$(BuildDependsOn);
_CreateAppBundle;
Codesign;
CreateIpa;
_CreateInstaller;
Archive;
</BuildDependsOn>
<!-- inner build for multi-rid build -->
@ -191,6 +194,9 @@
_CompileAppManifest;
_CreateMergedAppBundle;
Codesign;
CreateIpa;
_CreateInstaller;
Archive;
</BuildDependsOn>
<!-- We re-use ComputeFilesToPublish & CopyFilesToPublishDirectory to copy files to the .app -->

Просмотреть файл

@ -43,21 +43,10 @@ Copyright (C) 2013-2014 Xamarin. All rights reserved.
</PropertyGroup>
<PropertyGroup>
<CodesignProvision Condition="'$(CodesignProvision)' == ''"></CodesignProvision>
<CodesignEntitlements Condition="'$(CodesignEntitlements)' == ''"></CodesignEntitlements>
<CodesignExtraArgs Condition="'$(CodesignExtraArgs)' == ''"></CodesignExtraArgs>
<CreatePackage Condition="'$(CreatePackage)' == ''">false</CreatePackage>
<HttpClientHandler Condition="'$(HttpClientHandler)' == ''">HttpClientHandler</HttpClientHandler>
<EnablePackageSigning Condition="'$(EnablePackageSigning)' == ''">false</EnablePackageSigning>
<PackageSigningKey Condition="'$(PackageSigningKey)' == ''"></PackageSigningKey>
<ProductDefinition Condition="'$(ProductDefinition)' == ''"></ProductDefinition>
<PackagingExtraArgs Condition="'$(PackagingExtraArgs)' == ''"></PackagingExtraArgs>
<I18n Condition="'$(I18n)' == ''"></I18n>
<IncludeMonoRuntime Condition="'$(IncludeMonoRuntime)' == ''">true</IncludeMonoRuntime>
<IsAppExtension Condition="'$(IsAppExtension)' == ''">False</IsAppExtension>
<EnableSGenConc Condition="'$(EnableSGenConc)' == ''">false</EnableSGenConc>
<AotScope Condition="'$(AotScope)' == ''">None</AotScope>
<ArchiveOnBuild Condition="'$(ArchiveOnBuild)' == ''">False</ArchiveOnBuild>
<Profiling Condition="'$(MtouchProfiling)' == ''">False</Profiling>
</PropertyGroup>

Просмотреть файл

@ -26,12 +26,6 @@ Copyright (C) 2014 Xamarin. All rights reserved.
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Before.targets')"/>
<PropertyGroup>
<_CanOutputAppBundle>False</_CanOutputAppBundle>
<_CanOutputAppBundle Condition="'$(OutputType)' == 'Exe' Or '$(IsAppExtension)' == 'true'">true</_CanOutputAppBundle>
<_RequireProvisioningProfile>False</_RequireProvisioningProfile>
<_RequireProvisioningProfile Condition="'$(CodesignProvision)' != ''">True</_RequireProvisioningProfile>
<_PreparedResourceRules></_PreparedResourceRules>
<_AppBundleName>$(AssemblyName)</_AppBundleName>
</PropertyGroup>
@ -120,35 +114,6 @@ Copyright (C) 2014 Xamarin. All rights reserved.
</TextureAtlas>
</Target>
<Target Name="_CompileProductDefinition" Condition="$(CreatePackage)" DependsOnTargets="_DetectAppManifest;_ComputeTargetArchitectures">
<CompileProductDefinition
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
ProductDefinition="$(ProductDefinition)"
OutputDirectory = "$(IntermediateOutputPath)"
TargetArchitectures = "$(TargetArchitectures)"
AppManifest = "$(_AppManifest)">
<Output TaskParameter="CompiledProductDefinition" PropertyName="_CompiledProductDefinition" />
</CompileProductDefinition>
</Target>
<Target Name="_CreateInstaller" Condition="$(CreatePackage)" DependsOnTargets="Codesign;_CompileProductDefinition">
<CreateInstallerPackage
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
OutputDirectory = "$(TargetDir)"
Name = "$(AssemblyName)"
AppManifest="$(_AppManifest)"
ProjectPath= "$(MSBuildProjectFullPath)"
AppBundleDir= "$(AppBundleDir)"
MainAssembly= "$(TargetPath)"
EnablePackageSigning = "$(EnablePackageSigning)"
ProductDefinition = "$(_CompiledProductDefinition)"
PackageSigningKey = "$(PackageSigningKey)"
PackagingExtraArgs = "$(PackagingExtraArgs)">
</CreateInstallerPackage>
</Target>
<PropertyGroup>
<CompileToNativeDependsOn>
_ComputeLinkMode;

Просмотреть файл

@ -457,7 +457,9 @@ namespace Xamarin.MacDev.Tasks
SaveArchivedExpandedEntitlements (archived);
if (SdkIsSimulator) {
if (Platform == Utils.ApplePlatform.MacCatalyst) {
EntitlementsInSignature = CompiledEntitlements;
} else if (SdkIsSimulator) {
if (compiled.Count > 0) {
EntitlementsInExecutable = CompiledEntitlements;
}

Просмотреть файл

@ -115,23 +115,63 @@ Copyright (C) 2020 Microsoft. All rights reserved.
<_SdkVersion Condition="'$(_PlatformName)' == 'macOS'">$(MacOSXSdkVersion)</_SdkVersion>
<_SdkVersion Condition="'$(_PlatformName)' != 'macOS'">$(MtouchSdkVersion)</_SdkVersion>
<!-- RequireCodeSigning -->
<!-- iOS/watchOS/tvOS is simple: device builds require code signing, simulator builds do not. This is a big lie, for some simulator builds need to be signed, but the _DetectCodeSigning task handles those cases. -->
<_RequireCodeSigning Condition="'$(_PlatformName)' != 'macOS' And '$(_RequireCodeSigning)' == ''">false</_RequireCodeSigning> <!-- Xamarin.iOS builds are not signed by default -->
<_RequireCodeSigning Condition="'$(_PlatformName)' != 'macOS' And '$(ComputedPlatform)' == 'iPhone'">true</_RequireCodeSigning> <!-- except that device builds must be signed -->
<!-- macOS is a bit more complicated:
* 'EnableCodeSigning' specifies whether the app is signed or not, and this defaults to false if it's not set.
* Extensions are special, because they must be signed. However, due to historical reasons, extension projects will have set EnableCodeSigning=false. So we do the following:
* If we're an extension, and code signing is disabled: enable code signing, set the code signing key (_CodeSigningKey) to '-', and pass this value to the _DetectCodeSigning task.
-->
<_RequireCodeSigning Condition="'$(_PlatformName)' == 'macOS' And '$(_RequireCodeSigning)' == ''">$(EnableCodeSigning)</_RequireCodeSigning> <!-- Xamarin.Mac projects use the 'EnableCodeSigning' variable to enable code signing -->
<_RequireCodeSigning Condition="'$(_PlatformName)' == 'macOS' And '$(_RequireCodeSigning)' == ''">false</_RequireCodeSigning> <!-- Xamarin.Mac projects: disable by default -->
<_CodeSigningKey Condition="'$(_PlatformName)' == 'macOS' And '$(IsAppExtension)' == 'true' And '$(_CodeSigningKey)' == '' And '$(_RequireCodeSigning)' == 'false'">-</_CodeSigningKey> <!-- Set _CodeSigningKey to '-' if we're an extension where code signing is not requested -->
<_RequireCodeSigning Condition="'$(_PlatformName)' == 'macOS' And '$(IsAppExtension)' == 'true'">true</_RequireCodeSigning> <!-- But extensions must be signed, so make sure they are -->
<!-- Other variables that are used in code signing / packaging, but that are by default empty (so no need for any logic): -->
<!-- CodesignProvision: the name of the provisioning profile to use when signing the bundle -->
<!-- CodesignEntitlements: the path to the Entitlements.plist to use when signing the bundle -->
<!-- CodesignExtraArgs: any extra arguments to pass to 'codesign' -->
<!-- PackageSigningKey: the certificate used to sign packages (.pkg). Applicable to macOS and Mac Catalyst -->
<!-- PackagingExtraArgs: any extra arguments passed to the productbuild tool when creating packages (.pkg). Applicable to macOS and Mac Catalyst -->
<!-- ProductDefinition: the product definition template (plist) used when creating the product definition to pass to the product build tool when creating packages (.pkg). Applicable to mcOS and Mac Catalyst -->
<!-- _RequireProvisioningProfile -->
<!-- Default: false -->
<!-- macOS: true if a provisioning profile is used -->
<!-- iOS/tvOS/watchOS: true if building for device or if a custom entitlements file is used -->
<!-- Mac Catalyst: true if a provisioning profile is used -->
<_RequireProvisioningProfile Condition="'$(_RequireProvisioningProfile)' == '' And '$(_PlatformName)' == 'macOS' And '$(CodesignProvision)' != ''">true</_RequireProvisioningProfile>
<_RequireProvisioningProfile Condition="'$(_RequireProvisioningProfile)' == '' And ('$(_PlatformName)' == 'iOS' Or '$(_PlatformName)' == 'tvOS' Or '$(_PlatformName)' == 'watchOS') And ('$(ComputedPlatform)' == 'iPhone' Or '$(CodesignEntitlements)' != '')">true</_RequireProvisioningProfile>
<_RequireProvisioningProfile Condition="'$(_RequireProvisioningProfile)' == '' And '$(_PlatformName)' == 'MacCatalyst' And '$(CodesignProvision)' != ''">true</_RequireProvisioningProfile>
<_RequireProvisioningProfile Condition="'$(_RequireProvisioningProfile)' == ''">false</_RequireProvisioningProfile>
</PropertyGroup>
<!-- RequireCodeSigning -->
<!-- iOS/watchOS/tvOS is simple: device builds require code signing, simulator builds do not. This is a big lie, for some simulator builds need to be signed, but the _DetectCodeSigning task handles those cases. -->
<PropertyGroup Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'">
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == ''">false</_RequireCodeSigning> <!-- Xamarin.iOS builds are not signed by default -->
<_RequireCodeSigning Condition="'$(ComputedPlatform)' == 'iPhone'">true</_RequireCodeSigning> <!-- except that device builds must be signed -->
</PropertyGroup>
<!-- macOS is a bit more complicated:
* 'EnableCodeSigning' specifies whether the app is signed or not, and this defaults to false if it's not set.
* Extensions are special, because they must be signed. However, due to historical reasons, extension projects will have set EnableCodeSigning=false. So we do the following:
* If we're an extension, and code signing is disabled: enable code signing, set the code signing key (_CodeSigningKey) to '-', and pass this value to the _DetectCodeSigning task.
-->
<PropertyGroup Condition="'$(_PlatformName)' == 'macOS' Or '$(_PlatformName)' == 'MacCatalyst'">
<!-- macOS and Mac Catalyst projects use the 'EnableCodeSigning' variable to enable code signing -->
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == ''">$(EnableCodeSigning)</_RequireCodeSigning>
<!-- Signing must be enabled when archiving -->
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == '' And '$(ArchiveOnBuild)' == 'true'">true</_RequireCodeSigning>
<!-- Extensions must be signed, so make sure they are -->
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == '' And '$(IsAppExtension)' == 'true'">true</_RequireCodeSigning>
<!-- Otherwise code signing is disabled by default -->
<_RequireCodeSigning Condition="'$(_RequireCodeSigning)' == ''">false</_RequireCodeSigning>
<!-- Set _CodeSigningKey to '-' if we're an extension where code signing is not requested -->
<_CodeSigningKey Condition="'$(IsAppExtension)' == 'true' And '$(_CodeSigningKey)' == '' And '$(_RequireCodeSigning)' == 'false'">-</_CodeSigningKey>
</PropertyGroup>
<PropertyGroup>
<!-- SpecifiedCodeSigningKey -->
<_SpecifiedCodesignKey Condition="'$(_PlatformName)' == 'macOS'">$(CodeSigningKey)</_SpecifiedCodesignKey> <!-- Xamarin.Mac projects use 'CodeSigningKey' -->
<_SpecifiedCodesignKey Condition="'$(_PlatformName)' != 'macOS'">$(CodesignKey)</_SpecifiedCodesignKey> <!-- Xamarin.iOS projects use 'CodesignKey' -->
<!-- Xamarin.Mac projects use 'CodeSigningKey', and Xamarin.iOS projects use 'CodesignKey'. -->
<!-- Here we accept both, and we'll recommend using 'CodesignKey' for all platforms going forward -->
<_SpecifiedCodesignKey Condition="'$(_SpecifiedCodesignKey)' == ''">$(CodeSigningKey)</_SpecifiedCodesignKey>
<_SpecifiedCodesignKey Condition="'$(_SpecifiedCodesignKey)' == ''">$(CodesignKey)</_SpecifiedCodesignKey>
<!-- If we should create a .pkg or not (only relevant for macOS / Mac Catalyst) -->
<!-- The equivalent property for the other platforms is 'BuildIpa' -->
<CreatePackage Condition="'$(CreatePackage)' == ''">false</CreatePackage>
<!-- If the .pkg should be signed or not. Applicable to macOS and Mac Catalyst. Defaults to false. -->
<EnablePackageSigning Condition="'$(EnablePackageSigning)' == ''">false</EnablePackageSigning>
</PropertyGroup>
<PropertyGroup Condition="'$(UsingAppleNETSdk)' != 'true'">
@ -148,6 +188,20 @@ Copyright (C) 2020 Microsoft. All rights reserved.
</PropertyGroup>
<PropertyGroup>
<ArchiveOnBuild Condition="'$(ArchiveOnBuild)' == ''">false</ArchiveOnBuild>
<IsAppExtension Condition="'$(IsAppExtension)' == ''">false</IsAppExtension>
<IsWatchExtension Condition="'$(IsWatchExtension)' == ''">false</IsWatchExtension>
<IsWatchApp Condition="'$(IsWatchApp)' == ''">false</IsWatchApp>
<!-- Xamarin.iOS projects use MtouchEnableSGenConc, and Xamarin.Mac projects use EnableSGenConc -->
<!-- Going forward we're sticking with EnableSGenConc, but we'll accept MtouchEnableSGenConc if it's set -->
<!-- If both are set, EnableSGenConc takes precedence -->
<EnableSGenConc Condition="'$(EnableSGenConc)' == ''">$(MtouchEnableSGenConc)</EnableSGenConc>
<EnableSGenConc Condition="'$(EnableSGenConc)' == ''">false</EnableSGenConc>
<_CanOutputAppBundle>false</_CanOutputAppBundle>
<_CanOutputAppBundle Condition="'$(OutputType)' == 'Exe' Or '$(IsAppExtension)' == 'true' Or '$(IsWatchApp)' == 'true'">true</_CanOutputAppBundle>
<!-- We can archive: -->
<!-- macOS and Mac Catalyst: executable projects which aren't app extensions -->
<!-- iOS, tvOS and watchOS: executable projects built for device which aren't app extensions nor watch apps -->

Просмотреть файл

@ -1568,7 +1568,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<CollectITunesSourceFiles
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true' And '@(_ITunesSourceFile)' == ''"
Condition="'$(IsMacEnabled)' == 'true' And '@(_ITunesSourceFile)' == '' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'"
OutputPath="$(DeviceSpecificOutputPath)"
>
<Output TaskParameter="ITunesSourceFiles" PropertyName="_ITunesSourceFile"/>
@ -1621,6 +1621,54 @@ Copyright (C) 2018 Microsoft. All rights reserved.
</ItemGroup>
</Target>
<Target Name="_CompileProductDefinition" Condition="$(CreatePackage)" DependsOnTargets="_DetectAppManifest;_ComputeTargetArchitectures">
<CompileProductDefinition
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
AppManifest="$(_AppManifest)"
OutputDirectory="$(IntermediateOutputPath)"
ProductDefinition="$(ProductDefinition)"
TargetArchitectures="$(TargetArchitectures)"
>
<Output TaskParameter="CompiledProductDefinition" PropertyName="_CompiledProductDefinition" />
</CompileProductDefinition>
</Target>
<Target Name="_CreateInstaller" Condition="$(CreatePackage)" DependsOnTargets="Codesign;_CompileProductDefinition">
<CreateInstallerPackage
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
AppBundleDir="$(AppBundleDir)"
AppManifest="$(_AppManifest)"
EnablePackageSigning="$(EnablePackageSigning)"
MainAssembly="$(TargetPath)"
Name="$(AssemblyName)"
OutputDirectory="$(TargetDir)"
PackageSigningKey="$(PackageSigningKey)"
PackagingExtraArgs="$(PackagingExtraArgs)"
ProductDefinition="$(_CompiledProductDefinition)"
ProjectPath="$(MSBuildProjectFullPath)"
>
</CreateInstallerPackage>
</Target>
<PropertyGroup>
<!-- Extensibility point for VS Publishing Workflow -->
<_BeforeCreateIpaForDistributionDependsOn />
<CreateIpaDependsOn>
_BeforeCreateIpaForDistribution;
_CompileEntitlements;
_CoreCreateIpa;
_PackageOnDemandResources;
_ZipIpa
</CreateIpaDependsOn>
</PropertyGroup>
<Target Name="_BeforeCreateIpaForDistribution" Condition="'$(IsAppDistribution)' == 'true'" DependsOnTargets="$(_BeforeCreateIpaForDistributionDependsOn)" />
<Target Name="CreateIpa" Condition="'$(_CanArchive)' == 'true' And '$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'" DependsOnTargets="$(CreateIpaDependsOn)" />
<Import Project="$(MSBuildThisFileDirectory)Xamarin.Shared.ObjCBinding.targets" Condition="'$(IsBindingProject)' == 'true'" />
<!-- Xamarin.ImplicitFacade.targets will detect if we need to add an implicit reference to netstandard.dll -->

Просмотреть файл

@ -34,8 +34,6 @@ Copyright (C) 2014-2016 Xamarin. All rights reserved.
<Target Name="Build" Condition="'$(_InvalidConfigurationWarning)' != 'true'" DependsOnTargets="_GenerateBundleName;$(BuildDependsOn)" Outputs="@(_AppExtensionBundlePath)" />
<Target Name="Rebuild" Condition="'$(_InvalidConfigurationWarning)' != 'true'" DependsOnTargets="_GenerateBundleName;$(RebuildDependsOn)" Outputs="@(_AppExtensionBundlePath)" />
<Target Name="CreateIpa"/>
<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets')"/>

Просмотреть файл

@ -94,8 +94,6 @@ Copyright (C) 2015-2016 Xamarin. All rights reserved.
<RemoveDir SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" Directories="$(AppBundleDir).dSYM" />
</Target>
<Target Name="CreateIpa"/>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)NoCode.cs" />
</ItemGroup>

Просмотреть файл

@ -38,8 +38,6 @@ Copyright (C) 2015-2016 Xamarin. All rights reserved.
<Target Name="Build" Condition="'$(_InvalidConfigurationWarning)' != 'true'" DependsOnTargets="_GenerateBundleName;$(BuildDependsOn)" Outputs="@(_AppExtensionBundlePath)" />
<Target Name="Rebuild" Condition="'$(_InvalidConfigurationWarning)' != 'true'" DependsOnTargets="_GenerateBundleName;$(RebuildDependsOn)" Outputs="@(_AppExtensionBundlePath)" />
<Target Name="CreateIpa"/>
<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets')"/>

Просмотреть файл

@ -32,8 +32,6 @@ Copyright (C) 2014-2016 Xamarin. All rights reserved.
<Target Name="Build" Condition="'$(_InvalidConfigurationWarning)' != 'true'" DependsOnTargets="_GenerateBundleName;$(BuildDependsOn)" Outputs="@(_AppExtensionBundlePath)" />
<Target Name="Rebuild" Condition="'$(_InvalidConfigurationWarning)' != 'true'" DependsOnTargets="_GenerateBundleName;$(RebuildDependsOn)" Outputs="@(_AppExtensionBundlePath)" />
<Target Name="CreateIpa"/>
<Import Project="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets"
Condition="Exists('$(MSBuildThisFileDirectory)$(MSBuildThisFileName).After.targets')"/>

Просмотреть файл

@ -29,14 +29,9 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<MtouchEnableBitcode Condition="'$(MtouchEnableBitcode)' == ''">False</MtouchEnableBitcode>
<MtouchUseThumb Condition="'$(MtouchUseThumb)' == ''">False</MtouchUseThumb>
<MtouchProjectDirectory>$(MSBuildProjectDirectory)</MtouchProjectDirectory>
<MtouchEnableSGenConc Condition="'$(MtouchEnableSGenConc)' == ''">False</MtouchEnableSGenConc>
<MtouchVerbosity Condition="$(MtouchVerbosity) == ''">2</MtouchVerbosity>
<IsAppExtension Condition="'$(IsAppExtension)' == ''">False</IsAppExtension>
<IsWatchExtension Condition="'$(IsWatchExtension)' == ''">False</IsWatchExtension>
<IsWatchApp Condition="'$(IsWatchApp)' == ''">False</IsWatchApp>
<IpaIncludeArtwork Condition="'$(IpaIncludeArtwork)' == ''">False</IpaIncludeArtwork>
<ArchiveOnBuild Condition="'$(ArchiveOnBuild)' == ''">False</ArchiveOnBuild>
<BuildIpa Condition="'$(BuildIpa)' == ''">False</BuildIpa>
<BuildSessionId></BuildSessionId>

Просмотреть файл

@ -34,15 +34,9 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Xamarin.Shared.targets" />
<PropertyGroup>
<_CanOutputAppBundle>False</_CanOutputAppBundle>
<_CanOutputAppBundle Condition="'$(OutputType)' == 'Exe' Or '$(IsAppExtension)' == 'true' Or '$(IsWatchApp)' == 'true'">True</_CanOutputAppBundle>
<_CanDeployToDeviceOrSimulator>False</_CanDeployToDeviceOrSimulator>
<_CanDeployToDeviceOrSimulator Condition="('$(OutputType)' == 'Exe' Or '$(IsAppExtension)' == 'true') And '$(IsWatchApp)' == 'false'">True</_CanDeployToDeviceOrSimulator>
<_RequireProvisioningProfile>False</_RequireProvisioningProfile>
<_RequireProvisioningProfile Condition="'$(ComputedPlatform)' == 'iPhone' Or '$(CodesignEntitlements)' != ''">True</_RequireProvisioningProfile>
<_PreparedResourceRules></_PreparedResourceRules>
<_AppBundleName>$(AssemblyName)</_AppBundleName>
</PropertyGroup>
@ -166,19 +160,6 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
</CodesignDependsOn>
</PropertyGroup>
<PropertyGroup>
<!-- Extensibility point for VS Publishing Workflow -->
<_BeforeCreateIpaForDistributionDependsOn />
<CreateIpaDependsOn>
_BeforeCreateIpaForDistribution;
_CompileEntitlements;
_CoreCreateIpa;
_PackageOnDemandResources;
_ZipIpa
</CreateIpaDependsOn>
</PropertyGroup>
<Target Name="ValidateAppStoreBundle" DependsOnTargets="_DetectSdkLocations;_ComputeTargetFrameworkMoniker">
<ALToolValidate
SessionId="$(BuildSessionId)"
@ -201,10 +182,6 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
/>
</Target>
<Target Name="_BeforeCreateIpaForDistribution" Condition="'$(IsAppDistribution)' == 'true'" DependsOnTargets="$(_BeforeCreateIpaForDistributionDependsOn)" />
<Target Name="CreateIpa" Condition="'$(_CanArchive)' == 'true'" DependsOnTargets="$(CreateIpaDependsOn)" />
<Target Name="_CleanUploaded" Condition="'$(_CanOutputAppBundle)' == 'true'" DependsOnTargets="_ComputeTargetArchitectures">
<Delete SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" Files="$(DeviceSpecificOutputPath).uploaded" />
</Target>
@ -338,7 +315,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
UseFloat32="$(MtouchFloat32)"
UseThumb="$(MtouchUseThumb)"
EnableBitcode="$(MtouchEnableBitcode)"
EnableSGenConc="$(MtouchEnableSGenConc)"
EnableSGenConc="$(EnableSGenConc)"
Interpreter="$(MtouchInterpreter)"
AppExtensionReferences="@(_ResolvedAppExtensionReferences)"
ArchiveSymbols="$(MonoSymbolArchive)"

Просмотреть файл

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using NUnit.Framework;
using Xamarin.Utils;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging.StructuredLogger;
namespace Xamarin.Tests {
[TestFixture]
public class PostBuildTest : TestBaseClass {
[Test]
[TestCase (ApplePlatform.iOS, "ios-arm64")]
[TestCase (ApplePlatform.iOS, "ios-arm64;ios-arm")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
public void ArchiveTest (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = new Dictionary<string, string> (verbosity);
var multiRid = runtimeIdentifiers.IndexOf (';') >= 0 ? "RuntimeIdentifiers" : "RuntimeIdentifier";
if (!string.IsNullOrEmpty (runtimeIdentifiers))
properties [multiRid] = runtimeIdentifiers;
properties ["ArchiveOnBuild"] = "true";
var result = DotNet.AssertBuild (project_path, properties);
var reader = new BinLogReader ();
var records = reader.ReadRecords (result.BinLogPath).ToList ();
var findString = "Output Property: ArchiveDir";
var archiveDirRecord = records.Where (v => v?.Args?.Message?.Contains (findString) == true).ToList ();
Assert.That (archiveDirRecord.Count, Is.GreaterThan (0), "ArchiveDir");
var archiveDir = archiveDirRecord [0].Args.Message.Substring (findString.Length + 1).Trim ();
Assert.That (archiveDir, Does.Exist, "Archive directory existence");
}
[Test]
[TestCase (ApplePlatform.iOS, "ios-arm64")]
[TestCase (ApplePlatform.iOS, "ios-arm64;ios-arm")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64")]
public void BuildIpaTest (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = new Dictionary<string, string> (verbosity);
var multiRid = runtimeIdentifiers.IndexOf (';') >= 0 ? "RuntimeIdentifiers" : "RuntimeIdentifier";
if (!string.IsNullOrEmpty (runtimeIdentifiers))
properties [multiRid] = runtimeIdentifiers;
properties ["BuildIpa"] = "true";
DotNet.AssertBuild (project_path, properties);
var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", platform.ToFramework (), runtimeIdentifiers.IndexOf (';') >= 0 ? string.Empty : runtimeIdentifiers, $"{project}.app");
var pkgPath = Path.Combine (appPath, "..", $"{project}.ipa");
Assert.That (pkgPath, Does.Exist, "pkg creation");
}
[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-x64")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
public void BuildPackageTest (ApplePlatform platform, string runtimeIdentifiers)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = new Dictionary<string, string> (verbosity);
var multiRid = runtimeIdentifiers.IndexOf (';') >= 0 ? "RuntimeIdentifiers" : "RuntimeIdentifier";
if (!string.IsNullOrEmpty (runtimeIdentifiers))
properties [multiRid] = runtimeIdentifiers;
properties ["CreatePackage"] = "true";
DotNet.AssertBuild (project_path, properties);
var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", platform.ToFramework (), runtimeIdentifiers.IndexOf (';') >= 0 ? string.Empty : runtimeIdentifiers, $"{project}.app");
var pkgPath = Path.Combine (appPath, "..", $"{project}.pkg");
Assert.That (pkgPath, Does.Exist, "pkg creation");
}
}
}

Просмотреть файл

@ -15,43 +15,7 @@ using Xamarin.MacDev;
namespace Xamarin.Tests {
[TestFixture]
public class DotNetProjectTest {
Dictionary<string, string> verbosity = new Dictionary<string, string> {
{ "MtouchExtraArgs", "-v" },
{ "MonoBundlingExtraArgs", "-v" },
};
string GetProjectPath (string project, string subdir = null, ApplePlatform? platform = null)
{
var project_dir = Path.Combine (Configuration.SourceRoot, "tests", "dotnet", project);
if (!string.IsNullOrEmpty (subdir))
project_dir = Path.Combine (project_dir, subdir);
if (platform.HasValue)
project_dir = Path.Combine (project_dir, platform.Value.AsString ());
var project_path = Path.Combine (project_dir, project + ".csproj");
if (!File.Exists (project_path))
project_path = Path.ChangeExtension (project_path, "sln");
if (!File.Exists (project_path))
throw new FileNotFoundException ($"Could not find the project or solution {project} - {project_path} does not exist.");
return project_path;
}
void Clean (string project_path)
{
var dirs = Directory.GetDirectories (Path.GetDirectoryName (project_path), "*", SearchOption.AllDirectories);
dirs = dirs.OrderBy (v => v.Length).Reverse ().ToArray (); // If we have nested directories, make sure to delete the nested one first
foreach (var dir in dirs) {
var name = Path.GetFileName (dir);
if (name != "bin" && name != "obj")
continue;
Directory.Delete (dir, true);
}
}
public class DotNetProjectTest : TestBaseClass {
[Test]
[TestCase (null)]
[TestCase ("iossimulator-x86")]

Просмотреть файл

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Mono.Cecil;
using NUnit.Framework;
using Xamarin.Utils;
using Xamarin.Tests;
using Xamarin.MacDev;
namespace Xamarin.Tests {
[TestFixture]
public abstract class TestBaseClass {
protected Dictionary<string, string> verbosity = new Dictionary<string, string> {
{ "MtouchExtraArgs", "-v" },
{ "MonoBundlingExtraArgs", "-v" },
};
protected string GetProjectPath (string project, string subdir = null, ApplePlatform? platform = null)
{
var project_dir = Path.Combine (Configuration.SourceRoot, "tests", "dotnet", project);
if (!string.IsNullOrEmpty (subdir))
project_dir = Path.Combine (project_dir, subdir);
if (platform.HasValue)
project_dir = Path.Combine (project_dir, platform.Value.AsString ());
var project_path = Path.Combine (project_dir, project + ".csproj");
if (!File.Exists (project_path))
project_path = Path.ChangeExtension (project_path, "sln");
if (!File.Exists (project_path))
throw new FileNotFoundException ($"Could not find the project or solution {project} - {project_path} does not exist.");
return project_path;
}
protected void Clean (string project_path)
{
var dirs = Directory.GetDirectories (Path.GetDirectoryName (project_path), "*", SearchOption.AllDirectories);
dirs = dirs.OrderBy (v => v.Length).Reverse ().ToArray (); // If we have nested directories, make sure to delete the nested one first
foreach (var dir in dirs) {
var name = Path.GetFileName (dir);
if (name != "bin" && name != "obj")
continue;
Directory.Delete (dir, true);
}
}
}
}