Skip to content

Commit b8c9610

Browse files
committed
Add new output DebugSymbolsFiles to ResolvePackageAssets
DebugSymbolsFiles outputs the list of absolute path to symbols files for package references. ReferenceDocumentationFiles outputs the list of absolute path to Xml documentation files. The change: ResolvePackagesAssets was modified to read/write DebugSymbolsFiles and ReferenceDocumentationFiles from/to the cache file. They were inserted after ContentFilesToProcess to keep the alphabetical order. The target was modified to copy the DebugSymbolsFiles to output directory only when CopyDebugSymbolFilesFromPackages is true, and ReferenceDocumentationFiles to the output directory when EnableCopySymbolsAndXmlDocsToOutputDir is true. There is some minor code cleanup not related to this bug.
1 parent 0a2a2e8 commit b8c9610

File tree

3 files changed

+103
-3
lines changed

3 files changed

+103
-3
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 RelatedProperty = "related";
137+
public const string XmlExtension = ".xml";
138+
public const string XmlFilePath = "XmlFilePath";
139+
public const string PdbExtension = ".pdb";
140+
public const string PdbFilePath = "PdbFilePath";
134141
}
135142
}

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

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Microsoft.Build.Framework;
1313
using Microsoft.Build.Utilities;
1414
using NuGet.Common;
15-
using NuGet.Frameworks;
1615
using NuGet.ProjectModel;
1716
using NuGet.Versioning;
1817

@@ -156,6 +155,9 @@ public sealed class ResolvePackageAssets : TaskBase
156155
[Required]
157156
public string DotNetAppHostExecutableNameWithoutExtension { get; set; }
158157

158+
/// <summary>
159+
/// True indicates we are doing a design-time build. Otherwise we are in a build.
160+
/// </summary>
159161
public bool DesignTimeBuild { get; set; }
160162

161163
/// <summary>
@@ -231,6 +233,24 @@ public sealed class ResolvePackageAssets : TaskBase
231233
[Output]
232234
public ITaskItem[] PackageDependencies { get; private set; }
233235

236+
/// <summary>
237+
/// List of symbol files (.pdb) related to NuGet packages.
238+
/// </summary>
239+
/// <remarks>
240+
/// Pdb files to be copied to the output directory
241+
/// </remarks>
242+
[Output]
243+
public ITaskItem[] DebugSymbolsFiles { get; private set;}
244+
245+
/// <summary>
246+
/// List of xml files related to NuGet packages.
247+
/// </summary>
248+
/// <remarks>
249+
/// The XML files should only be included in the publish output if PublishReferencesDocumentationFiles is true
250+
/// </remarks>
251+
[Output]
252+
public ITaskItem[] ReferenceDocumentationFiles { get; private set; }
253+
234254
/// <summary>
235255
/// Messages from the assets file.
236256
/// These are logged directly and therefore not returned to the targets (note private here).
@@ -311,11 +331,13 @@ private void ReadItemGroups()
311331
ApphostsForShimRuntimeIdentifiers = reader.ReadItemGroup();
312332
CompileTimeAssemblies = reader.ReadItemGroup();
313333
ContentFilesToPreprocess = reader.ReadItemGroup();
334+
DebugSymbolsFiles = reader.ReadItemGroup();
314335
FrameworkAssemblies = reader.ReadItemGroup();
315336
FrameworkReferences = reader.ReadItemGroup();
316337
NativeLibraries = reader.ReadItemGroup();
317338
PackageDependencies = reader.ReadItemGroup();
318339
PackageFolders = reader.ReadItemGroup();
340+
ReferenceDocumentationFiles = reader.ReadItemGroup();
319341
ResourceAssemblies = reader.ReadItemGroup();
320342
RuntimeAssemblies = reader.ReadItemGroup();
321343
RuntimeTargets = reader.ReadItemGroup();
@@ -510,7 +532,7 @@ private static BinaryReader CreateReaderFromDisk(ResolvePackageAssets task, byte
510532
BinaryReader reader = null;
511533
try
512534
{
513-
if (File.GetLastWriteTimeUtc(task.ProjectAssetsCacheFile) > File.GetLastWriteTimeUtc(task.ProjectAssetsFile))
535+
if (IsCacheFileUpToDate())
514536
{
515537
reader = OpenCacheFile(task.ProjectAssetsCacheFile, settingsHash);
516538
}
@@ -537,6 +559,8 @@ private static BinaryReader CreateReaderFromDisk(ResolvePackageAssets task, byte
537559
}
538560

539561
return reader;
562+
563+
bool IsCacheFileUpToDate() => File.GetLastWriteTimeUtc(task.ProjectAssetsCacheFile) > File.GetLastWriteTimeUtc(task.ProjectAssetsFile);
540564
}
541565

542566
private static BinaryReader OpenCacheStream(Stream stream, byte[] settingsHash)
@@ -651,6 +675,8 @@ internal sealed class CacheWriter : IDisposable
651675

652676
private const string NetCorePlatformLibrary = "Microsoft.NETCore.App";
653677

678+
private const char RelatedPropertySeparator = ';';
679+
654680
public CacheWriter(ResolvePackageAssets task)
655681
{
656682
_targetFramework = task.TargetFramework;
@@ -776,11 +802,13 @@ private void WriteItemGroups()
776802
WriteItemGroup(WriteApphostsForShimRuntimeIdentifiers);
777803
WriteItemGroup(WriteCompileTimeAssemblies);
778804
WriteItemGroup(WriteContentFilesToPreprocess);
805+
WriteItemGroup(WriteDebugSymbolsFiles);
779806
WriteItemGroup(WriteFrameworkAssemblies);
780807
WriteItemGroup(WriteFrameworkReferences);
781808
WriteItemGroup(WriteNativeLibraries);
782809
WriteItemGroup(WritePackageDependencies);
783-
WriteItemGroup(WritePackageFolders);
810+
WriteItemGroup(WritePackageFolders);
811+
WriteItemGroup(WriteReferenceDocumentationFiles);
784812
WriteItemGroup(WriteResourceAssemblies);
785813
WriteItemGroup(WriteRuntimeAssemblies);
786814
WriteItemGroup(WriteRuntimeTargets);
@@ -1091,6 +1119,61 @@ private void WriteContentFilesToPreprocess()
10911119
});
10921120
}
10931121

1122+
private void WriteDebugSymbolsFiles()
1123+
{
1124+
WriteDebugItems(
1125+
p => p.RuntimeAssemblies,
1126+
MetadataKeys.PdbExtension);
1127+
}
1128+
1129+
private void WriteReferenceDocumentationFiles()
1130+
{
1131+
WriteDebugItems(
1132+
p => p.CompileTimeAssemblies,
1133+
MetadataKeys.XmlExtension);
1134+
}
1135+
1136+
private void WriteDebugItems(
1137+
Func<LockFileTargetLibrary, IEnumerable<LockFileItem>> getAssets,
1138+
string extension)
1139+
{
1140+
foreach (var library in _runtimeTarget.Libraries)
1141+
{
1142+
if (!library.IsPackage())
1143+
{
1144+
continue;
1145+
}
1146+
1147+
foreach (LockFileItem asset in getAssets(library))
1148+
{
1149+
if (asset.IsPlaceholderFile() || !asset.Properties.ContainsKey(MetadataKeys.RelatedProperty))
1150+
{
1151+
continue;
1152+
}
1153+
1154+
string itemSpec = _packageResolver.ResolvePackageAssetPath(library, asset.Path);
1155+
1156+
string relatedExtensions = asset.Properties[MetadataKeys.RelatedProperty];
1157+
1158+
foreach (string fileExtension in relatedExtensions.Split(RelatedPropertySeparator))
1159+
{
1160+
if (fileExtension.ToLower() == extension)
1161+
{
1162+
string xmlFilePath = Path.ChangeExtension(itemSpec, fileExtension);
1163+
if (File.Exists(xmlFilePath))
1164+
{
1165+
WriteItem(xmlFilePath, library);
1166+
}
1167+
else
1168+
{
1169+
_task.Log.LogWarning(Strings.AssetsFileNotFound, xmlFilePath);
1170+
}
1171+
}
1172+
}
1173+
}
1174+
}
1175+
}
1176+
10941177
private void WriteFrameworkAssemblies()
10951178
{
10961179
if (_task.DisableFrameworkAssemblies)

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ Copyright (c) .NET Foundation. All rights reserved.
297297
<Output TaskParameter="Analyzers" ItemName="ResolvedAnalyzers" />
298298
<Output TaskParameter="ApphostsForShimRuntimeIdentifiers" ItemName="_ApphostsForShimRuntimeIdentifiersResolvePackageAssets" />
299299
<Output TaskParameter="ContentFilesToPreprocess" ItemName="_ContentFilesToPreprocess" />
300+
<Output TaskParameter="DebugSymbolsFiles" ItemName="_DebugSymbolsFiles" />
301+
<Output TaskParameter="ReferenceDocumentationFiles" ItemName="_ReferenceDocumentationFiles" />
300302
<Output TaskParameter="FrameworkAssemblies" ItemName="ResolvedFrameworkAssemblies" />
301303
<Output TaskParameter="FrameworkReferences" ItemName="TransitiveFrameworkReference" />
302304
<Output TaskParameter="NativeLibraries" ItemName="NativeCopyLocalItems" />
@@ -309,6 +311,14 @@ Copyright (c) .NET Foundation. All rights reserved.
309311
<Output TaskParameter="PackageDependencies" ItemName="PackageDependencies" />
310312
</ResolvePackageAssets>
311313

314+
<ItemGroup Condition="'$(CopyDebugSymbolFilesFromPackages)' == 'true'">
315+
<ReferenceCopyLocalPaths Include="@(_DebugSymbolsFiles)"></ReferenceCopyLocalPaths>
316+
</ItemGroup>
317+
318+
<ItemGroup Condition="'$(CopyDocumentationFilesFromPackages)' == 'true'">
319+
<ReferenceCopyLocalPaths Include="@(_ReferenceDocumentationFiles)"></ReferenceCopyLocalPaths>
320+
</ItemGroup>
321+
312322
<ItemGroup Condition="'$(UseAppHostFromAssetsFile)' == 'true'">
313323
<_NativeRestoredAppHostNETCore Include="@(NativeCopyLocalItems)"
314324
Condition="'%(NativeCopyLocalItems.FileName)%(NativeCopyLocalItems.Extension)' == '$(_DotNetAppHostExecutableName)'"/>

0 commit comments

Comments
 (0)