Skip to content

Commit 6c1a9d0

Browse files
committed
Add output DebugSymbolsFiles to ResolvePackageAssets
This property contains the list of files related to debug symbols, and xml per asset.
1 parent b0b9714 commit 6c1a9d0

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

src/Tasks/Common/MetadataKeys.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,12 @@ internal static class MetadataKeys
131131
public const string IsVersion5 = "IsVersion5";
132132
public const string CreateCompositeImage = "CreateCompositeImage";
133133
public const string PerfmapFormatVersion = "PerfmapFormatVersion";
134+
135+
// Debug symbols
136+
public const string Related = "related";
137+
public const string Xml = ".xml";
138+
public const string XmlPath = "XmlPath";
139+
public const string Pdb = ".pdb";
140+
public const string PdbPath = "PdbPath";
134141
}
135142
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
 ////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Package Asset Cache File Format Details
3+
//
4+
// Encodings of Int32, Byte[], String as defined by System.IO.BinaryReader/Writer.
5+
//
6+
// There are 3 sections, written in the following order:
7+
//
8+
// 1. Header
9+
// ---------
10+
// Encodes format and enough information to quickly decide if cache is still valid.
11+
//
12+
// Header:
13+
// Int32 Signature: Spells PKGA ("package assets") when 4 little-endian bytes are interpreted as ASCII chars.
14+
// Int32 Version: Increased whenever format changes to prevent issues when building incrementally with a different SDK.
15+
// Byte[] SettingsHash: SHA-256 of settings that require the cache to be invalidated when changed.
16+
// Int32 MetadataStringTableOffset: Byte offset in file to start of the metadata string table.
17+
//
18+
// 2. ItemGroup[] ItemGroups
19+
// --------------
20+
// There is one ItemGroup for each ITaskItem[] output (Analyzers, CompileTimeAssemblies, etc.)
21+
// Count and order of item groups is constant and therefore not encoded in to the file.
22+
//
23+
// ItemGroup:
24+
// Int32 ItemCount
25+
// Item[] Items
26+
//
27+
// Item:
28+
// String ItemSpec (not index to string table because it generally unique)
29+
// Int32 MetadataCount
30+
// Metadata[] Metadata
31+
//
32+
// Metadata:
33+
// Int32 Key: Index in to MetadataStringTable for metadata key
34+
// Int32 Value: Index in to MetadataStringTable for metadata value
35+
//
36+
// 3. MetadataStringTable
37+
// ----------------------
38+
// Indexes keys and values of item metadata to compress the cache file
39+
//
40+
// MetadataStringTable:
41+
// Int32 MetadataStringCount
42+
// String[] MetadataStrings
43+
////////////////////////////////////////////////////////////////////////////////////////////////////

src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ public sealed class ResolvePackageAssets : TaskBase
231231
[Output]
232232
public ITaskItem[] PackageDependencies { get; private set; }
233233

234+
/// <summary>
235+
/// List of file symbols pdb and xml related to NuGet packages
236+
/// </summary>
237+
/// <remarks>
238+
/// This is the list of files to be copied to the output directory
239+
/// </remarks>
240+
[Output]
241+
public ITaskItem[] DebugSymbolsFiles { get; private set;}
242+
234243
/// <summary>
235244
/// Messages from the assets file.
236245
/// These are logged directly and therefore not returned to the targets (note private here).
@@ -311,6 +320,7 @@ private void ReadItemGroups()
311320
ApphostsForShimRuntimeIdentifiers = reader.ReadItemGroup();
312321
CompileTimeAssemblies = reader.ReadItemGroup();
313322
ContentFilesToPreprocess = reader.ReadItemGroup();
323+
DebugSymbolsFiles = reader.ReadItemGroup();
314324
FrameworkAssemblies = reader.ReadItemGroup();
315325
FrameworkReferences = reader.ReadItemGroup();
316326
NativeLibraries = reader.ReadItemGroup();
@@ -510,7 +520,7 @@ private static BinaryReader CreateReaderFromDisk(ResolvePackageAssets task, byte
510520
BinaryReader reader = null;
511521
try
512522
{
513-
if (File.GetLastWriteTimeUtc(task.ProjectAssetsCacheFile) > File.GetLastWriteTimeUtc(task.ProjectAssetsFile))
523+
if (IsCacheFileNewerThanAssetsFile())
514524
{
515525
reader = OpenCacheFile(task.ProjectAssetsCacheFile, settingsHash);
516526
}
@@ -537,6 +547,8 @@ private static BinaryReader CreateReaderFromDisk(ResolvePackageAssets task, byte
537547
}
538548

539549
return reader;
550+
551+
bool IsCacheFileNewerThanAssetsFile() => File.GetLastWriteTimeUtc(task.ProjectAssetsCacheFile) > File.GetLastWriteTimeUtc(task.ProjectAssetsFile);
540552
}
541553

542554
private static BinaryReader OpenCacheStream(Stream stream, byte[] settingsHash)
@@ -776,6 +788,7 @@ private void WriteItemGroups()
776788
WriteItemGroup(WriteApphostsForShimRuntimeIdentifiers);
777789
WriteItemGroup(WriteCompileTimeAssemblies);
778790
WriteItemGroup(WriteContentFilesToPreprocess);
791+
WriteItemGroup(WriteDebugSymbolsFiles);
779792
WriteItemGroup(WriteFrameworkAssemblies);
780793
WriteItemGroup(WriteFrameworkReferences);
781794
WriteItemGroup(WriteNativeLibraries);
@@ -1091,6 +1104,27 @@ private void WriteContentFilesToPreprocess()
10911104
});
10921105
}
10931106

1107+
private void WriteDebugSymbolsFiles()
1108+
{
1109+
WriteItems(
1110+
_runtimeTarget,
1111+
package => package.RuntimeAssemblies,
1112+
filter: asset => asset.Properties.ContainsKey(MetadataKeys.Related),
1113+
writeMetadata: (package, asset) =>
1114+
{
1115+
asset.Properties.TryGetValue(MetadataKeys.Related, out string propertyValue);
1116+
if (string.Compare(propertyValue, MetadataKeys.Pdb, true) == 0)
1117+
{
1118+
WriteMetadata(MetadataKeys.PdbPath, Path.ChangeExtension(asset.Path, ".pdb"));
1119+
}
1120+
1121+
if (string.Compare(propertyValue, MetadataKeys.Xml, true) == 0)
1122+
{
1123+
WriteMetadata(MetadataKeys.XmlPath, Path.ChangeExtension(asset.Path, ".xml"));
1124+
}
1125+
});
1126+
}
1127+
10941128
private void WriteFrameworkAssemblies()
10951129
{
10961130
if (_task.DisableFrameworkAssemblies)

0 commit comments

Comments
 (0)