Skip to content
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

Mixed solution (.net full/.net core) doesn't work with global paket installation #3687

Closed
Lanayx opened this issue Oct 16, 2019 · 20 comments
Closed

Comments

@Lanayx
Copy link

Lanayx commented Oct 16, 2019

Description

I can't make mixed solution work.

Repro steps

Create a new solution with full .net console application.
Add new console .net core application to the solution.
Run command paket convert-from-nuget (I have paket installed globally as dotnet tool)
Try to run full .net console app

Expected behavior

Console app runs successfully

Actual behavior

I get error
The command ""C:\Users\user\source\repos\MixedSolution\.paket\paket.exe" restore --references-file "C:\Users\user\source\repos\MixedSolution\paket.references"" exited with code 9009.

Known workarounds

Copy paket.exe to .paket folder

@forki
Copy link
Member

forki commented Oct 16, 2019

can you please upload a zip with repro?

@Lanayx
Copy link
Author

Lanayx commented Oct 16, 2019

Sure, here you go
MixedSolution.zip

@forki
Copy link
Member

forki commented Oct 16, 2019

I just added paket.exe (bootstrapper in magic mode) in your .paket folder. run .paket\paket.exe restore and dotnet build and all worked.

@Lanayx
Copy link
Author

Lanayx commented Oct 16, 2019

I see, will update description. Can it be fixed for global paket installation?

@Lanayx Lanayx changed the title Mixed solution (.net full/.net core) doesn't work Mixed solution (.net full/.net core) doesn't work with global paket installation Oct 16, 2019
@forki
Copy link
Member

forki commented Oct 16, 2019 via email

@Lanayx
Copy link
Author

Lanayx commented Oct 16, 2019

I do use the latest paket version and targets file is inside .paket folder in my example. You can also take a look at Repro steps, I got everything just by creating projects from scratch and running convert-from-nuget command.

@forki
Copy link
Member

forki commented Oct 16, 2019 via email

@Lanayx
Copy link
Author

Lanayx commented Oct 16, 2019

Sorry, mixed up with paket.targets. I've tried adding paket.exe in .paket folder and console app worked and Paket.Restore.targets were generated. But whenever I remove paket.exe from that folder to make use of global paket, I get the same error again (even though Paket.Restore.targets is present now).

@forki
Copy link
Member

forki commented Oct 16, 2019

@atlemann ideas?

@atlemann
Copy link
Contributor

It doesn't work for full framework only solution, so it doesn't matter if it's mixed platform. Why, I don't know yet, but I never changed paket.targets when adding cli-tool support. Maybe we have to copy that part from paket.Restore.targets?

@atlemann
Copy link
Contributor

It's very strange, since we're using paket as global tool for a massive project with 150ish full-framework projects and a couple of new-sdk projects and it works...

@atlemann
Copy link
Contributor

Replacing paket.targest with the following seems to fix it. But why it still works for our current soution, I don't know. I'll have to investigate.

@Lanayx Could you try to replace the content of your paket.targets file with the following and see if it helps?

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <!-- Enable the restore command to run before builds -->
    <RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>
    <PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath>
    <PaketRootPath>$(MSBuildThisFileDirectory)..\</PaketRootPath>
    <PaketLockFilePath>$(PaketRootPath)paket.lock</PaketLockFilePath>
    <PaketRestoreCacheFile>$(PaketRootPath)paket-files\paket.restore.cached</PaketRestoreCacheFile>
    <MonoPath Condition="'$(MonoPath)' == '' And Exists('/Library/Frameworks/Mono.framework/Commands/mono')">/Library/Frameworks/Mono.framework/Commands/mono</MonoPath>
    <MonoPath Condition="'$(MonoPath)' == ''">mono</MonoPath>
  </PropertyGroup>

<!-- Check if paket is available as local dotnet cli tool -->
  <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>

    <!-- If local paket tool is found, use that -->
    <PropertyGroup Condition=" '$(LocalPaketToolExitCode)' == '0' ">
      <InternalPaketCommand>dotnet paket</InternalPaketCommand>
    </PropertyGroup>

    <!-- If not, then we go through our normal steps of setting the Paket command.  -->
    <PropertyGroup Condition=" '$(LocalPaketToolExitCode)' != '0' ">
      <!-- windows, root => tool => proj style => bootstrapper => global -->
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' == 'Windows_NT' AND Exists('$(PaketRootPath)paket.exe') ">$(PaketRootPath)paket.exe</PaketExePath>
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' == 'Windows_NT' AND Exists('$(PaketToolsPath)paket.exe') ">$(PaketToolsPath)paket.exe</PaketExePath>
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' == 'Windows_NT' AND '$(PaketBootstrapperStyle)' == 'proj' ">$(PaketToolsPath)paket.exe</PaketExePath>
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' == 'Windows_NT' AND Exists('$(PaketBootStrapperExeDir)') ">$(_PaketBootStrapperExeDir)paket.exe</PaketExePath>
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' == 'Windows_NT' ">paket.exe</PaketExePath>

      <!-- no windows, try native paket as default,  root => tool => proj style => mono paket => bootstrpper => global -->
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND Exists('$(PaketRootPath)paket') ">$(PaketRootPath)paket</PaketExePath>
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND Exists('$(PaketToolsPath)paket') ">$(PaketToolsPath)paket</PaketExePath>
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND '$(PaketBootstrapperStyle)' == 'proj' ">$(PaketToolsPath)paket</PaketExePath>

      <!-- no windows, try mono paket -->
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND Exists('$(PaketRootPath)paket.exe') ">$(PaketRootPath)paket.exe</PaketExePath>
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND Exists('$(PaketToolsPath)paket.exe') ">$(PaketToolsPath)paket.exe</PaketExePath>

      <!-- no windows, try bootstrapper -->
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' AND Exists('$(PaketBootStrapperExeDir)') ">$(PaketBootStrapperExeDir)paket.exe</PaketExePath>

      <!-- no windows, try global native paket -->
      <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(OS)' != 'Windows_NT' ">paket</PaketExePath>

      <_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)"))</_PaketExeExtension>
      <InternalPaketCommand Condition=" '$(InternalPaketCommand)' == '' AND '$(_PaketExeExtension)' == '.dll' ">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>

  </Target>

  <Choose> <!-- MyProject.fsproj.paket.references has the highest precedence -->
    <When Condition="Exists('$(MSBuildProjectFullPath).paket.references')">
      <PropertyGroup>
        <PaketReferences>$(MSBuildProjectFullPath).paket.references</PaketReferences>
      </PropertyGroup>
    </When> <!-- MyProject.paket.references -->
    <When Condition="Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references')">
      <PropertyGroup>
        <PaketReferences>$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references</PaketReferences>
      </PropertyGroup>
    </When> <!-- paket.references -->
    <When Condition="Exists('$(MSBuildProjectDirectory)\paket.references')">
      <PropertyGroup>
        <PaketReferences>$(MSBuildProjectDirectory)\paket.references</PaketReferences>
      </PropertyGroup>
    </When> <!-- Set to empty if a reference file isn't found matching one of the 3 format options -->
    <Otherwise>
      <PropertyGroup>
        <PaketReferences></PaketReferences>
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <PropertyGroup>
    <!-- We need to ensure packages are restored prior to assembly resolve -->
    <BuildDependsOn Condition="$(RestorePackages) == 'true'">RestorePackages; $(BuildDependsOn);</BuildDependsOn>
  </PropertyGroup>
  
  <Target Name="RestorePackages" DependsOnTargets="SetPaketCommand">

    <PropertyGroup>
      <!-- Commands -->
      <RestoreCommand>$(PaketCommand) restore --references-file "$(PaketReferences)"</RestoreCommand>
      <PaketRestoreRequired>true</PaketRestoreRequired>
    </PropertyGroup>

    <PropertyGroup Condition="Exists('$(PaketRestoreCacheFile)') ">
      <PaketRestoreCachedHash>$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedHash>
      <PaketRestoreLockFileHash>$([System.IO.File]::ReadAllText('$(PaketLockFilePath)'))</PaketRestoreLockFileHash>
      <PaketRestoreRequired>true</PaketRestoreRequired>
      <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
      <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired>
    </PropertyGroup>

    <Exec Command="$(RestoreCommand)"
          IgnoreStandardErrorWarningFormat="true"
          WorkingDirectory="$(PaketRootPath)"
          ContinueOnError="false"
          Condition=" '$(PaketRestoreRequired)' == 'true' AND Exists('$(PaketReferences)') AND '$(PaketReferences)' != '' " 
    />
  </Target>
</Project>

@atlemann
Copy link
Contributor

Haha, found it. It seems paket.exe still exists in then .paket folder. That's why it works. It's been a while since I worked on that solution. I guess I'll open a PR to fix paket.targets. Guess there aren't many users of global tools and full framework projects, since this came up this late.

@forki
Copy link
Member

forki commented Oct 17, 2019 via email

@Lanayx
Copy link
Author

Lanayx commented Oct 17, 2019

@atlemann For some reason .net full only solution worked well for me with global tools and without paket.exe in .paket folder. As for mixed solution - I've replaced paket.targets with your version and it worked.

Guess there aren't many users of global tools and full framework projects

Yes, I think it's because this page doesn't suggest this option even though it's the simplest way to get started.

@forki
Copy link
Member

forki commented Oct 17, 2019

the updated paket.targets file ships with 5.226.0

@forki forki closed this as completed Oct 17, 2019
@Lanayx
Copy link
Author

Lanayx commented Oct 17, 2019

Thank you guys for such a quick resolution!

@atlemann
Copy link
Contributor

No prob, forki usually fixes things faster than Lucky Luke draws his weapon.

Now the question is, how do I update it in an existing project? Invoking paket restore only updates paket.Restore.targets, but nothing happens to paket.targets...hmm...

@forki
Copy link
Member

forki commented Oct 17, 2019

yes we do not touch the old targets files. people need to download those from release page

@atlemann
Copy link
Contributor

Ok, I just did. Fix works for our massive solution as well...when I removed the dangling .paket/paket.exe file which I thought was gone. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants