|
47 | 47 | <Exec Command=""$(DotNetPreviewTool)" pack @(_PackProps, ' ') "$(XamarinAndroidSourcePath)src\Microsoft.Android.Templates\Microsoft.Android.Templates.csproj"" /> |
48 | 48 | </Target> |
49 | 49 |
|
| 50 | + <UsingTask TaskName="GetAndroidWorkloadExtends" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 51 | + <ParameterGroup> |
| 52 | + <JsonFilePath ParameterType="System.String" Required="true" /> |
| 53 | + <ExtendsElement Output="true" ParameterType="System.String" /> |
| 54 | + </ParameterGroup> |
| 55 | + <Task> |
| 56 | + <Using Namespace="System" /> |
| 57 | + <Using Namespace="System.IO" /> |
| 58 | + <Code Type="Fragment" Language="cs"> |
| 59 | + <![CDATA[ |
| 60 | + var jsonContent = File.ReadAllText(JsonFilePath); |
| 61 | + var startElement = "\"extends\" : ["; |
| 62 | + var startIndex = jsonContent.IndexOf(startElement); |
| 63 | + var endIndex = jsonContent.IndexOf("]"); |
| 64 | + if (startIndex != -1) { |
| 65 | + startIndex += startElement.Length; |
| 66 | + endIndex = jsonContent.IndexOf("]", startIndex); |
| 67 | + if (endIndex != -1) { |
| 68 | + ExtendsElement = jsonContent.Substring(startIndex, endIndex - startIndex)?.Trim(); |
| 69 | + } |
| 70 | + } |
| 71 | + if (startIndex == -1 || endIndex == -1 || string.IsNullOrEmpty(ExtendsElement)) |
| 72 | + Log.LogError($"Failed to find extends element in workload json '{JsonFilePath}'"); |
| 73 | + ]]> |
| 74 | + </Code> |
| 75 | + </Task> |
| 76 | + </UsingTask> |
| 77 | + |
50 | 78 | <Target Name="InstallManifestAndDependencies" |
51 | 79 | DependsOnTargets="_GetDefaultPackageVersion"> |
52 | 80 | <PropertyGroup> |
|
62 | 90 | Targets="_GenerateXAWorkloadContent" |
63 | 91 | /> |
64 | 92 |
|
| 93 | + <GetAndroidWorkloadExtends JsonFilePath="$(_LocalAndroidManifestFolder)WorkloadManifest.json"> |
| 94 | + <Output TaskParameter="ExtendsElement" PropertyName="AndroidWorkloadExtendsElement" /> |
| 95 | + </GetAndroidWorkloadExtends> |
| 96 | + |
65 | 97 | <PropertyGroup> |
66 | 98 | <_EmptyWorkloadJsonContent> |
67 | 99 | <![CDATA[ |
68 | | -{"version": "0.0.1", "workloads": { "android-deps": { "extends" : [ "microsoft-net-runtime-android" ] } } } |
| 100 | +{"version": "0.0.1", "workloads": { "android-deps": { "extends" : [ $(AndroidWorkloadExtendsElement) ] } } } |
69 | 101 | ]]> |
70 | 102 | </_EmptyWorkloadJsonContent> |
71 | 103 | </PropertyGroup> |
72 | 104 |
|
73 | 105 | <!-- Create empty workload to install dotnet/runtime dependencies, and then clean up the workload and metadata files from install --> |
| 106 | + <Error Condition=" '$(AndroidWorkloadExtendsElement)' == '' " Text="Failed to find extends element in workload json" /> |
74 | 107 | <MakeDir Directories="$(_EmptyWorkloadDir)" /> |
75 | 108 | <WriteLinesToFile |
76 | 109 | File="$(_EmptyWorkloadDir)WorkloadManifest.json" |
|
0 commit comments