dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.71k stars 1.07k forks source link

dotnet pack for global tools support for Full framework #9394

Open kant2002 opened 6 years ago

kant2002 commented 6 years ago

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">
    <PropertyGroup>
    <PackAsTool>true</PackAsTool>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp2.1;net462</TargetFrameworks>
    </PropertyGroup>
    </Project>
  2. 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

peterhuene commented 6 years ago

Hi @kant2002. Thanks for reporting this to us. I don't think we've considered this scenario fully. Including @wli3 to the discussion.

As a possible workaround (one I haven't tried), would it be possible to make setting PackAsTool conditional on '$(TargetFramework)' == 'netcoreapp2.1'?

kant2002 commented 6 years ago

Yes, indeed this working. Thanks, that's at least allow me move forward, and don't play with shared projects or additional dependencies too much.

kant2002 commented 6 years ago

My mistake. It is actually pack right now without errors

What is not here is

   <packageTypes>
      <packageType name="DotnetTool" />
    </packageTypes>

part is missing from NUSPEC file

For additional information, if this is needed, I specify condition like this.

  <PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
    <PackAsTool>true</PackAsTool>    
  </PropertyGroup>
wli3 commented 6 years ago

https://github.com/dotnet/sdk/pull/2152

wli3 commented 6 years ago

This is expected and deliberate. As of today, global tools only support netcoreapp2.1

kant2002 commented 6 years ago

@wli3 Please reopen, I understand why I have such error, but it does not cover my use-case, and I think it is justifiable to want create both regular EXE file and dotnet global tool. Not everybody jump on the .NET Core bandwagon, and distribute small EXE with dependency as ZIP archive is still viable option. Why I have to duplicate code in two different projects, then all what I want is create both regular EXE and global tool from same project. I understand that netcoreapp2.0 or net462 would not work as global tools. Maybe technically not the same, but regular console application and global tool is same for me, but global tool is just different distribution mechanism.

kant2002 commented 6 years ago

Maybe this should be documentation issue. If such, you could point me to the appropriate location, so I would ask there. And if that documentation issue, I could contribute to it as well, as well I want to contribute here.

wli3 commented 6 years ago

@KathleenDollard

@kant2002 thank you. I understand your scenario. Let me change the title to global tools full framework support. And mark it as a feature requires.

Ask for documentation. We have several documentation in process for global tools for 2.1.300 release.

moh-hassan commented 6 years ago

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

To avoid creation of shared project:

KalleOlaviNiemitalo commented 3 years ago

Found a way to put it all in one csproj:

<PropertyGroup>
    <TargetFrameworks>net40;netcoreapp2.1</TargetFrameworks>
    <PackAsTool Condition="$(TargetFramework) != 'net40'">true</PackAsTool>
    <SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>

The resulting nupkg: