Skip to content

PackageReference should support DevelopmentDependency metadata #4125

Closed

Description

@AArnott

msbuild /t:pack fails when building a stable versioned package that depends on an unstable one, even though that unstable one is a DevelopmentDependency:

  1. Create .NET Core console app
  2. Add this package reference
    <PackageReference Include="Nerdbank.GitVersioning" Version="1.5.28-rc" developmentDependency="true" />`
  3. Pack the project with msbuild /t:pack

Build fails with a crashed MSBuild task with this message:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(73,5): error MSB4018:
The "PackTask" task failed unexpectedly.\r [C:\Users\andre\OneDrive\Documents\Visual Studio 2017\Projects\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(73,5): error MSB4018: System.IO.InvalidDataException: A stable release of a package should not have a prerelease dependency. Either modify the version spec of dependency "Nerdbank.GitVersionin
g [1.5.61-ga5f362ccc1, )" or update the version field in the nuspec.\r [C:\Users\andre\OneDrive\Documents\Visual Studio 2017\Projects\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj]

In fact I shouldn't even have to specify DevelopmentDependency="true" in my reference because the nuspec of the referenced package itself has that property set.

Activity

  1. davidfowl commented on Dec 18, 2016

    @davidfowl
    Member

    You're aiming to have this package excluded from the output package right?

  2. AArnott commented on Dec 18, 2016

    @AArnott
    ContributorAuthor

    Correct: no dependency, no embedding.
    And thus no restriction on using unstable packages while building a stable one.

  3. emgarten commented on Dec 18, 2016

    @emgarten
    Member

    PrivateAssets is the equivalent.

    <PackageReference Include="Nerdbank.GitVersioning" Version="1.5.28-rc">
       <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  4. AArnott commented on Dec 18, 2016

    @AArnott
    ContributorAuthor

    Thanks @emgarten. Should that be a default then when the package's own nuspec sets DevelopmentDependency=true?

    Also, I'm guessing that's not quite equivalent to what we have in project.json (in an MSBuild project). I can add a package dependency to a developmentDependency package and that propagates across project references (as I usually want), yet that doesn't limit my ability to compile those projects into stable packages that don't depend on it. Your PrivateAssets=all metadata suggests to me that it won't propagate across P2Ps.

  5. clairernovotny commented on Dec 21, 2016

    @clairernovotny

    I need this as well for GitVersionTask for the same reason. The GitVersionTask nuspec has developmentDependency set to true.

    When a project references it, it should default the <PrivateAssets>all</PrivateAssets> metadata on that package ref...or whatever is needed to ensure it doesn't get added to the generated nuspec with /t:pack

  6. davidfowl commented on Dec 21, 2016

    @davidfowl
    Member

    @emgarten we need 2 things:

    • We need a way for a package to express what assets get exported when referenced in a project .e.g If I want all projects that reference me to have effectively <PrivateAssets>all</PrivateAssets> by default then I should be able to express that in the nuspec.
    • We should infer developmentDependency set to true as implicitly saying <PrivateAssets>all</PrivateAssets> .
  7. AArnott commented on Feb 16, 2017

    @AArnott
    ContributorAuthor

    Can we at a minimum for Dev15 RTW get developmentDependency=true in a nuspec file to be honored by having the dotnet SDK project type not propagate the dependency in nuget packages it packs?

  8. AArnott commented on Feb 17, 2017

    @AArnott
    ContributorAuthor

    @davidfowl points out that PrivateAssets=all at the consuming side should workaround this issue. This is also consistent with the documentation. But I tried it, and the dotnet pack step still emits a package dependency on it (with the default exclude="Build,Analyzers" attribute no less).

  9. rohit21agrawal commented on Feb 17, 2017

    @rohit21agrawal
    Contributor

    @AArnott pack should not emit a dependency when <PrivateAssets>all</PrivateAssets> is specified. Did you make sure you restored after you added the <PrivateAssets> tag to your dependency? Pack relies on reading the dependencies and their metadata from the assets file, so if the assets file doesn't reflect your changes, pack wouldn't know about them.

  10. AArnott commented on Feb 17, 2017

    @AArnott
    ContributorAuthor

    Thanks, @rohit21agrawal. That was the trick. I was only running dotnet pack after my change rather than a restore as well.

  11. rohit21agrawal commented on Feb 17, 2017

    @rohit21agrawal
    Contributor

    Great! Are we good to close this issue now?

  12. AArnott commented on Feb 17, 2017

    @AArnott
    ContributorAuthor

    No. There's still the matter of developmentDependency being ignored that should have set PrivateAssets=all by default, which @davidfowl seems to agree with as well.

  13. 67 remaining items

  14. nkolev92 commented on Mar 12, 2018

    @nkolev92
    Member

    @AArnott
    Packages can still be both today. There's nothing enforcing that today. It won't work because of the tangential problem because of how build assets transitive flow is handled today, but it's still possible.

    But as you point out, in our case they are different.
    There's no point in fragmenting this experience among PR/MsBuildSDKs.
    The MSBuildSDKs is the correct approach, because itself participates in restore, which allows for a more comprehensive experience.

    Additionally, there's no enforcement on whether development dependency marked packages bring in developmen dependencies themselves.
    If they bring in some runtime dependencies, and the consumer accidentally uses those, it'll break the package when packed later on.

    Sdks don't have that since they have to be self-contained.

    Additionally with development dependency we would introduce a needless basic feature discrepancy among VS and commandline which we've worked very hard not to do.

    We are basically adding an install gesture in PR, which is currently non-existent (other than in name ofc)

  15. bricelam commented on Mar 26, 2018

    @bricelam

    I think the decision to use ExcludeAssets="Runtime" has some unintended consequences. See dotnet/efcore#11437

  16. modified the milestones: 4.7, 4.8 on Apr 3, 2018
  17. jainaashish commented on Apr 3, 2018

    @jainaashish

    Since we had to revert this change because of EF tools package broken with ExcludeAssets=Runtime, I'm reopening this issue. We'll bring it back in 15.8 with more validations.

  18. mwpowellhtx commented on May 13, 2018

    @mwpowellhtx

    👍 re: @bording 's responses.

    So, gentlemen, what's the bottom line here? I contend that seamlessly supporting rolling up developmentDependencies is desirable, with a minimum of files or other assets that I need to touch, whether by hand of via tooling of any kind. PrivateAssets, etc, just introduces a lower signal to noise ratio, IMO, i.e. makes it harder, not easier, to discern whether a dependency ought to be rolled up in the NuGet package.

    Because logic, so to say.

  19. bugproof commented on Jun 27, 2019

    @bugproof

    I tried setting developmentDependency to true and it doesn't work. Only PrivateAssets work.

  20. BinToss commented on Jul 25, 2024

    @BinToss

    I tried setting developmentDependency to true and it doesn't work. Only PrivateAssets work.

    I also misunderstood the spec at https://learn.microsoft.com/en-us/nuget/reference/nuspec#developmentdependency.

    To clarify any confusion...

    <developmentDependency>true</developmentDependency> in a package's nuspec indicates to package managers that the package is a development dependency. See https://learn.microsoft.com/en-us/nuget/reference/nuspec#developmentdependency.

    <!-- microsoft.sourcelink.github.nuspec -->
    <?xml version="1.0" encoding="utf-8"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
      <metadata>
        ...
        <developmentDependency>true</developmentDependency>
        ...
      </metadata>
    </package>

    SDK-style projects generate their nuspec. You can set the value of developmentDependency via the MSBuild property DevelopmentDependency. See https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target-inputs.

    <PropertyGroup>
      <DevelopmentDependency>true</DevelopmentDependency>
    </PropertyGroup>

    or

    dotnet pack -p:DevelopmentDependency=true

    When a package manager adds a "development dependency" package as a PackageReference, the PackageReference's PrivateAssets is set to all and compile is removed from IncludeAssets if applicable. compile assets refer to binaries in a package's lib directory.

    dotnet add package Microsoft.SourceLink.GitHub --version 8.0.0
    <!-- This package was published with <developmentDependency>true</developmentDependency> in its nuspec -->
    <PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
    dotnet add package Newtonsoft.Json --version 13.0.3
    <!-- This package was NOT published with developmentDependency set. -->
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

    Adding DevelopmentDependency="true" or developmentDependency="true" to a PackageReference will do nothing.

    I tried setting developmentDependency to true and it doesn't work. Only PrivateAssets work.

    I also misunderstood the spec at https://learn.microsoft.com/en-us/nuget/reference/nuspec#developmentdependency.

    To clarify any confusion...

    <developmentDependency>true</developmentDependency> in a package's nuspec indicates to package managers that the package is a development dependency. See https://learn.microsoft.com/en-us/nuget/reference/nuspec#developmentdependency.

    <!-- microsoft.sourcelink.github.nuspec -->
    <?xml version="1.0" encoding="utf-8"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
      <metadata>
        ...
        <developmentDependency>true</developmentDependency>
        ...
      </metadata>
    </package>

    SDK-style projects generate their nuspec. You can set the value of developmentDependency via the MSBuild property DevelopmentDependency. See https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target-inputs.

    <PropertyGroup>
      <DevelopmentDependency>true</DevelopmentDependency>
    </PropertyGroup>

    or

    dotnet pack -p:DevelopmentDependency=true

    When a package manager adds a "development dependency" package as a PackageReference, the PackageReference's PrivateAssets is set to all and compile is removed from IncludeAssets if applicable. compile assets refer to binaries in a package's lib directory.

    dotnet add package Microsoft.SourceLink.GitHub --version 8.0.0
    <!-- This package was published with <developmentDependency>true</developmentDependency> in its nuspec -->
    <PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
    dotnet add package Newtonsoft.Json --version 13.0.3
    <!-- This package was NOT published with developmentDependency set. -->
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

    Adding DevelopmentDependency="true" or developmentDependency="true" to a PackageReference will do nothing.

    <!-- still treated as a normal dependency -->
    <PackageReference 
      Include="Newtonsoft.Json" 
      Version="13.0.3" 
      DevelopmentDependency="true" 
    />

    Instead you must use PrivateAssets="all" ExcludeAssets="compile".

    <!-- treated as a development dependency -->
    <PackageReference 
      Include="Newtonsoft.Json"
      Version="13.0.3"
      PrivateAssets="all"
      ExcludeAssets="compile"
    />

    ExcludeAssets="compile" is unnecessary if the package does not contain any libs i.e. the nupkg does not have a "libs" directory. If the package has no compile assets, then it doesn't matter if the compile assets are included. Likewise, package managers won't modify the IncludeAssets of a development dependency if there are no libs to exclude—despite the example indicating IncludeAssets is modified regardless. It better serves as an example of a development dependency that mistakenly includes libs, thereby requiring its compile assets (libs) to be excluded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions