无法升级或降级 NuGet 包
Can't upgrade or downgrade NuGet package
我有一个 ASP.NET 核心网站,它依赖于 2 个 class 库。
他们都引用了 Microsoft.NETCore 但版本不知何故混淆了,导致我收到警告:
Detected package downgrade: Microsoft.NETCore.App from 1.1.0 to 1.0.3
NuGet 不允许我更改 Microsoft.NetCore.App
的版本:
如果我尝试升级或降级,我收到错误
Following versions are unavailable due to additional constraints in the project or packages.config
如何解决这个错误?
我的 csproj 文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>AutomotiveWebPortalCore</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>AutomotiveWebPortalCore</PackageId>
<UserSecretsId>aspnet-AutomotiveWebPortalCore-20170223120414</UserSecretsId>
<RuntimeFrameworkVersion>1.0.3</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);dotnet</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<Content Update="wwwroot\**\*;Views\**\*;Areas\**\Views;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="5.2.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="1.2.0" />
<PackageReference Include="DevExtreme.AspNet.Core" Version="16.2.4" />
<PackageReference Include="DevExtreme.AspNet.Data" Version="1.2.4" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink.Loader" Version="14.0.1" />
<PackageReference Include="bootstrap" Version="3.3.7" />
<PackageReference Include="HubSpot.Tether" Version="1.1.1" />
</ItemGroup>
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
</Target>
<ItemGroup>
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutomotiveDAL\AutomotiveDAL.csproj" />
<ProjectReference Include="..\AutomotiveDTO\AutomotiveDTO.csproj" />
</ItemGroup>
</Project>
编辑:
以下是我的 class 库的参考资料:
数据访问层:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="5.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0-msbuild3-final" />
</ItemGroup>
</Project>
数据传输对象:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
</Project>
"Following versions are unavailable due to additional constraints" 消息似乎甚至出现在全新的空 ASP.NET 核心项目中。我认为这是 NuGet GUI 的错误或功能。 (我使用的是 Visual Studio 2017 的最终发行版)
您可以通过直接编辑 .csproj 文件来解决此问题:在解决方案资源管理器中右键单击该项目,然后 select 编辑 (项目名称).csproj .
您可以在第一个 PropertyGroup 中提升 Microsoft.NETCore.App(和目标框架)的版本:
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<!-- snip -->
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
<!-- snip -->
</PropertyGroup>
然后,关闭文件并重建项目。我用你在问题中提到的所有 (public) 依赖项测试了这个,没有发现任何包版本冲突。
我有一个 ASP.NET 核心网站,它依赖于 2 个 class 库。
他们都引用了 Microsoft.NETCore 但版本不知何故混淆了,导致我收到警告:
Detected package downgrade: Microsoft.NETCore.App from 1.1.0 to 1.0.3
NuGet 不允许我更改 Microsoft.NetCore.App
的版本:
如果我尝试升级或降级,我收到错误
Following versions are unavailable due to additional constraints in the project or packages.config
如何解决这个错误?
我的 csproj 文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>AutomotiveWebPortalCore</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>AutomotiveWebPortalCore</PackageId>
<UserSecretsId>aspnet-AutomotiveWebPortalCore-20170223120414</UserSecretsId>
<RuntimeFrameworkVersion>1.0.3</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);dotnet</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<Content Update="wwwroot\**\*;Views\**\*;Areas\**\Views;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="5.2.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="1.2.0" />
<PackageReference Include="DevExtreme.AspNet.Core" Version="16.2.4" />
<PackageReference Include="DevExtreme.AspNet.Data" Version="1.2.4" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink.Loader" Version="14.0.1" />
<PackageReference Include="bootstrap" Version="3.3.7" />
<PackageReference Include="HubSpot.Tether" Version="1.1.1" />
</ItemGroup>
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
</Target>
<ItemGroup>
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AutomotiveDAL\AutomotiveDAL.csproj" />
<ProjectReference Include="..\AutomotiveDTO\AutomotiveDTO.csproj" />
</ItemGroup>
</Project>
编辑:
以下是我的 class 库的参考资料:
数据访问层:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="5.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0-msbuild3-final" />
</ItemGroup>
</Project>
数据传输对象:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
</Project>
"Following versions are unavailable due to additional constraints" 消息似乎甚至出现在全新的空 ASP.NET 核心项目中。我认为这是 NuGet GUI 的错误或功能。 (我使用的是 Visual Studio 2017 的最终发行版)
您可以通过直接编辑 .csproj 文件来解决此问题:在解决方案资源管理器中右键单击该项目,然后 select 编辑 (项目名称).csproj .
您可以在第一个 PropertyGroup 中提升 Microsoft.NETCore.App(和目标框架)的版本:
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<!-- snip -->
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
<!-- snip -->
</PropertyGroup>
然后,关闭文件并重建项目。我用你在问题中提到的所有 (public) 依赖项测试了这个,没有发现任何包版本冲突。