Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pack command generates incorrect dependencies #4137

Closed
srivatsn opened this issue Dec 21, 2016 · 7 comments
Closed

Pack command generates incorrect dependencies #4137

srivatsn opened this issue Dec 21, 2016 · 7 comments

Comments

@srivatsn
Copy link

Moved from dotnet/sdk#484 filed by @onovotny

I have a project which cross compiles to many target frameworks, including desktop .NET 4.5.

I have the NETStandard.Library excluded from net45 as many users complain when adding that dependency. When I then run msbuild /t:pack or dotnet pack (same thing), the dependencies it generates includes netstandard1.0 (which is a valid target platform), but it does not generate an empty group for net45. It's not properly calculating the dependencies that only affect net45.

The result is that the net45 package will resolve and get the netstandard1.0 set of dependencies because there's no explicit net45 dependency group and that's the problem.

Here's what it generates:
img

And here's the csproj that created it.

<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!--<Import Condition=" '$(TargetFramework)' == 'uap10.0'"  Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />-->
  <PropertyGroup>
    <TargetFrameworks>netstandard1.0;netstandard1.3;net45;uap10.0;portable-win81+wpa81;win8;wpa81;wp8</TargetFrameworks>
  </PropertyGroup>
  <PropertyGroup Condition="'$(TargetFramework)' == 'win8'">
    <TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup Condition="'$(TargetFramework)' == 'wpa81'">
    <TargetFrameworkIdentifier>WindowsPhoneApp</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v8.1</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup Condition="'$(TargetFramework)' == 'portable-win81+wpa81'">
    <TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
    <TargetFrameworkProfile>Profile32</TargetFrameworkProfile>
  </PropertyGroup>
  <PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0'">
    <NugetTargetMoniker>UAP,Version=v10.0</NugetTargetMoniker>
    <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
    <TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
    <TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
    <TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
  </PropertyGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'portable-win81+wpa81' ">
    <Reference Include="System" />
    <Reference Include="System.Runtime" />
    <Reference Include="System.Runtime.Extensions" />
    <Reference Include="System.Resources.ResourceManager" />
    <Reference Include="System.Core" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <PropertyGroup Condition="'$(TargetFramework)' == 'wp8'">
    <TargetFrameworkIdentifier>WindowsPhone</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v8.0</TargetFrameworkVersion>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="NETStandard.Library" Version="1.6.1" Condition="'$(TargetFramework)' != 'net45'"/>
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'win8' or '$(TargetFramework)' == 'wpa81'  or '$(TargetFramework)' == 'wp8' ">
    <Reference Include="System" />
    <Reference Include="System.Runtime" />
    <Reference Include="System.Runtime.Extensions" />
    <Reference Include="System.Resources.ResourceManager" />
    <Reference Include="System.Core" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0' ">
    <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="5.2.2" />
    <PackageReference Include="Microsoft.TargetingPack.Private.WinRT" Version="1.0.3">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>
@clairernovotny
Copy link

Ping @rrelyea, can this please hit RC3? The issue is that for an empty dependency group, it's not emitting a blank in the nuspec.

@rohit21agrawal
Copy link
Contributor

@rrelyea we should assign a milestone to this asap

@rohit21agrawal
Copy link
Contributor

@srivatsn there seems to be a build issue with the project file above :

CSC : error CS0006: Metadata file '\mscorlib.dll' could not be found [D:\temp\packagerefissue\packagerefissue.csproj]

Attaching a repro project - running dotnet restore, and then dotnet build repros the issue. Can you get someone to take a look?

packagerefissue.zip

@rohit21agrawal
Copy link
Contributor

@onovotny if i understood your issue correctly, i have tried to repro it with a minimal csproj file, and it does have an empty net45 dependency group in the nuspec. We have made some changes to how pack gets its dependencies recently, and it may have fixed your issue. You can try it yourself by downloading the latest CLI version that also includes the sdk.

Here is the project that i used.
packagerefissue (2).zip

If this solved your issue, please let me know so i can close this bug.

@rohit21agrawal
Copy link
Contributor

@onovotny have you tried repro'ing this issue with the latest CLI ?

@clairernovotny
Copy link

Just tried with the latest CLI and can confirm this is fixed for me. Thanks!

@rohit21agrawal
Copy link
Contributor

Awesome! Thanks for validating :)

jkommer added a commit to jkommer/GravatarHelper that referenced this issue Jan 24, 2017
Currently awaiting for NuGet/Home#4137 to be resolved - as dotnet pack causes our NET45 build NETStandard.Library which we wait to avoid.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants