NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 250 forks source link

Nuget doesn't show target frameworks information in UI if there is no dependency #7160

Open gowthamrang opened 6 years ago

gowthamrang commented 6 years ago

Details about Problem

I was trying to pack, a library, managed by a legacy csproj file. Nuget pack command was able to pack the library excluding the target framework version information in the nuspec file. I was expecting nuget pack to read the target framework version from the legacy csproj file and include that information with the nuspec file

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):

NuGet Version: 4.3.0.4406

VS version (if appropriate): 15.6.6

OS version (i.e. win10 v1607 (14393.321)): win10 pro

Detailed repro steps so we can see the same problem

  1. Consider a legacy Test.csproj

  2. nuget pack Test.csproj

...

Other suggested things

Verbose Logs

NuGet Version: 4.3.0.4406
Attempting to build package from 'TestLibrary.csproj'.
MSBuild auto-detection: using msbuild version '15.6.85.37198' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Packing files from 'd:\Documents\Visual Studio 2017\Projects\TestLibrary\TestLibrary\bin\Debug'.
Add file 'd:\Documents\Visual Studio 2017\Projects\TestLibrary\TestLibrary\bin\Debug\TestLibrary.dll' to package as 'lib\net471\TestLibrary.dll'
WARNING: Description was not specified. Using 'Description'.
WARNING: Author was not specified. Using 'g.raman'.

Id: TestLibrary
Version: 1.0.0
Authors: g.raman
Description: Description
Dependencies:

Added file '[Content_Types].xml'.
Added file '_rels/.rels'.
Added file 'lib/net471/TestLibrary.dll'.
Added file 'package/services/metadata/core-properties/cb5d4cb0aa424bcd9019c62abfa9786f.psmdcp'.
Added file 'TestLibrary.nuspec'.

Successfully created package 'd:\Documents\Visual Studio 2017\Projects\TestLibrary\TestLibrary\TestLibrary.1.0.0.nupkg'.

Sample Project

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>1ed5b2c7-d3b8-464c-94e6-b14c9934fc00</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>TestLibrary</RootNamespace>
    <AssemblyName>TestLibrary</AssemblyName>
    <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System"/>

    <Reference Include="System.Core"/>
    <Reference Include="System.Xml.Linq"/>
    <Reference Include="System.Data.DataSetExtensions"/>

    <Reference Include="Microsoft.CSharp"/>

    <Reference Include="System.Data"/>

    <Reference Include="System.Net.Http"/>

    <Reference Include="System.Xml"/>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

Very helpful if you can zip a project and paste into this issue!

jainaashish commented 6 years ago

Target framework information has implicitly been included when it adds assembly under lib/net471/TestLibrary.dll which is what helps NuGet to figure out the target framework when it tries to install this package. So there is no need of explicitly including target framework information.

gowthamrang commented 6 years ago

Ah ok, the visual studio-nuget client doesn't display this information

I was hoping to see something like this expected and this is what I'm seeing testlibrary ]

jainaashish commented 6 years ago

On a second thought, NuGet UI can do a better job showing list of frameworks even though there is no dependency similar to NuGet.org behavior.... That will be really useful for the consumer to figure out the supported framework until we have the search by tfm or package applicability features in place.

image

cc @rrelyea

donnie-msft commented 1 year ago

On a second thought, NuGet UI can do a better job showing list of frameworks even though there is no dependency similar to NuGet.org behavior.... That will be really useful for the consumer to figure out the supported framework until we have the search by tfm or package applicability features in place.

image

cc @rrelyea

Maybe this was fixed at some point? I see this package showing in PM UI the same as nuget.org. Version 17.7.0 Preview 2.0 [33630.43.main]

image

zivkan commented 1 year ago

@donnie-msft SDK style projects that are packed create empty dependency groups for TFMs that don't have dependencies. Therefore, the .nuspec file defines the dependencies node, plus a group that specifies the TFM, as can be verified in NuGet Package Explorer (click the "View metadata source" button): https://nuget.info/packages/Microsoft.Extensions.DependencyInjection.Abstractions/2.1.1

I'm not sure if nuget.exe pack does the same for legacy csproj (that does not have any packages installed), but that's exactly what the issue author said does not happen.

donnie-msft commented 1 year ago

I see, then the comment I quoted was not a real example and worse, it's misleading since it postulates that what shows on nuget.org doesn't show on PM UI. Thanks for pointing it out.