我有一个ASP.NET核心网站,它依赖于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>
答案 0 :(得分:7)
即使在一个全新的空ASP.NET核心项目中,似乎也会出现“由于其他约束而导致以下版本不可用”的消息。我认为这是一个bug或NuGet GUI的一个功能。 (我正在使用Visual Studio 2017的最终版本)
您可以通过直接编辑.csproj文件来解决此问题:在解决方案资源管理器中右键单击项目,然后选择编辑(项目名称).csproj 。
您可以在第一个PropertyGroup中提升Microsoft.NETCore.App(和目标框架)的版本:
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<!-- snip -->
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
<!-- snip -->
</PropertyGroup>
然后,关闭文件并重建项目。我使用您在问题中提到的所有(公共)依赖项对此进行了测试,但未发现任何包版本冲突。