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 pack for global tools support for Full framework

See original GitHub issue

My idea is to have both global tool, and regular application, so non developers could be targeted with app running full framework

Steps to reproduce

  1. Create global tool, and add support for multiple target frameworks
<Project Sdk="Microsoft.NET.Sdk">
  1. run dotnet pack

Expected behavior

Generate pack only for netcoreapp2.1 or provide ability to select which TFM target

Actual behavior

C:\Program Files\dotnet\sdk\2.1.300-rc1-008673\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.PackTool.targets(42,5): error : only supports .NET Core. [XXX.csproj]

Environment data

dotnet --info output:

Пакет SDK для .NET Core (отражающий любой global.json): Version: 2.1.300-rc1-008673 Commit: f5e3ddbe73

Host (useful for support): Version: 2.1.0-rc1 Commit: eb9bc92051

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

KalleOlaviNiemitalocommented, Aug 12, 2021

Found a way to put it all in one csproj:

    <PackAsTool Condition="$(TargetFramework) != 'net40'">true</PackAsTool>

The resulting nupkg:

  • Declares <packageType name="DotnetTool" />.
  • Contains a tools\netcoreapp2.1\any directory with files in it.
  • Does not contain a lib directory.
  • Does not declare <group targetFramework=".NETFramework4.0" />.
  • Does not contain net40 binaries.
  • Can be installed by dotnet tool install and run.
  • May still declare things like the following. ☹
         <frameworkAssembly assemblyName="WindowsBase" targetFramework=".NETFramework4.0" />
moh-hassancommented, Oct 30, 2018

I faced the same problem and I did the following workaround solution:

To avoid creation of shared project:

  • The console application is multi-target (net45;netappcore2.1) ASIS, no PackAsTool

  • Create new project for the global tool (MyGlobalTool.csproj) : netappcore2.1 with PackAsTool = true Add reference to MyConsole project application

      <ProjectReference Include="..\Myconsole\Myconsole.csproj" />

    in netcoreapp MyGlobalTool project, create a class with Main method that call MyConsole.Main()

     class Program
      	static void  Main(string[] args)
      		MyConsole.Program.Main(args); //Main method in MyConsole application.

The advantage of this solution:

  • Avoid creation of shared project (Two projects instead of three projects)
  • Creating two different packages one with PackageId /content/tool for MyConsole (net45) and Another package for netcoreapp2.1 with its PackageId /content/tool (netcoreapp2.1 tool) (I need to distribute two different nuget packages: Myconsole (net45)/MyGlobalTool (netcoreapp2.1)
Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet pack command - .NET CLI
The dotnet pack command builds the project and creates NuGet packages. The result of this command is a NuGet package (that is, a...
Read more >
NET tools - .NET CLI
Covers global tools, tool-path tools, and local tools. ... A .NET tool is a special NuGet package that contains a console application.
Read more >
Tutorial: Install and use a .NET global tool - .NET CLI
Complete the first tutorial of this series. Use the tool as a global tool. Install the tool from the package by running the...
Read more >
Tutorial: Create a .NET tool using the .NET CLI
In this tutorial, you create and package a tool. In the next two tutorials you use the tool as a global tool and...
Read more >
dotnet tool install command - .NET CLI
The dotnet tool install command installs the specified .NET tool on your machine.
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 Post

No results found

github_iconTop Related Hashnode Post

No results found