Packaging does not handle a refonly build correctly
See original GitHub issueUse case: I am trying to generate a reference-assembly-only package for some of our runtime packages. This to allow giving a prospective customer code that compiles, but cannot run.
I’m trying to trigger this using ProduceOnlyReferenceAssembly=true
.
When this is set, I
- avoid setting
GenerateDocumentationFile
totrue
(it would leak information about internals) - avoid setting
ProduceReferenceAssembly
totrue
(refout
conflicts withrefonly
) - add a
.ReferenceAssemblies
suffix toPackageId
- set
BuildOutputTargetFolder
toref
(because the docs say reference assemblies should go there instead of lib) - set
IncludeSymbols
tofalse
The build works fine with that, producing just the reference assembly in the output folder.
However, the pack task complains:
error NU5026: The file '$(OutputPath)\$(Configuration)\$(TargetFramework)\$(TargetName).pdb' to be packed was not found on disk.
I am not asking for a symbols package, not have I otherwise asked for PDB files to be built or packed; the compiler does not seem to produce one at all when refonly
is used.
Using the binlog file, I see that the Pack
task seems to get the .pdb file names from a _TargetPathsToSymbols
item group.
Note that while the error refers to the file under OutputPath
, the TargetPathsToSymbols
being passed actually has them under IntermediateOutputPath
(and OutputPath
is not being passed).
I suppose there are two separate issues, that combine to form this error:
- the
_TargetPathsToSymbols
item group is populated with PDB files that are not actually produced by the build- this in turn is because
_WalkEachTargetPerFramework
calls_GetDebugSymbolsWithTfm
for each target framework whenIncludeBuildOutput
istrue
- in and of itself, that seems fine
- it in turn depends on a
DebugSymbolsProjectOutputGroupOutput
item group, set byDebugSymbolsProjectOutputGroup
- this in turn is because
- the
Pack
task requires the file names passed to itsTargetPathsToSymbols
parameter to exist even withIncludeSymbols
set tofalse
I can work around the error using
<Target Name="ThereAreNoPDBFilesAfterARefOnlyBuild"
AfterTargets="DebugSymbolsProjectOutputGroup"
Condition=" '$(ProduceOnlyReferenceAssembly)' == 'true' ">
<ItemGroup>
<DebugSymbolsProjectOutputGroupOutput Remove="$(IntermediateOutputPath)$(TargetName).pdb" />
</ItemGroup>
</Target>
but that is hardly a clean solution, and it then complains about missing reference assemblies:
C:\Program Files\dotnet\sdk\5.0.300\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(221,5): warning NU5131: References were found in the nuspec, but some reference assemblies were not found in both the nuspec and ref folder. Add the following reference assemblies:
C:\Program Files\dotnet\sdk\5.0.300\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(221,5): warning NU5131: - Add $(TargetFileName) to the net472 reference group in the nuspec
C:\Program Files\dotnet\sdk\5.0.300\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(221,5): warning NU5131: - Add $(TargetFileName) to the netcoreapp3.1 reference group in the nuspec
C:\Program Files\dotnet\sdk\5.0.300\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(221,5): warning NU5131:
The generated .nuspec has
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
...
<dependencies>
<group targetFramework=".NETFramework4.7.2" />
<group targetFramework=".NETCoreApp3.1" />
</dependencies>
</metadata>
<files>
<file src="$(OutputPath)\Debug\net472\$(TargetFileName)" target="ref\net472\$(TargetFileName)" />
<file src="$(OutputPath)\Debug\netcoreapp3.1\$(TargetFileName)" target="ref\netcoreapp3.1\$(TargetFileName)" />
</files>
</package>
Looking at the NU5131 docs, it seems mostly concerned with packages containing both ref and lib assemblies. The suggestion seems to be that something like
<references>
<group targetFramework="net472">
<reference file="$(TargetFileName)" />
</group>
<group targetFramework="netcoreapp3.1">
<reference file="$(TargetFileName)" />
</group>
</references>
is needed, but I can’t immediately find any documentation on how to have the NuGet targets generate that.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
It’s possible that dotnet/msbuild#6510 will resolve things enough, and I do have a workaround for now.
And the remaining element (NU5131) is more a NuGet issue than an SDK one (but I don’t suppose issues can be transferred from the dotnet org to the NuGet one?) - and even that’s avoidable via
NoWarn
(as much as I dislike having to do that).I’ll leave it open for a bit, but I would say it’s not currently all that urgent.
@Zastai it looks like you found a workaround, is there still an outstanding issue here?