使用ASP.NET Core 2.2“无法找到任何兼容的框架版本”

时间:2019-03-26 14:06:57

标签: c# asp.net .net-core

我有一个ASP.Net Core MVC 2.2应用程序。 在Visual Studio中运行应用程序可以正常工作。但是,当我尝试使用 dotnet publish 发布应用程序时,出现以下错误:

It was not possible to find any compatible framework version
  The specified framework 'Microsoft.NETCore.App', version '1.0.0' was not found.
    - Check application dependencies and target a framework version installed at:
        C:\Program Files\dotnet\
    - Installing .NET Core prerequisites might help resolve this problem:
        https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
    - The .NET Core framework and SDK can be installed from:
        https://aka.ms/dotnet-download
    - The following versions are installed:
        2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        2.1.5 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        2.1.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        2.1.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        2.1.8 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        2.1.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        2.2.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
        2.2.3 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

我不知道在哪里可以引用V 1.0.0,这里是dotnet --info的输出

.NET Core SDK (gem„á "global.json"):
 Version:   2.2.105
 Commit:    7cecb35b92

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.105\

Host (useful for support):
  Version: 2.2.3
  Commit:  6b8ad509b6

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.403 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.503 [C:\Program Files\dotnet\sdk]
  2.1.504 [C:\Program Files\dotnet\sdk]
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.2.104 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

未使用global.json文件,*。csproj文件如下所示:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
   <TargetFramework>netcoreapp2.2</TargetFramework>
    <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>a17e.Web</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>a17e.Web</PackageId>
    <TypeScriptToolsVersion>3.1</TypeScriptToolsVersion>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='thi|AnyCPU'" />

  <ItemGroup>
    <None Include="App.config" />
    <None Update="log4net.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
    <None Update="Views\**\*;Areas\**\*.cshtml">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\a17e.Application\a17e.Application.csproj" />
    <ProjectReference Include="..\a17e.EntityFrameworkCore\a17e.EntityFrameworkCore.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Castle.LoggingFacility.MsLogging" Version="3.1.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
    <PackageReference Include="BundlerMinifier.Core" Version="2.9.406" />
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.4.0" />
    <PackageReference Include="Abp.AspNetCore" Version="4.4.0" />
    <PackageReference Include="Abp.Castle.Log4Net" Version="4.4.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="2.2.2" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.2.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.2.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
    <PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>

  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <Exec Command="dotnet bundle" />
  </Target>

  <ItemGroup>
    <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="logs\" />
    <Folder Include="wwwroot\css\views\account\" />
  </ItemGroup>

</Project>

2 个答案:

答案 0 :(得分:1)

我认为问题来自您的<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> </packageSources> <AzureDevOpsFeed> <add key="Username" value="MyUsername" /> <add key="PAT" value="MyPatKey" /> </AzureDevOpsFeed> </configuration> PrepublishScript)。软件包BundlerMinifier.Core(版本2.9.406)具有以下依赖性:

  • dotnet bundle
  • .NETCoreApp1.0
  • .NETCoreApp2.0
  • .NETFramework4.5.2

似乎由于该项目的目标是.NETStandard2.0,所以此引用失败了,或者实际上退回到了netcoreapp2.2,或者只是给出了令人误解的信息。为了进行健全性检查,也许将项目降级为netcoreapp1.0以验证其是否有效。

仅需注意,netcoreapp2.0实现了netcoreapp2.2,所以我希望所有工作都能完成,但是推断可能在依赖关系解析期间没有发生。

答案 1 :(得分:0)

解决方案是我有一个旧版本的BundlerMinifier.Core引用- 更改即可解决问题:

<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.9.406" />

我还发现了一个错误描述:https://github.com/madskristensen/BundlerMinifier/issues/292