Dotnet Pack vs Nuget.exe Pack,版本降级错误
Dotnet Pack vs Nuget.exe Pack, version downgrade error
我们已从使用 nuget.exe pack 更改为 dotnet pack(以摆脱对 .nuspec 文件的需求)
我们曾经运行这个命令:
nuget pack "MyComp.Shared\MyComp.Shared.csproj" -OutputDirectory c:\nugetlocal -version 2021.7.7.1149-local -symbols
在开发过程中,我们在本地项目中使用这个打包的 nuget 不会有任何问题。
现在我们 运行
dotnet pack "MyComp.Shared\MyComp.Shared.csproj" -output c:\nugetlocal -version 2021.7.7.1149-local --include-symbols
但是,当我们使用这个包时,我们现在会收到版本降级错误。使用第一个命令 nuget.exe packed 时不会发生这种情况。
错误
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
Nuget 包项目
<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>
消费项目
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MyComp.Enums" Version="2021.7.5.1317" />
</ItemGroup>
</Project>
编辑:this link 确实帮助解决了问题
要了解问题,
您可以获取一个 .nupkg 文件,将扩展名更改为 .zip,然后打开该文件。里面是一个 .nuspec 文件。
当我们使用 nuget.exe 打包时,<dependancies />
标签中没有包含任何内容。
我们意识到 dotnet pack
将项目引用添加到内部 .nuspec 文件中,并使用与您正在打包的项目相同的版本号标记它们
所以我们需要确保在构建一个时,我们构建依赖项并使用它们。
<?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>
我们已从使用 nuget.exe pack 更改为 dotnet pack(以摆脱对 .nuspec 文件的需求)
我们曾经运行这个命令:
nuget pack "MyComp.Shared\MyComp.Shared.csproj" -OutputDirectory c:\nugetlocal -version 2021.7.7.1149-local -symbols
在开发过程中,我们在本地项目中使用这个打包的 nuget 不会有任何问题。
现在我们 运行
dotnet pack "MyComp.Shared\MyComp.Shared.csproj" -output c:\nugetlocal -version 2021.7.7.1149-local --include-symbols
但是,当我们使用这个包时,我们现在会收到版本降级错误。使用第一个命令 nuget.exe packed 时不会发生这种情况。
错误
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
Nuget 包项目
<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>
消费项目
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MyComp.Enums" Version="2021.7.5.1317" />
</ItemGroup>
</Project>
编辑:this link 确实帮助解决了问题
要了解问题,
您可以获取一个 .nupkg 文件,将扩展名更改为 .zip,然后打开该文件。里面是一个 .nuspec 文件。
当我们使用 nuget.exe 打包时,<dependancies />
标签中没有包含任何内容。
我们意识到 dotnet pack
将项目引用添加到内部 .nuspec 文件中,并使用与您正在打包的项目相同的版本号标记它们
所以我们需要确保在构建一个时,我们构建依赖项并使用它们。
<?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>