NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

NuGet fails to pack ref-only assemblies #9473

Open dotMorten opened 4 years ago

dotMorten commented 4 years ago

Details about Problem

NuGet product used: VS UI, dotnet.exe

dotnet.exe --version (if appropriate): 3.1.201

VS version (if appropriate): 16.5.4

Detailed repro steps so we can see the same problem

  1. Create a new .NET Standard 2.0 class library project.

  2. Set ProduceOnlyReferenceAssembly to True

  3. Pack the project (VS IDE or dotnet pack).

  4. Observe the error: 1>------ Build started: Project: PackageFailureRepro, Configuration: Debug Any CPU ------ 1>C:\Program Files\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error NU5026: The file 'C:\Users\mn\source\repos\PackageFailureRepro\PackageFailureRepro\bin\Debug\netstandard2.0\PackageFailureRepro.pdb' to be packed was not found on disk. 1>Done building project "PackageFailureRepro.csproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Ref assemblies doesn't generate PDBs, but even weirder is I'm not even trying to pack PDBs in the package.

Full project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <ProduceOnlyReferenceAssembly>True</ProduceOnlyReferenceAssembly>
  </PropertyGroup>

</Project>

Sample Project

PackageFailureRepro.zip

Workaround

  <Target Name="CreateFakePDB" AfterTargets="Build" Condition="'$(ProduceOnlyReferenceAssembly)'=='True'">
    <WriteLinesToFile File="$(OutputPath)$(AssemblyName).pdb" Lines="" Overwrite="false" Encoding="Unicode" />
  </Target>
alexvaut commented 4 years ago

I get exactly the same issue with a target that looks like this (no ProduceOnlyReferenceAssembly), I do this workaround because of another issue with symbols and nuget (https://github.com/dotnet/sdk/issues/1458):

    <PropertyGroup>
        <IncludeSymbols>false</IncludeSymbols>  
        <EmbedAllSources>true</EmbedAllSources>
        <EmbedUntrackedSources>true</EmbedUntrackedSources>
        <DebugType>embedded</DebugType> 
    </PropertyGroup>

@dotMorten thanks for the workaround !