Skip to content

Commit 4d34ee0

Browse files
[One .NET] fix duplicate .pdb files for multiple RIDs
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) in /Users/builder/azdo/_work/18/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 579 at Xamarin.Android.Tasks.FastDeploy.DeployFastDevFiles(String toolPath, String overridePath) in /Users/builder/azdo/_work/18/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 491 at Xamarin.Android.Tasks.FastDeploy.RunTaskAsync() in /Users/builder/azdo/_work/18/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 175 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/ This is caused by the contents of the `@(ResolvedFileToPublish)` item group: 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 Since `HelloForms.dll` doesn't map to a single `HelloForms.pdb`, the `%(DestinationSubPath)` item metadata is not added by the `<ProcessAssemblies/>` MSBuild task. And so the following item transform generates 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: https://github.com/dotnet/msbuild/blob/65d31a0151b072b910d9ea16e152265d467e3239/src/Tasks/Microsoft.Common.CurrentVersion.targets#L374 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 `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.
1 parent d60d160 commit 4d34ee0

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
@@ -359,14 +359,16 @@ public void DotNetBuild (string runtimeIdentifiers, bool isRelease)
359359
var apkPath = Path.Combine (outputPath, "UnnamedProject.UnnamedProject.apk");
360360
FileAssert.Exists (apkPath);
361361
using (var apk = ZipHelper.OpenZip (apkPath)) {
362+
apk.AssertContainsEntry (apkPath, $"assemblies/{proj.ProjectName}.dll", shouldContainEntry: expectEmbeddedAssembies);
363+
apk.AssertContainsEntry (apkPath, $"assemblies/{proj.ProjectName}.pdb", shouldContainEntry: !CommercialBuildAvailable && !isRelease);
362364
var rids = runtimeIdentifiers.Split (';');
363365
foreach (var abi in rids.Select (MonoAndroidHelper.RuntimeIdentifierToAbi)) {
364366
apk.AssertContainsEntry (apkPath, $"lib/{abi}/libmonodroid.so");
365367
apk.AssertContainsEntry (apkPath, $"lib/{abi}/libmonosgen-2.0.so");
366368
if (rids.Length > 1) {
367-
apk.AssertContainsEntry (apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", expectEmbeddedAssembies);
369+
apk.AssertContainsEntry (apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies);
368370
} else {
369-
apk.AssertContainsEntry (apkPath, "assemblies/System.Private.CoreLib.dll", expectEmbeddedAssembies);
371+
apk.AssertContainsEntry (apkPath, "assemblies/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies);
370372
}
371373
}
372374
}

0 commit comments

Comments
 (0)