Skip to content

Commit 2ba11d6

Browse files
Revert "Remove $(AndroidWorkloadExtendsElement)"
This reverts commit 2d07a35.
1 parent e4a6ec3 commit 2ba11d6

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

build-tools/create-packs/ConfigureLocalWorkload.targets

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@
4747
<Exec Command="&quot;$(DotNetPreviewTool)&quot; pack @(_PackProps, ' ') &quot;$(XamarinAndroidSourcePath)src\Microsoft.Android.Templates\Microsoft.Android.Templates.csproj&quot;" />
4848
</Target>
4949

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+
5078
<Target Name="InstallManifestAndDependencies"
5179
DependsOnTargets="_GetDefaultPackageVersion">
5280
<PropertyGroup>
@@ -62,15 +90,20 @@
6290
Targets="_GenerateXAWorkloadContent"
6391
/>
6492

93+
<GetAndroidWorkloadExtends JsonFilePath="$(_LocalAndroidManifestFolder)WorkloadManifest.json">
94+
<Output TaskParameter="ExtendsElement" PropertyName="AndroidWorkloadExtendsElement" />
95+
</GetAndroidWorkloadExtends>
96+
6597
<PropertyGroup>
6698
<_EmptyWorkloadJsonContent>
6799
<![CDATA[
68-
{"version": "0.0.1", "workloads": { "android-deps": { "extends" : [ "microsoft-net-runtime-android" ] } } }
100+
{"version": "0.0.1", "workloads": { "android-deps": { "extends" : [ $(AndroidWorkloadExtendsElement) ] } } }
69101
]]>
70102
</_EmptyWorkloadJsonContent>
71103
</PropertyGroup>
72104

73105
<!-- 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" />
74107
<MakeDir Directories="$(_EmptyWorkloadDir)" />
75108
<WriteLinesToFile
76109
File="$(_EmptyWorkloadDir)WorkloadManifest.json"

0 commit comments

Comments
 (0)