Skip to content

Commit 57c5a5f

Browse files
[One .NET] fix duplicate .pdb files for multiple RIDs (#5236)
Deploying a project that uses two `$(RuntimeIdentifiers)` will fail on our new fast deploy system with: Xamarin.Android.Common.Debugging.targets(589,5): Access to the path 'obj/Debug/net5.0-android/android/assets/' is denied. at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at Xamarin.Android.Tasks.FastDeploy.DeployFileWithFastDevTool(ITaskItem file, String toolPath, String overridePath, Byte[] buffer, Byte[] compressed, LZ4Level lz4level) at Xamarin.Android.Tasks.FastDeploy.DeployFastDevFiles(String toolPath, String overridePath) at Xamarin.Android.Tasks.FastDeploy.RunTaskAsync() Reviewing the log, there are some weird things happening. Some incorrect `@(_ResolvedSymbols)` items are passed to the `<FastDeploy/>` MSBuild task: _ResolvedSymbols obj/Debug/net5.0-android/android/assets/ obj/Debug/net5.0-android/android/assets/ The expectation is that `@(_ResolvedSymbols)` contain *files*, not directories; in particular, `@(_ResolvedSymbols)` should contain `HelloForms.pdb`! This is caused by the contents of the `@(ResolvedFileToPublish)` item group that is populated by the `ComputeFilesToPublish` MSBuild target in the dotnet/sdk: ResolvedFileToPublish obj/Debug/net5.0-android/HelloForms.dll obj/Debug/net5.0-android/android.21-arm64/HelloForms.pdb obj/Debug/net5.0-android/android.21-x86/HelloForms.pdb The `HelloForms.pdb` files listed here do not actually *exist*; the path should be: `obj/Debug/net5.0-android/HelloForms.pdb`. This is caused by the way our "outer" build (51fb93e) has no `$(RuntimeIdentifer)`, while we have an "inner" build that's per-RID. The "inner" build needs to fix up the `@(_DebugSymbolsIntermediatePath)` item group to account for this; see the [`ComputeResolvedFilesToPublishList` MSBuild target][0]. We were already fixing up `@(IntermediateAssembly)`. When `HelloForms.dll` did not map to a single `HelloForms.pdb`, the `%(DestinationSubPath)` item metadata is not added by the `<ProcessAssemblies/>` MSBuild task in Xamarin.Android. Thus the following item transform generated an incorrect result: <_ResolvedSymbols Include="@(ResolvedSymbols->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" /> To fix this: * `@(_ResolvedSymbols)` should check if `%(DestinationSubPath)` is blank. * Call `->Distinct()` on input to the `<ProcessAssemblies/>` MSBuild task. * Patch up the `@(_DebugSymbolsIntermediatePath)` item group, so that it uses the proper value for `@(IntermediateOutputPath)` of the outer build. See dotnet/msbuild for the definition of the [`@(_DebugSymbolsIntermediatePath)` item group][1]. After these changes, the `@(ResolvedFileToPublish)` item group appears correct now: ResolvedFileToPublish obj/Debug/net5.0-android/HelloForms.dll obj/Debug/net5.0-android/HelloForms.pdb and `HelloForms.pdb` now makes it to the `.apk` file as well. Other changes: * Updated a test to look for `UnnamedProject.pdb` during a multiple RID build. * I removed the `Removing duplicate: ...` log message, as it was printing hundreds of log messages that aren't particularly useful. [0]: https://github.com/dotnet/sdk/blob/ee455863aa6ddf13108bb54b37a5a47fb12fe39e/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L522-L555 [1]: https://github.com/dotnet/msbuild/blob/65d31a0151b072b910d9ea16e152265d467e3239/src/Tasks/Microsoft.Common.CurrentVersion.targets#L374
1 parent 519ca83 commit 57c5a5f

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ _ResolveAssemblies MSBuild target.
3333
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
3434
<IntermediateAssembly Include="$(_OuterIntermediateAssembly)" />
3535
</ItemGroup>
36+
<ItemGroup Condition=" '@(_DebugSymbolsIntermediatePath->Count())' != '0' ">
37+
<_DebugSymbolsIntermediatePath Remove="@(_DebugSymbolsIntermediatePath)" />
38+
<_DebugSymbolsIntermediatePath Include="$([System.IO.Path]::ChangeExtension ($(_OuterIntermediateAssembly), '.pdb'))" />
39+
</ItemGroup>
3640
</Target>
3741

3842
<Target Name="_ResolveAssemblies">
@@ -67,8 +71,8 @@ _ResolveAssemblies MSBuild target.
6771
Condition=" '%(Identity)' != '' "
6872
/>
6973
<ProcessAssemblies
70-
InputAssemblies="@(_ResolvedAssemblyFiles)"
71-
ResolvedSymbols="@(_ResolvedSymbolFiles)"
74+
InputAssemblies="@(_ResolvedAssemblyFiles->Distinct())"
75+
ResolvedSymbols="@(_ResolvedSymbolFiles->Distinct())"
7276
IncludeDebugSymbols="$(AndroidIncludeDebugSymbols)"
7377
LinkMode="$(AndroidLinkMode)">
7478
<Output TaskParameter="OutputAssemblies" ItemName="_ProcessedAssemblies" />
@@ -121,10 +125,10 @@ _ResolveAssemblies MSBuild target.
121125
<Target Name="_PrepareAssemblies"
122126
DependsOnTargets="$(_PrepareAssembliesDependsOnTargets)">
123127
<ItemGroup Condition=" '$(AndroidLinkMode)' == 'None' And '$(AndroidIncludeDebugSymbols)' == 'true' ">
124-
<_ResolvedAssemblies Include="@(ResolvedAssemblies->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" />
125-
<_ResolvedUserAssemblies Include="@(ResolvedUserAssemblies->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" />
126-
<_ResolvedFrameworkAssemblies Include="@(ResolvedFrameworkAssemblies->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" />
127-
<_ResolvedSymbols Include="@(ResolvedSymbols->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" />
128+
<_ResolvedAssemblies Include="@(ResolvedAssemblies->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" Condition=" '%(DestinationSubPath)' != '' " />
129+
<_ResolvedUserAssemblies Include="@(ResolvedUserAssemblies->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" Condition=" '%(DestinationSubPath)' != '' " />
130+
<_ResolvedFrameworkAssemblies Include="@(ResolvedFrameworkAssemblies->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" Condition=" '%(DestinationSubPath)' != '' " />
131+
<_ResolvedSymbols Include="@(ResolvedSymbols->'$(MonoAndroidIntermediateAssemblyDir)%(DestinationSubPath)')" Condition=" '%(DestinationSubPath)' != '' " />
128132
<_ShrunkAssemblies Include="@(_ResolvedAssemblies)" />
129133
<_ShrunkUserAssemblies Include="@(_ResolvedUserAssemblies)" />
130134
<_ShrunkFrameworkAssemblies Include="@(_ResolvedFrameworkAssemblies)" />

src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ public override bool RunTask ()
6666
assembly.SetMetadata ("FrameworkAssembly", frameworkAssembly.ToString ());
6767
assembly.SetMetadata ("HasMonoAndroidReference", MonoAndroidHelper.HasMonoAndroidReference (reader).ToString ());
6868
} else {
69-
Log.LogDebugMessage ($"Removing duplicate: {assembly.ItemSpec}");
70-
71-
var symbolPath = Path.ChangeExtension (assembly.ItemSpec, ".pdb");
72-
if (symbols.Remove (symbolPath)) {
73-
Log.LogDebugMessage ($"Removing duplicate: {symbolPath}");
74-
}
69+
symbols.Remove (Path.ChangeExtension (assembly.ItemSpec, ".pdb"));
7570
}
7671
}
7772
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,16 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease)
360360
var apkPath = Path.Combine (outputPath, "UnnamedProject.UnnamedProject.apk");
361361
FileAssert.Exists (apkPath);
362362
using (var apk = ZipHelper.OpenZip (apkPath)) {
363+
apk.AssertContainsEntry (apkPath, $"assemblies/{proj.ProjectName}.dll", shouldContainEntry: expectEmbeddedAssembies);
364+
apk.AssertContainsEntry (apkPath, $"assemblies/{proj.ProjectName}.pdb", shouldContainEntry: !CommercialBuildAvailable && !isRelease);
363365
var rids = runtimeIdentifiers.Split (';');
364366
foreach (var abi in rids.Select (MonoAndroidHelper.RuntimeIdentifierToAbi)) {
365367
apk.AssertContainsEntry (apkPath, $"lib/{abi}/libmonodroid.so");
366368
apk.AssertContainsEntry (apkPath, $"lib/{abi}/libmonosgen-2.0.so");
367369
if (rids.Length > 1) {
368-
apk.AssertContainsEntry (apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", expectEmbeddedAssembies);
370+
apk.AssertContainsEntry (apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies);
369371
} else {
370-
apk.AssertContainsEntry (apkPath, "assemblies/System.Private.CoreLib.dll", expectEmbeddedAssembies);
372+
apk.AssertContainsEntry (apkPath, "assemblies/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies);
371373
}
372374
}
373375
}

0 commit comments

Comments
 (0)