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

Missing tools from PackageDownload when publishing as global tool #394

Closed
yang-xiaodong opened this issue Feb 4, 2020 · 11 comments
Closed
Assignees
Milestone

Comments

@yang-xiaodong
Copy link

Description

GitVersion does not work when packaged as dotnet tools for sharing in a team.
The error message is Could not find package 'GitVersion.Tool', or 'GitVersion.CommandLine'

Steps to reproduce

  1. The tools project named MyCommand.csproj
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <PackAsTool>True</PackAsTool>
    <IsPackable>True</IsPackable>
    <ToolCommandName>mycommand</ToolCommandName>
    <PackageOutputPath>./../artefacts</PackageOutputPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Nuke.Common" Version="0.24.0" />
    <PackageDownload Include="GitVersion.Tool" Version="[5.1.1]" />
  </ItemGroup>
  1. Build.cs code under the MyCommand.csproj
class Build : NukeBuild
{
    public static int Main() => Execute<Build>(x => x.ShowVersion);

    [GitVersion] GitVersion GitVersion;

    Target ShowVersion => _ => _
        .Executes(() =>
        {
            Logger.Success("Current Version: " + GitVersion.SemVer);
        });
}
  1. Pack the dotnet tools project MyCommand.csproj and push to nuget server
> dotnet pack MyCommand.csproj 
> dotnet nuget push -s http://192.168.xxx.xxx/v3/index.json ..\artefacts\MyCommand.1.0.0.nupkg

4、Install as the dotnet tool and execute to show the version

> dotnet tool install -g --add-source http://192.168.xxx.xxx/v3/index.json MyCommand
> mycommand showversion

Then the error will be raised

Relevant log output

NUKE Execution Engine version 0.24.0 (Windows,.NETCoreApp,Version=v3.0)

Assertion failed: Could not find package 'GitVersion.Tool', or 'GitVersion.CommandLine' using:
 - Embedded packages directory at ''
   at Nuke.Common.ControlFlow.Fail(String text)
   at Nuke.Common.Tooling.ToolPathResolver.GetPackageDirectory(String[] packageIds, String version)
   at Nuke.Common.Tooling.ToolPathResolver.GetPackageExecutable(String packageId, String packageExecutable, String version, String framework)
   at Nuke.Common.Tools.GitVersion.GitVersionTasks.GetToolPath(String framework)
   at Nuke.Common.Tools.GitVersion.GitVersionSettings.GetToolPath()
   at Nuke.Common.Tools.GitVersion.GitVersionSettings.get_ToolPath()
   at Nuke.Common.Tooling.ProcessTasks.StartProcess(ToolSettings toolSettings)
   at Nuke.Common.Tools.GitVersion.GitVersionTasks.GitVersion(GitVersionSettings toolSettings)
   at Nuke.Common.Tools.GitVersion.GitVersionTasks.GitVersion(Configure`1 configurator)
   at Nuke.Common.Tools.GitVersion.GitVersionAttribute.GetValue(MemberInfo member, Object instance)
   at Nuke.Common.Execution.InjectionUtility.InjectValuesInternal[T](T instance, IEnumerable`1 tuples)
   at Nuke.Common.Execution.InjectionUtility.InjectValues[T](T instance, Func`2 filter)
   at Nuke.Common.Execution.BuildManager.Execute[T](Expression`1[] defaultTargetExpressions)
@matkoch matkoch changed the title Could not find package 'GitVersion.Tool', or 'GitVersion.CommandLine' Missing tools from PackageDownload when publishing as global tool Feb 4, 2020
@matkoch
Copy link
Member

matkoch commented Feb 4, 2020

Could you please star the project?

@yang-xiaodong
Copy link
Author

Sure, :)
By the way , it works in visual studio

@yang-xiaodong
Copy link
Author

If needed, I can help write a blog and publicity in China .net community website. I have about 2000+ followers of .net fans

@matkoch
Copy link
Member

matkoch commented Feb 4, 2020

@yang-xiaodong sure, always welcome :)

what do you mean, what works in Visual Studio?

@yang-xiaodong
Copy link
Author

Source code in visual studio, click nuke icon and debug can print the version, no error!

@matkoch
Copy link
Member

matkoch commented Feb 4, 2020

Yes. That works different than after installing as global tool.

@matkoch
Copy link
Member

matkoch commented Feb 4, 2020

For now I suggest to switch to PackageReference with ExcludeAssets=all. That should work, afaik.

@yang-xiaodong
Copy link
Author

yang-xiaodong commented Feb 5, 2020

@matkoch Thanks for your answer, I tried the suggested way you pointed, it doesn't seem to work for me, am I missing something?

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <PackAsTool>True</PackAsTool>
    <IsPackable>True</IsPackable>
    <ToolCommandName>mycommand</ToolCommandName>
    <PackageOutputPath>./../artefacts</PackageOutputPath>
    <Version>1.0.4</Version>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Nuke.Common" Version="0.24.0" />

<!--<PackageDownload Include="GitVersion.Tool" Version="[5.1.1]" />-->
    <PackageReference Include="GitVersion.Tool" Version="5.1.1">
      <ExcludeAssets>all</ExcludeAssets>
    </PackageReference>    
  </ItemGroup>
</Project>

@cmenzi
Copy link
Contributor

cmenzi commented Feb 5, 2020

Maybe some information on this:

When you're using <ExcludeAssets>all</ExcludeAssets> the references don't get packed into nuget.

I've nearly managed it though .props file. See here: #396

Another option regarding this: NuGet/Home#9132 (comment) is not using `.

Suggestion from nuget team is to use https://github.com/microsoft/MSBuildSdks

GitHub
MSBuild project SDKs. Contribute to microsoft/MSBuildSdks development by creating an account on GitHub.

@krankenbro
Copy link

krankenbro commented Mar 4, 2020

I had the same problem. The found workaround is to add constructor

public Build()
{
        ToolPathResolver.ExecutingAssemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}

@matkoch matkoch added this to the v0.24.6 milestone Mar 25, 2020
@matkoch matkoch closed this as completed Mar 25, 2020
@lock
Copy link

lock bot commented Apr 15, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants