解决错误“Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version=v4.6.1"

编程入门 行业动态 更新时间:2024-10-27 10:26:40
本文介绍了解决错误“Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version=v4.6.1"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个使用 net461 引用运行的 ASP.NET Core 1.0 完整应用程序.现在我正在尝试添加另一个框架 - netcoreapp1.0.为此,我像这样更新了我的 project.json:

I have an ASP.NET Core 1.0 complete application running using net461 references. Now I am trying to add another framework - netcoreapp1.0. For this, I have updated my project.json like this:

{
   "userSecretsId":"",
   "version":"2.4.0-*",
   "buildOptions":{
      "emitEntryPoint":true,
      "preserveCompilationContext":true
   },
   "dependencies":{
      "Microsoft.ApplicationInsights.AspNetCore":"1.0.0",
      "Microsoft.AspNetCore.Authentication.Cookies":"1.0.0",
      "Microsoft.AspNetCore.Diagnostics":"1.0.0",
      "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore":"1.0.0",
      "Microsoft.AspNetCore.Identity":"1.0.0",
      "Microsoft.AspNetCore.Identity.EntityFrameworkCore":"1.0.0",
      "Microsoft.AspNetCore.Mvc":"1.0.0",
      "Microsoft.AspNetCore.Mvc.TagHelpers":"1.0.0",
      "Microsoft.AspNetCore.Server.IISIntegration":"1.0.0",
      "Microsoft.AspNetCore.Server.Kestrel":"1.0.0",
      "Microsoft.AspNetCore.StaticFiles":"1.0.0",
      "Microsoft.EntityFrameworkCore":"1.0.0",
      "Microsoft.EntityFrameworkCore.SqlServer":"1.0.0",
      "Microsoft.Extensions.Configuration.CommandLine":"1.0.0",
      "Microsoft.Extensions.Configuration.FileExtensions":"1.0.0",
      "Microsoft.Extensions.Configuration.Json":"1.0.0",
      "Microsoft.Extensions.Configuration.UserSecrets":"1.0.0",
      "Microsoft.Extensions.Logging":"1.0.0",
      "Microsoft.Extensions.Logging.Console":"1.0.0",
      "Microsoft.Extensions.Logging.Debug":"1.0.0",
      "Microsoft.VisualStudio.Web.BrowserLink.Loader":"14.0.0",
      "Microsoft.VisualStudio.Web.CodeGenerators.Mvc":"1.0.0-preview2-final"
   },
   "tools":{
      "BundlerMinifier.Core":"2.0.238",
      "Microsoft.AspNetCore.Razor.Tools":"1.0.0-preview2-final",
      "Microsoft.AspNetCore.Server.IISIntegration.Tools":"1.0.0-preview2-final",
      "Microsoft.Extensions.SecretManager.Tools":"1.0.0-preview2-final"
   },
   "commands":{
      "ef":"EntityFramework.Commands",
      "web":"Microsoft.AspNetCore.Server.Kestrel"
   },
   "frameworks":{
      "net461":{

      },
      "netcoreapp1.0":{
         "imports":[
            "dotnet5.6",
            "portable-net45+win8"
         ]
      }
   },
   "runtimes":{
      "win10-x64":{

      },
      "win81-x64":{

      },
      "win8-x64":{

      },
      "win7-x64":{

      }
   },
   "publishOptions":{
      "exclude":[
         "**.user",
         "**.vspscc",
         "wwwroot",
         "node_modules"
      ]
   },
   "scripts":{
      "prepublish":[
         "npm install",
         "bower install",
         "gulp clean",
         "gulp min"
      ]
   }
}

修改project.json后,出现这个错误:

After modifying project.json, I got this error:

无法使以下项目可运行:MVC6_Full_Version(.NETCoreApp,Version=v1.0) 原因:未找到预期的 coreclr 库在包图中.请再次尝试运行 dotnet restore.

Failed to make the following project runnable: MVC6_Full_Version (.NETCoreApp,Version=v1.0) reason: Expected coreclr library not found in package graph. Please try running dotnet restore again.

为了解决这个问题,我运行了 dotnet restore 命令但没有成功.

To resolve this, I ran dotnet restore command but no luck.

然后,我添加了这个块:

Then, I added this block:

"Microsoft.NETCore.App": {
  "version": "1.0.0",
  "type": "platform"
},

添加这个块后,我得到了一个不同的错误:

After adding this block, I got a different error:

代码:NU1002 说明:依赖 Microsoft.NETCore.App 1.0.0不支持框架 .NETFramework,Version=v4.6.1.

Code: NU1002 Description: The dependency Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1.

基本上,我想在我的应用程序中添加两个引用 - .NET Framework 4.6.1 和 ASP.NET Core 1.0.

Basically, I want to add both references in my applications - .NET Framework 4.6.1 and ASP.NET Core 1.0.

我该如何解决这个错误?

How do I resolve this error?

推荐答案

使用 .NET Framework 或 .NET Core 构建 ASP.NET Core 项目绝对是可能的.你真的很接近 - 只需要一些调整:

It's definitely possible to build ASP.NET Core projects using .NET Framework or .NET Core. You're really close - just a few tweaks needed:

删除 runtimes 部分,除非您打算进行本机编译(有点不寻常)将 Microsoft.NETCore.App 的引用放在 dependencies 部分 inside netcoreapp1.0 部分.我已经测试了以下更改,它恢复和编译没有错误: Remove the runtimes section, unless you are intending to do native compilation (somewhat unusual) Place the reference to Microsoft.NETCore.App in a dependencies section inside the netcoreapp1.0 section. I've tested the following change and it restores and compiles without errors:

project.json

...

   "frameworks": {
      "net461": {

      },
      "netcoreapp1.0": {
         "dependencies": {
            "Microsoft.NETCore.App": {
               "type": "platform",
               "version": "1.0.0"
            }
         },
         "imports": [
            "dotnet5.6",
            "portable-net45+win8"
         ]
      }
   }

仅 .NET Core 需要 Microsoft.NETCore.App 依赖项,将其添加到此处将确保在为该框架构建时可用.

The Microsoft.NETCore.App dependency is only required for .NET Core, and adding it here will make sure it's available when building for that framework.

此外,commands 部分已被弃用,可以删除.

Also, the commands section has been deprecated and can be removed.

这篇关于解决错误“Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version=v4.6.1"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-14 15:38:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/845338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   框架   错误   NETCore   App

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!