Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output DebugSymbolsFiles to ResolvePackageAssets #27580

Merged
merged 2 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Tasks/Common/MetadataKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,12 @@ internal static class MetadataKeys
public const string IsVersion5 = "IsVersion5";
public const string CreateCompositeImage = "CreateCompositeImage";
public const string PerfmapFormatVersion = "PerfmapFormatVersion";

// Debug symbols
public const string RelatedProperty = "related";
public const string XmlExtension = ".xml";
public const string XmlFilePath = "XmlFilePath";
public const string PdbExtension = ".pdb";
public const string PdbFilePath = "PdbFilePath";
}
}
89 changes: 86 additions & 3 deletions src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Common;
using NuGet.Frameworks;
using NuGet.ProjectModel;
using NuGet.Versioning;

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

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

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

/// <summary>
/// List of symbol files (.pdb) related to NuGet packages.
/// </summary>
/// <remarks>
/// Pdb files to be copied to the output directory
/// </remarks>
[Output]
public ITaskItem[] DebugSymbolsFiles { get; private set;}

/// <summary>
/// List of xml files related to NuGet packages.
/// </summary>
/// <remarks>
/// The XML files should only be included in the publish output if PublishReferencesDocumentationFiles is true
/// </remarks>
[Output]
public ITaskItem[] ReferenceDocumentationFiles { get; private set; }

/// <summary>
/// Messages from the assets file.
/// These are logged directly and therefore not returned to the targets (note private here).
Expand Down Expand Up @@ -311,11 +331,13 @@ private void ReadItemGroups()
ApphostsForShimRuntimeIdentifiers = reader.ReadItemGroup();
CompileTimeAssemblies = reader.ReadItemGroup();
ContentFilesToPreprocess = reader.ReadItemGroup();
DebugSymbolsFiles = reader.ReadItemGroup();
FrameworkAssemblies = reader.ReadItemGroup();
FrameworkReferences = reader.ReadItemGroup();
NativeLibraries = reader.ReadItemGroup();
PackageDependencies = reader.ReadItemGroup();
PackageFolders = reader.ReadItemGroup();
ReferenceDocumentationFiles = reader.ReadItemGroup();
ResourceAssemblies = reader.ReadItemGroup();
RuntimeAssemblies = reader.ReadItemGroup();
RuntimeTargets = reader.ReadItemGroup();
Expand Down Expand Up @@ -510,7 +532,7 @@ private static BinaryReader CreateReaderFromDisk(ResolvePackageAssets task, byte
BinaryReader reader = null;
try
{
if (File.GetLastWriteTimeUtc(task.ProjectAssetsCacheFile) > File.GetLastWriteTimeUtc(task.ProjectAssetsFile))
if (IsCacheFileUpToDate())
{
reader = OpenCacheFile(task.ProjectAssetsCacheFile, settingsHash);
}
Expand All @@ -537,6 +559,8 @@ private static BinaryReader CreateReaderFromDisk(ResolvePackageAssets task, byte
}

return reader;

bool IsCacheFileUpToDate() => File.GetLastWriteTimeUtc(task.ProjectAssetsCacheFile) > File.GetLastWriteTimeUtc(task.ProjectAssetsFile);
}

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

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

private const char RelatedPropertySeparator = ';';

public CacheWriter(ResolvePackageAssets task)
{
_targetFramework = task.TargetFramework;
Expand Down Expand Up @@ -776,11 +802,13 @@ private void WriteItemGroups()
WriteItemGroup(WriteApphostsForShimRuntimeIdentifiers);
WriteItemGroup(WriteCompileTimeAssemblies);
WriteItemGroup(WriteContentFilesToPreprocess);
WriteItemGroup(WriteDebugSymbolsFiles);
WriteItemGroup(WriteFrameworkAssemblies);
WriteItemGroup(WriteFrameworkReferences);
WriteItemGroup(WriteNativeLibraries);
WriteItemGroup(WritePackageDependencies);
WriteItemGroup(WritePackageFolders);
WriteItemGroup(WritePackageFolders);
WriteItemGroup(WriteReferenceDocumentationFiles);
WriteItemGroup(WriteResourceAssemblies);
WriteItemGroup(WriteRuntimeAssemblies);
WriteItemGroup(WriteRuntimeTargets);
Expand Down Expand Up @@ -1091,6 +1119,61 @@ private void WriteContentFilesToPreprocess()
});
}

private void WriteDebugSymbolsFiles()
{
WriteDebugItems(
p => p.RuntimeAssemblies,
MetadataKeys.PdbExtension);
}

private void WriteReferenceDocumentationFiles()
{
WriteDebugItems(
p => p.CompileTimeAssemblies,
MetadataKeys.XmlExtension);
}

private void WriteDebugItems(
Func<LockFileTargetLibrary, IEnumerable<LockFileItem>> getAssets,
string extension)
{
foreach (var library in _runtimeTarget.Libraries)
{
if (!library.IsPackage())
{
continue;
}

foreach (LockFileItem asset in getAssets(library))
{
if (asset.IsPlaceholderFile() || !asset.Properties.ContainsKey(MetadataKeys.RelatedProperty))
{
continue;
}

string itemSpec = _packageResolver.ResolvePackageAssetPath(library, asset.Path);

string relatedExtensions = asset.Properties[MetadataKeys.RelatedProperty];

foreach (string fileExtension in relatedExtensions.Split(RelatedPropertySeparator))
{
if (fileExtension.ToLower() == extension)
ocallesp marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use invariant comparison

Suggested change
if (fileExtension.ToLower() == extension)
if (fileExtension.ToLowerInvariant() == extension)

{
string xmlFilePath = Path.ChangeExtension(itemSpec, fileExtension);
if (File.Exists(xmlFilePath))
{
WriteItem(xmlFilePath, library);
}
else
{
_task.Log.LogWarning(Strings.AssetsFileNotFound, xmlFilePath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really the right error message here. Do we need to log a warning at all here?

}
}
}
}
}
}

private void WriteFrameworkAssemblies()
{
if (_task.DisableFrameworkAssemblies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="Analyzers" ItemName="ResolvedAnalyzers" />
<Output TaskParameter="ApphostsForShimRuntimeIdentifiers" ItemName="_ApphostsForShimRuntimeIdentifiersResolvePackageAssets" />
<Output TaskParameter="ContentFilesToPreprocess" ItemName="_ContentFilesToPreprocess" />
<Output TaskParameter="DebugSymbolsFiles" ItemName="_DebugSymbolsFiles" />
<Output TaskParameter="ReferenceDocumentationFiles" ItemName="_ReferenceDocumentationFiles" />
<Output TaskParameter="FrameworkAssemblies" ItemName="ResolvedFrameworkAssemblies" />
<Output TaskParameter="FrameworkReferences" ItemName="TransitiveFrameworkReference" />
<Output TaskParameter="NativeLibraries" ItemName="NativeCopyLocalItems" />
Expand All @@ -309,6 +311,14 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="PackageDependencies" ItemName="PackageDependencies" />
</ResolvePackageAssets>

<ItemGroup Condition="'$(CopyDebugSymbolFilesFromPackages)' == 'true'">
<ReferenceCopyLocalPaths Include="@(_DebugSymbolsFiles)"></ReferenceCopyLocalPaths>
</ItemGroup>

<ItemGroup Condition="'$(CopyDocumentationFilesFromPackages)' == 'true'">
ocallesp marked this conversation as resolved.
Show resolved Hide resolved
<ReferenceCopyLocalPaths Include="@(_ReferenceDocumentationFiles)"></ReferenceCopyLocalPaths>
</ItemGroup>

<ItemGroup Condition="'$(UseAppHostFromAssetsFile)' == 'true'">
<_NativeRestoredAppHostNETCore Include="@(NativeCopyLocalItems)"
Condition="'%(NativeCopyLocalItems.FileName)%(NativeCopyLocalItems.Extension)' == '$(_DotNetAppHostExecutableName)'"/>
Expand Down
Loading