简体   繁体   中英

Dotnet Pack vs Nuget.exe Pack, version downgrade error

We have changed from using nuget.exe pack, to do.net pack (to get rid of the need for a.nuspec file)

We used to run this command:

nuget pack "MyComp.Shared\MyComp.Shared.csproj" -OutputDirectory c:\nugetlocal -version 2021.7.7.1149-local -symbols

And we would have no issues consuming this packed nuget in our local project during development.

Now instead we run

dotnet pack "MyComp.Shared\MyComp.Shared.csproj" -output c:\nugetlocal -version 2021.7.7.1149-local --include-symbols

However, when we consume this package we now get version downgrade errors. This didn't happen with nuget.exe packed, using the first command.

The error

Severity    Code    Description Project File    Line    Suppression State   Tool
Error   NU1605  Detected package downgrade: MyComp.Enums from 2021.7.7.1149-local to 2021.7.5.1317. Reference the package directly from the project to select a different version. 
 MyComp.Processors -> MyComp.Shared 2021.7.7.1149-local -> MyComp.Enums (>= 2021.7.7.1149-local) 
 MyComp.Processors -> MyComp.Enums (>= 2021.7.5.1317)   MyComp.Processors   C:\Users\uzzer\source\repos\MyCompp\MyComp.Processors\MyComp.Processors.csproj  

The Nuget package project

<Project Sdk="Microsoft.NET.Sdk">
    
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <PackageId>MyComp.Shared</PackageId>
    <Description>MyComp.Shared</Description>
    <Authors>MyComp</Authors>
    <Company>MyComp</Company> 
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentValidation" Version="10.1.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.6" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.6" />
    <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.6" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyComp.Extensions\MyComp.Extensions.csproj" />
    <ProjectReference Include="..\MyComp.Enums\MyComp.Enums.csproj" />
  </ItemGroup>

</Project>

The consuming project

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MyComp.Enums" Version="2021.7.5.1317" />
  </ItemGroup>

</Project>

EDIT: this link really helped solve the issue

To understand the issue,

You can take a.nupkg file, change the extension to.zip and then open the file. Inside is a.nuspec file.

When we packed with nuget.exe, this did not include anything in the <dependancies /> tag.

What we realized what that do.net pack takes project references adds them to the internal.nuspec file, and version stamps them with the same version number as the project you are packing

So we need to make sure that when we build one, we build the dependencies and consume those too.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>MyComp.Shared</id>
    <version>2021.7.7.1150-local</version>
    <authors>MyComp</authors>
    <description>MyComp.Shared</description>
    <dependencies>
      <group targetFramework="net5.0">
        <dependency id="MyComp.Enums" version="2021.7.7.1150-local" exclude="Build,Analyzers" />
        <dependency id="FluentValidation" version="10.1.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Identity" version="2.2.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Identity.EntityFrameworkCore" version="5.0.6" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Mvc.Abstractions" version="2.2.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.AspNetCore.Mvc.ViewFeatures" version="2.2.0" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.Identity.Core" version="5.0.6" exclude="Build,Analyzers" />
        <dependency id="Microsoft.Extensions.Identity.Stores" version="5.0.6" exclude="Build,Analyzers" />
        <dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
</package>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM