Skip to content

Commit cd9c9ff

Browse files
[Xamarin.Android.Build.Tasks] fix cases of missing @(Reference) (#7947)
Context: https://github.com/dotnet/msbuild/blob/c75672a6e7387bc5c1f99c166e9277351144b14c/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2327 Fixes: dotnet/maui#10154 This partially reverts c1efcb5. Previously, we removed this change because it broke .NET MAUI's build with: Unable to open file 'obj\Release\net8.0-android\android-x64\aot\x86_64\Microsoft.Maui.Controls.resources\temp.s': Permission denied The problem being that the .NET SDK was placing satellite assemblies in the `@(ResolvedFileToPublish)` item group. Let's apply our change from before, but also set `$(ResolveAssemblyReferencesFindRelatedSatellites)` to `false` for our "inner build" per `$(RuntimeIdentifier)`. This solves the original issue for dotnet/maui#10154 without changing behavior of satellite assemblies. I added `.resx` files in our new test, and assert that satellite assemblies make to apps for good measure.
1 parent b4438e7 commit cd9c9ff

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ _ResolveAssemblies MSBuild target.
4444
</PropertyGroup>
4545

4646
<Target Name="_ComputeFilesToPublishForRuntimeIdentifiers"
47-
DependsOnTargets="_FixupIntermediateAssembly;ResolveReferences;ComputeFilesToPublish;$(_RunAotMaybe)"
47+
DependsOnTargets="BuildOnlySettings;_FixupIntermediateAssembly;ResolveReferences;ComputeFilesToPublish;$(_RunAotMaybe)"
4848
Returns="@(ResolvedFileToPublish)">
4949
<ItemGroup>
5050
<ResolvedFileToPublish Remove="@(_SourceItemsToCopyToPublishDirectory)" />
@@ -90,6 +90,7 @@ _ResolveAssemblies MSBuild target.
9090
<_AdditionalProperties>
9191
_ComputeFilesToPublishForRuntimeIdentifiers=true
9292
;AppendRuntimeIdentifierToOutputPath=true
93+
;ResolveAssemblyReferencesFindRelatedSatellites=false
9394
;SkipCompilerExecution=true
9495
;_OuterIntermediateAssembly=@(IntermediateAssembly)
9596
;_OuterOutputPath=$(OutputPath)

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,82 @@ public void DotNetIncremental ([Values (true, false)] bool isRelease, [Values ("
11081108
}
11091109
}
11101110

1111+
[Test]
1112+
public void ProjectDependencies ([Values(true, false)] bool projectReference)
1113+
{
1114+
// Setup dependencies App A -> Lib B -> Lib C
1115+
var path = Path.Combine ("temp", TestName);
1116+
1117+
var libB = new XASdkProject (outputType: "Library") {
1118+
ProjectName = "LibraryB",
1119+
IsRelease = true,
1120+
};
1121+
libB.Sources.Clear ();
1122+
libB.Sources.Add (new BuildItem.Source ("Foo.cs") {
1123+
TextContent = () => @"public class Foo {
1124+
public Foo () {
1125+
var bar = new Bar();
1126+
}
1127+
}",
1128+
});
1129+
1130+
var libC = new XASdkProject (outputType: "Library") {
1131+
ProjectName = "LibraryC",
1132+
IsRelease = true,
1133+
};
1134+
libC.Sources.Clear ();
1135+
libC.Sources.Add (new BuildItem.Source ("Bar.cs") {
1136+
TextContent = () => "public class Bar { }",
1137+
});
1138+
libC.Sources.Add (new BuildItem ("EmbeddedResource", "Foo.resx") {
1139+
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
1140+
});
1141+
libC.Sources.Add (new BuildItem ("EmbeddedResource", "Foo.es.resx") {
1142+
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancelar</value></data>")
1143+
});
1144+
1145+
// Add a @(Reference) or @(ProjectReference)
1146+
if (projectReference) {
1147+
libB.AddReference (libC);
1148+
} else {
1149+
libB.OtherBuildItems.Add (new BuildItem.Reference ($@"..\{libC.ProjectName}\bin\Release\{libC.TargetFramework}\{libC.ProjectName}.dll"));
1150+
}
1151+
1152+
// Build libraries
1153+
var libCBuilder = CreateDotNetBuilder (libC, Path.Combine (path, libC.ProjectName));
1154+
Assert.IsTrue (libCBuilder.Build (), $"{libC.ProjectName} should succeed");
1155+
var libBBuilder = CreateDotNetBuilder (libB, Path.Combine (path, libB.ProjectName));
1156+
Assert.IsTrue (libBBuilder.Build (), $"{libB.ProjectName} should succeed");
1157+
1158+
var appA = new XASdkProject {
1159+
ProjectName = "AppA",
1160+
IsRelease = true,
1161+
Sources = {
1162+
new BuildItem.Source ("Bar.cs") {
1163+
TextContent = () => "public class Bar : Foo { }",
1164+
},
1165+
new BuildItem ("EmbeddedResource", "Foo.resx") {
1166+
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
1167+
},
1168+
new BuildItem ("EmbeddedResource", "Foo.es.resx") {
1169+
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancelar</value></data>")
1170+
},
1171+
}
1172+
};
1173+
appA.AddReference (libB);
1174+
var appBuilder = CreateDotNetBuilder (appA, Path.Combine (path, appA.ProjectName));
1175+
Assert.IsTrue (appBuilder.Build (), $"{appA.ProjectName} should succeed");
1176+
1177+
var apkPath = Path.Combine (FullProjectDirectory, appA.OutputPath, $"{appA.PackageName}-Signed.apk");
1178+
FileAssert.Exists (apkPath);
1179+
var helper = new ArchiveAssemblyHelper (apkPath);
1180+
helper.AssertContainsEntry ($"assemblies/{appA.ProjectName}.dll");
1181+
helper.AssertContainsEntry ($"assemblies/{libB.ProjectName}.dll");
1182+
helper.AssertContainsEntry ($"assemblies/{libC.ProjectName}.dll");
1183+
helper.AssertContainsEntry ($"assemblies/es/{appA.ProjectName}.resources.dll");
1184+
helper.AssertContainsEntry ($"assemblies/es/{libC.ProjectName}.resources.dll");
1185+
}
1186+
11111187
[Test]
11121188
public void DotNetDesignTimeBuild ()
11131189
{

0 commit comments

Comments
 (0)