Skip to content

No public mechanism to place symbols outside of lib/ref for Pack #10860

Open

Description

@ericstj

Details about Problem

In dotnet/runtime we're moving a lot of our packages from using our custom pkgproj system to using the built-in CSProj + PackTask (hooray!). One of the challenges we faced was that it's difficult to place symbols outside the lib/ref folder.

This is necessary for supported scenarios of packaging runtime assets (runtimes/<rid>/lib/<tfm>) and analyzers (analyzers/dotnet/<language>) and build tasks (build/<tfm>).

I've seen others (including NuGet itself) use TfmSpecificPackageFile to provide symbols, however this doesn't result in the file being treated as a symbol file (and thus removed from the primary package). The only way to specify symbols which are treated correctly is to set _TargetPathsToSymbols which is private (by _ convention). Setting the DebugSymbolsProjectOutputGroupOutput doesn't work well as this only works for the inner build of the packed project, which might not always be the case. Take a library which wants to include a build task or analyzer from another project, a library which wants to include native assets (including PDBs), etc. The only way for this scenario to work is to directly set _TargetPathsToSymbols.

We expected to be able to set the PackagePath for _TargetPathsToSymbols items, similar to Content items, and have that be honored by NuGet. That was not the case. We did find that through a coincidence we can set TargetPath to a rooted path we can still achieve what we want.
https://github.com/NuGet/NuGet.Client/blob/f24bad0668193ce21a1db8cabd1ce95ba509c7f0/src/NuGet.Core/NuGet.Commands/MSBuildProjectFactory.cs#L146

var packageFile = new ManifestFile()
{
    Source = file.FinalOutputPath,
    Target = IsTool ? Path.Combine(targetFolders[i], targetPath) : Path.Combine(targetFolders[i], tfm, targetPath)
};

The usage of Path.Combine here let's us specify a rooted TargetPath value. Kudos to @Anipik for discovering this workaround.

So my our here is to have a public item type that allows for the addition of files that will be treated as symbols, allow for that item to be specified in an outer build, and make it handle PackagePath metadata.

Though not specifically required by us, it might also make sense to define a way (like TfmSpecificPackageFile) for an inner build to provide symbols that have an arbitrary path. Such a feature could be useful for projects whose primary output is build task, analyzer, etc.

Activity

  1. changed the title [-]No public mechanism to place outside of lib/ref for Pack[/-] [+]No public mechanism to place symbols outside of lib/ref for Pack[/+] on May 19, 2021
  2. added
    Priority:2
    on May 19, 2021
  3. ericstj commented on Jun 3, 2021

    @ericstj
    Author

    NuGet/NuGet.Client#4053 provides a good start here, defining a public way to provide TFM-specific symbols from the inner build via TfmSpecificDebugSymbolsFile.

    The pieces we still need to fully address this scenario are as follows:

    • Provide a mechanism to specify symbols from outer build (like Content/None/etc, but having symbols behavior where they only appear in symbols packages). Today this requires using private item _TargetPathsToSymbols. Recommended item name: SymbolsPackageFile.
    • Support PackagePath metadata on both the item created above and TfmSpecificDebugSymbolsFile. Ideally we should also support PackagePath on other BuildOutputInPackage items too (like TfmSpecificPackageFile) if it can be done in the same way.
  4. nkolev92 commented on Jun 3, 2021

    @nkolev92
    Member

    #10913 tracks the parts implemented by NuGet/NuGet.Client#4053

  5. ericstj commented on Oct 21, 2022

    @ericstj
    Author

    Another place this came up:
    https://github.com/dotnet/machinelearning/blob/1903fa5eda154f0227d9490d961a828d8fd493b5/src/Microsoft.ML/Microsoft.ML.csproj#L5-L9

    Essentially there is no way for a package to provide symbols unless it also specifies IncludeBuildOutput=true.

    This is because the only item which nuget treats as symbols is _TargetPathsToSymbols
    https://github.com/NuGet/NuGet.Client/blob/735db82e81e36497bacabbb558e0f706b9c13d0e/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L239

    And that is only populated when '$(IncludeBuildOutput)' == 'true'
    https://github.com/NuGet/NuGet.Client/blob/735db82e81e36497bacabbb558e0f706b9c13d0e/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L374

    For consistency with the TargetsForTfmSpecificContentInPackage extension point which is included regardless of IncludeBuildOutput I think TargetsForTfmSpecificDebugSymbolsInPackage should also be included when IncludeBuildOutput is set to false. I believe we can simply remove the condition above, since there is a condition on the item around including DebugSymbolsProjectOutputGroupOutput.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions