New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`dotnet pack` fails on .NET Core project when `paket.references` contains only File: references #2623

Closed
magne opened this Issue Aug 17, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@magne
Contributor

magne commented Aug 17, 2017

Description

When building a .NET Core project with a paket.references only containing File: references, running dotnet pack will fail rather than producing a NuGet package.

The reason the build will fail is that no intermediate paket reference file is produced (would be src\TestProj\obj\TestProj.csproj.references in this case). This in turn causes .paket\Paket.Restore.targets to fail on line 87.

Repro steps

Given the following .Net Core .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net461</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <Compile Include="..\..\paket-files\MiniProfiler\dotnet\StackExchange.Profiling\Data\ExecuteType.cs">
            <Paket>True</Paket>
            <Link>paket-files/ExecuteType.cs</Link>
        </Compile>
        <Compile Include="..\..\paket-files\MiniProfiler\dotnet\StackExchange.Profiling\Data\IDbProfiler.cs">
            <Paket>True</Paket>
            <Link>IDbProfiler.cs</Link>
        </Compile>
    </ItemGroup>
    <Import Project="..\.paket\Paket.Restore.targets"/>
</Project>

paket.dependencies:

source https://api.nuget.org/v3/index.json

github MiniProfiler/dotnet:v3 StackExchange.Profiling/Data/ExecuteType.cs
github MiniProfiler/dotnet:v3 StackExchange.Profiling/Data/IDbProfiler.cs

and paket.references:

File:ExecuteType.cs
File:IDbProfiler.cs

When running

dotnet pack

the build will produce an error.

...> dotnet --info
.NET Command Line Tools (2.0.0)

Product Information:
 Version:            2.0.0
 Commit SHA-1 hash:  cdcd1928c9

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

...> .paket\paket.exe --version
Paket version 5.85.3

Expected behavior

The build should produce a NuGet package.

Actual behavior

The build fails with the following error:

...> dotnet pack
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  TestProj -> xxx\src\TestProj\bin\Debug\net461\TestProj.dll
  Paket version 5.85.3
  Performance:
   - Runtime: 665 milliseconds
  Paket failed with
  -> Specified references-file 'xxx\src\TestProj/obj/TestProj.csproj.references' does not exist.
xxx\.paket\Paket.Restore.targets(87,5): error MSB3073: The command ""xxx\.paket\paket.exe" fix-nuspecs files "obj\TestProj.1.0.0.nuspec" references-file "xxx\src\TestProj/obj/TestProj.csproj.references" " exited with code 1. [xxx\src\TestProj\TestProj.csproj]

If the .csproj file specifies the property <IsPackable>false</IsPackable> the error is

...> dotnet pack
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

xxx\.paket\Paket.Restore.targets(94,5): error MSB4044: The "PackTask" task was not given a value for the required parameter "PackItem". [xxx\src\TestProj\TestProj.csproj]

but this would be fixed by #2621.

Known workarounds

Adding the following target to either .paket\Paket.Restore.targets or your .csproj file will make the build produce a NuGet package:

    <Target Name="CreatePaketReferencesFile" AfterTargets="GenerateNuspec" BeforeTargets="PaketOverrideNuspec" Condition="'$(IsPackable)' == '' Or '$(IsPackable)' == 'true'" >
        <PropertyGroup>
            <PaketReferencesFilePath>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references</PaketReferencesFilePath>
        </PropertyGroup>
        <Touch Files="$(PaketReferencesFilePath)" AlwaysCreate="true" />
    </Target>

Another solution might be to add the following condition to the PaketDisableDirectPack and PaketOverrideNuspec targets in .paket\Paket.Restore.targets:

<Target Name="..." Condition="($(IsPackable) == '' Or $(IsPackable) == 'true') And Exists('$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references')">
   ...
</Target>

This has the added benefit that paket is not invoked, increasing performance.

I have no idea which of these workarounds is best.

@forki

This comment has been minimized.

Show comment
Hide comment
@forki

forki Aug 17, 2017

Member

Second sounds good. Can you please send a pull request?

Member

forki commented Aug 17, 2017

Second sounds good. Can you please send a pull request?

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