Repository navigation
Description
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
[-]No public mechanism to place outside of lib/ref for Pack[/-][+]No public mechanism to place symbols outside of lib/ref for Pack[/+]ericstj commentedon Jun 3, 2021
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:
_TargetPathsToSymbols. Recommended item name:SymbolsPackageFile.PackagePathmetadata on both the item created above andTfmSpecificDebugSymbolsFile. Ideally we should also supportPackagePathon otherBuildOutputInPackageitems too (likeTfmSpecificPackageFile) if it can be done in the same way.nkolev92 commentedon Jun 3, 2021
#10913 tracks the parts implemented by NuGet/NuGet.Client#4053
ericstj commentedon Oct 21, 2022
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
_TargetPathsToSymbolshttps://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
TargetsForTfmSpecificContentInPackageextension point which is included regardless ofIncludeBuildOutputI thinkTargetsForTfmSpecificDebugSymbolsInPackageshould also be included whenIncludeBuildOutputis set to false. I believe we can simply remove the condition above, since there is a condition on the item around includingDebugSymbolsProjectOutputGroupOutput.Generate Apple native symbol packages during pack (#4846)