简体   繁体   English

do.net Pack vs Nuget.exe Pack,版本降级报错

[英]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)我们已经从使用 nuget.exe 包更改为 do.net 包(以摆脱对 .nuspec 文件的需要)

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.在开发过程中,我们在本地项目中使用这个打包的 nuget 不会有任何问题。

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.但是,当我们使用这个 package 时,我们现在会遇到版本降级错误。 This didn't happen with nuget.exe packed, using the first command.使用第一个命令打包 nuget.exe 时不会发生这种情况。

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 Nuget package 项目

<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.您可以获取一个.nupkg 文件,将扩展名更改为.zip,然后打开该文件。 Inside is a.nuspec file.里面是一个.nuspec 文件。

When we packed with nuget.exe, this did not include anything in the <dependancies /> tag.当我们打包 nuget.exe 时, <dependancies />标签中没有包含任何内容。

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我们意识到do.net pack将项目引用添加到 internal.nuspec 文件中,并使用与您正在打包的项目相同的版本号标记它们

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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