我有一个ASP.NET Core网站,它依赖于2个类库。
他们都引用了Microsoft.NETCore,但是这些版本有些混淆,导致我收到警告:
检测到的程序包降级:Microsoft.NETCore.App从1.1.0降到1.0.3
NuGet不允许我更改Microsoft.NetCore.App
的版本:
如果我尝试升级或降级,则会收到错误消息
由于项目或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>
编辑:
这是我的类库的参考:
数据访问层:
<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>
最佳答案
即使在全新的空ASP.NET Core项目中,似乎也会出现“由于其他限制而导致以下版本不可用”的消息。我认为这是NuGet GUI的错误或功能。 (我正在使用Visual Studio 2017的最终发行版)
您可以通过直接编辑.csproj文件来解决该问题:在解决方案资源管理器中右键单击该项目,然后选择Edit(projectname).csproj。
您可以在第一个PropertyGroup中提高Microsoft.NETCore.App(和目标框架)的版本:
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<!-- snip -->
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
<!-- snip -->
</PropertyGroup>
然后,关闭文件并重建项目。我用问题中提到的所有(公共)依赖项对此进行了测试,但没有发现任何软件包版本冲突。