question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Packaging does not handle a refonly build correctly

See original GitHub issue

Use 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 to true (it would leak information about internals)
  • avoid setting ProduceReferenceAssembly to true (refout conflicts with refonly)
  • add a .ReferenceAssemblies suffix to PackageId
  • set BuildOutputTargetFolder to ref (because the docs say reference assemblies should go there instead of lib)
  • set IncludeSymbols to false

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 when IncludeBuildOutput is true
      • in and of itself, that seems fine
      • it in turn depends on a DebugSymbolsProjectOutputGroupOutput item group, set by DebugSymbolsProjectOutputGroup
  • the Pack task requires the file names passed to its TargetPathsToSymbols parameter to exist even with IncludeSymbols set to false

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:open
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Zastaicommented, Jun 2, 2021

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.

0reactions
sfoslundcommented, Jun 2, 2021

@Zastai it looks like you found a workaround, is there still an outstanding issue here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ProduceOnlyReferenceAssembly=true fails with Do not use ...
The following project fails to compile: net5.0 true The above p... ... CSC : error CS8308: Do not use refout when using refonly....
Read more >
Rider can't compile solution with mixed .net core and . ...
Visual Studio seem to handle this sort of situation correctly. The workaround is to make the classic .NET part a separate solution. Steps...
Read more >
Reference assemblies
Reference assemblies can't be loaded for execution, but they can be passed as compiler input in the same way as implementation assemblies.
Read more >
Deep-dive into .NET Core primitives, part 2: the shared ...
I repeat, the NuGet package does not provide the shared framework. (I'll repeat once more below.) The NuGet package only provides a set...
Read more >
Using Unity with Sublime Text 2 (How to get everything set ...
I've installed completesharp from package control. ... I'd love to use sublime, but without actual completions I can't. It says it can't ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found