Added `Run` target for Android

* split up `Directory.Build.targets` into iOS and Android files
* did this so the Android `Run` target won't interfere with iOS
This commit is contained in:
Jonathan Peppers 2020-04-23 08:23:28 -05:00
Родитель e62eda746e
Коммит fcf4d58c32
4 изменённых файлов: 49 добавлений и 31 удалений

26
Directory.Android.targets Normal file
Просмотреть файл

@ -0,0 +1,26 @@
<Project>
<PropertyGroup>
<AssetTargetFallback>monoandroid10.0;monoandroid90;monoandroid81;monoandroid80;$(AssetTargetFallback)</AssetTargetFallback>
<!-- Workaround to skip a .NET 4.5 MSBuild task: https://github.com/xamarin/AndroidSupportComponents/blob/68d28bc676673ec45f7f5ea2462c10bed87e2a2a/source/buildtasks/support-vector-drawable/Support-Vector-Drawable-BuildTasks.csproj#L10 -->
<VectorDrawableCheckBuildToolsVersionTaskBeforeTargets />
</PropertyGroup>
<!-- NOTE: the target below is workarounds for $(AssetTargetFallback) usage -->
<!-- related: https://github.com/NuGet/docs.microsoft.com-nuget/issues/1955 -->
<Target
Name="FixAndroidNuGetAssemblies"
AfterTargets="ResolvePackageAssets"
Condition="'$(PkgXamarin_Forms)' != ''">
<ItemGroup>
<Reference Include="Xamarin.Forms.Platform" HintPath="$(PkgXamarin_Forms)\lib\MonoAndroid10.0\Xamarin.Forms.Platform.dll" />
<Reference Include="Xamarin.Forms.Platform.Android" HintPath="$(PkgXamarin_Forms)\lib\MonoAndroid10.0\Xamarin.Forms.Platform.Android.dll" />
<Reference Include="FormsViewGroup" HintPath="$(PkgXamarin_Forms)\lib\MonoAndroid10.0\FormsViewGroup.dll" />
<RuntimeCopyLocalItems Remove="$(PkgXamarin_Forms)\lib\netstandard2.0\Xamarin.Forms.Platform.dll" />
<ResolvedCompileFileDefinitions Remove="$(PkgXamarin_Forms)\lib\netstandard2.0\Xamarin.Forms.Platform.dll" />
</ItemGroup>
</Target>
<Target Name="Run" DependsOnTargets="StartAndroidActivity" />
</Project>

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

@ -1,33 +1,4 @@
<Project>
<PropertyGroup Condition="'$(UsingAndroidNETSdk)' == 'true'">
<AssetTargetFallback>monoandroid10.0;monoandroid90;monoandroid81;monoandroid80;$(AssetTargetFallback)</AssetTargetFallback>
<!-- Workaround to skip a .NET 4.5 MSBuild task: https://github.com/xamarin/AndroidSupportComponents/blob/68d28bc676673ec45f7f5ea2462c10bed87e2a2a/source/buildtasks/support-vector-drawable/Support-Vector-Drawable-BuildTasks.csproj#L10 -->
<VectorDrawableCheckBuildToolsVersionTaskBeforeTargets />
</PropertyGroup>
<!-- NOTE: the target below is workarounds for $(AssetTargetFallback) usage -->
<!-- related: https://github.com/NuGet/docs.microsoft.com-nuget/issues/1955 -->
<Target
Name="FixAndroidNuGetAssemblies"
AfterTargets="ResolvePackageAssets"
Condition="'$(UsingAndroidNETSdk)' == 'true' and '$(PkgXamarin_Forms)' != ''">
<ItemGroup>
<Reference Include="Xamarin.Forms.Platform" HintPath="$(PkgXamarin_Forms)\lib\MonoAndroid10.0\Xamarin.Forms.Platform.dll" />
<Reference Include="Xamarin.Forms.Platform.Android" HintPath="$(PkgXamarin_Forms)\lib\MonoAndroid10.0\Xamarin.Forms.Platform.Android.dll" />
<Reference Include="FormsViewGroup" HintPath="$(PkgXamarin_Forms)\lib\MonoAndroid10.0\FormsViewGroup.dll" />
<RuntimeCopyLocalItems Remove="$(PkgXamarin_Forms)\lib\netstandard2.0\Xamarin.Forms.Platform.dll" />
<ResolvedCompileFileDefinitions Remove="$(PkgXamarin_Forms)\lib\netstandard2.0\Xamarin.Forms.Platform.dll" />
</ItemGroup>
</Target>
<Target
Name="SetiOSDefaultPublishProps"
BeforeTargets="PrepareForPublish"
Condition="$(RuntimeIdentifier.StartsWith('ios'))">
<PropertyGroup>
<PublishTrimmed>True</PublishTrimmed>
<MonoAOT>True</MonoAOT>
<UseAppHost>False</UseAppHost>
</PropertyGroup>
</Target>
<Import Condition="$(RuntimeIdentifier.StartsWith('android'))" Project="Directory.Android.targets" />
<Import Condition="$(RuntimeIdentifier.StartsWith('ios'))" Project="Directory.iOS.targets" />
</Project>

11
Directory.iOS.targets Normal file
Просмотреть файл

@ -0,0 +1,11 @@
<Project>
<Target Name="SetiOSDefaultPublishProps" BeforeTargets="PrepareForPublish">
<PropertyGroup>
<PublishTrimmed>True</PublishTrimmed>
<MonoAOT>True</MonoAOT>
<UseAppHost>False</UseAppHost>
</PropertyGroup>
</Target>
</Project>

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

@ -10,6 +10,8 @@ Projects:
* HelloiOS - a native Xamarin.iOS application
* HelloForms, HelloForms.iOS, HelloForms.Android - a cross-platform Xamarin.Forms application
### Android
For example, to build the Android project:
dotnet publish HelloAndroid\HelloAndroid.csproj
@ -23,6 +25,14 @@ the `.csproj` or run:
dotnet publish -t:Install HelloAndroid\HelloAndroid.csproj -r android.21-arm64
To launch the app:
dotnet publish -t:Run HelloAndroid\HelloAndroid.csproj
_This can also be done at the same time as `-t:Install`._
### iOS
To build the iOS project:
dotnet publish HelloiOS/HelloiOS.csproj --self-contained