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.

`dotnet restore` does not work on Linux when installed as global tool

See original GitHub issue

Description

Paket version: 5.219.6 Last Paket version without this issue: 5.219.5

dotnet restore fails on Linux with the following message when paket is installed using dotnet tool install -g paket

The issue seems to be the following line in Paket.Restore.targets:

<PaketCommand Condition=" '$(PaketCommand)' == '' AND '$(_PaketExeExtension)' == '' ">dotnet "$(PaketExePath)"</PaketCommand>

Repro steps

Please provide the steps required to reproduce the problem

  1. Install paket: dotnet tool install -g paket
  2. Run paket install.
  3. Run dotnet restore.

GitHub Repository with Travis CI setup: https://github.com/bash/paket-issue-3671

Expected behavior

No error.

Actual behavior

No executable found matching command "dotnet-paket"
/home/travis/build/bash/paket-bug/.paket/Paket.Restore.targets(139,5): error MSB3073: The command "dotnet "paket" restore" exited with code 1. [/home/travis/build/bash/paket-issue-3671/PaketBug/PaketBug.csproj]
The command "dotnet restore" exited with 1.

Known workarounds

Installing an older version of paket:

dotnet tool install -g paket --version 5.219.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:37 (36 by maintainers)

github_iconTop GitHub Comments

2reactions
NatElkinscommented, Sep 28, 2019

@atlemann Okay you’re right I prematurely declared victory before. I think I’ve actually got it this time, although it’s kind of horrible (but let’s be honest, anything having to do with MSBuild is horrible).

Add this target at the top:

  <Target Name="SetPaketCommand" >
    <!-- Call 'dotnet paket' and see if it returns without an error. Mute all the output. -->
    <Exec Command="dotnet paket --version" IgnoreExitCode="true" StandardOutputImportance="low" StandardErrorImportance="low" >
      <Output TaskParameter="ExitCode" PropertyName="LocalPaketToolExitCode" />
    </Exec>

    <!-- This is just a debug statement. -->
    <Message Importance="high" Text="$(PaketCommand) - paket command should be empty | $(LocalPaketToolExitCode) - code" />

    <!-- Then we go through our normal steps of setting the Paket command.
         I called it InternalPaketCommand here because apparently properties aren't available
         outside the targets they are declared in. -->
    <PropertyGroup>
      <_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)"))</_PaketExeExtension>
      <InternalPaketCommand Condition=" '$(InternalPaketCommand)' == '' AND '$(_PaketExeExtension)' == '.dll' ">dotnet "$(PaketExePath)"</InternalPaketCommand>
      <InternalPaketCommand Condition=" '$(InternalPaketCommand)' == '' AND '$(_PaketExeExtension)' == '' AND $(LocalPaketToolExitCode) == 0">dotnet "$(PaketExePath)"</InternalPaketCommand>
      <InternalPaketCommand Condition=" '$(InternalPaketCommand)' == '' AND '$(OS)' != 'Windows_NT' AND '$(_PaketExeExtension)' == '.exe' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)"</InternalPaketCommand>
      <InternalPaketCommand Condition=" '$(InternalPaketCommand)' == '' ">"$(PaketExePath)"</InternalPaketCommand>
    </PropertyGroup>

    <!-- The way to get a property to be available outside the target is to use this task. -->
    <CreateProperty Value="$(InternalPaketCommand)">
      <Output TaskParameter="Value" PropertyName="PaketCommand"/>
    </CreateProperty>

    <!-- This is just a debug statement. -->
    <Message Importance="high" Text="$(PaketCommand) - paket command | $(LocalPaketToolExitCode) - code" />
  </Target>

This target will be responsible for creating the PaketCommand property, which is used in two other targets, PaketRestore and PaketOverrideNuspec. Unfortunately it looks like you can’t have properties depend on targets/tasks, so I think this is the only way to do it.

Then to make sure PaketCommand is set before PaketRestore and PaketOverrideNuspec are called, you need to update the DependsOnTargets property for each of them. Top lines of those targets should look something like this:

PaketRestore:

<Target Name="PaketRestore" Condition="'$(PaketRestoreDisabled)' != 'True'" BeforeTargets="_GenerateDotnetCliToolReferenceSpecs;_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreGraphWalkPerFramework;CollectPackageReferences" DependsOnTargets="SetPaketCommand;PaketBootstrapping">

PaketOverrideNuspec:

<Target Name="PaketOverrideNuspec" DependsOnTargets="SetPaketCommand" AfterTargets="GenerateNuspec" Condition="('$(IsPackable)' == '' Or '$(IsPackable)' == 'true') And Exists('$(PaketIntermediateOutputPath)/$(MSBuildProjectFile).references')" >
0reactions
atlemanncommented, Sep 29, 2019

I added one yesterday

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot .NET tool usage issues
You might come across issues when trying to install or run a .NET tool, which can be a global tool or a local...
Read more >
dotnet restore command - .NET CLI
Learn how to restore dependencies and project-specific tools with the dotnet restore command.
Read more >
Run dotnet tool restore to make the dotnet-ef command ...
I found 2 ways. try to run visual studio as administrator. if (1.) does not work, in the project enter dotnet new tool-manifest...
Read more >
"dotnet restore --interactive" doesn't work with Azure Artifacts
I have downloaded the Azure Artifacts Credential Provider by running a powershell command (Invoke-WebRequest...) and installed it - what seems - ...
Read more >
.NET Core Global Tools and Gotchas
A .NET Core global tool is a special NuGet package that contains a console application ... There is no uninstall after dotnet install...
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