简体   繁体   English

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

[英]Solving error “Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1”

I have an ASP.NET Core 1.0 complete application running using net461 references. 我有一个使用net461引用运行的ASP.NET Core 1.0完整应用程序。 Now I am trying to add another framework - netcoreapp1.0 . 现在我想添加另一个框架netcoreapp1.0 For this, I have updated my project.json like this: 为此,我更新了我的project.json,如下所示:

{
   "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"
      ]
   }
}

After modifying project.json, I got this error: 修改project.json后,我收到此错误:

Failed to make the following project runnable: MVC6_Full_Version (.NETCoreApp,Version=v1.0) reason: Expected coreclr library not found in package graph. 无法使以下项目可运行:MVC6_Full_Version(.NETCoreApp,Version = v1.0)原因:在包图中找不到预期的coreclr库。 Please try running dotnet restore again. 请尝试再次运行dotnet restore。

To resolve this, I ran dotnet restore command but no luck. 要解决这个问题,我运行了dotnet restore命令,但没有运气。

Then, I added this block: 然后,我添加了这个块:

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

After adding this block, I got a different error: 添加此块后,我得到一个不同的错误:

Code: NU1002 Description: The dependency Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1. 代码:NU1002描述:依赖Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version = v4.6.1。

Basically, I want to add both references in my applications - .NET Framework 4.6.1 and ASP.NET Core 1.0. 基本上,我想在我的应用程序中添加两个引用 - .NET Framework 4.6.1和ASP.NET Core 1.0。

How do I resolve this error? 我该如何解决这个错误?

It's definitely possible to build ASP.NET Core projects using .NET Framework or .NET Core. 使用.NET Framework或.NET Core构建ASP.NET Core项目绝对是可能的。 You're really close - just a few tweaks needed: 你真的很接近 - 只需要一些调整:

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

project.json project.json

...

   "frameworks": {
      "net461": {

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

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. Microsoft.NETCore.App .NETCore.App依赖关系仅对.NET Core是必需的,在此处添加它将确保在为该框架构建时可用。

Also, the commands section has been deprecated and can be removed. 此外, commands部分已被弃用,可以删除。

I referenced .net core class library in .net 4.6.1 by changing the following. 我通过更改以下内容引用.net 4.6.1中的.net核心类库。

Before I was getting this error when trying to reference the .net core from .net 4.6.1 在尝试从.net 4.6.1引用.net核心时出现此错误之前 在此输入图像描述

Fix: 固定:

Original 原版的

    {
    "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Interop.SHDocVw.dll": "1.1.0",
    "Microsoft.mshtml.dll": "7.0.3300.1"
    },

    "frameworks": {
    //"net461": {},
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8",
        "net461"
      ]
    }
   },

    "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ]
    }
   }

Corrected 更正

    {
     "dependencies": {
        "Interop.SHDocVw.dll": "1.1.0",
        "Microsoft.mshtml.dll": "7.0.3300.1"
     },

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

    "scripts": {
        "prepublish": [ "bower install", "dotnet bundle" ]
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复`您的项目未引用“.NETFramework,Version=v4.6.1”框架...` - How to fix `Your project does not reference ".NETFramework,Version=v4.6.1" framework...` 找到框架“Microsoft.NETCore.App”,版本“5”时找不到 Microsoft.NETCore.App 5.0.0 - The framework 'Microsoft.NETCore.App', version '5' was not found while Microsoft.NETCore.App 5.0.0 is found 已使用 '.NETFramework,Version=v4.6.1' 而不是项目目标框架 ' 恢复 - was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework ' 如何解决/解决异常未找到框架“ .NETFramework,Version = v4.6.1”的参考程序集? - How should I fix/resolve exception The reference assemblies for framework “.NETFramework,Version=v4.6.1” were not found? 带有 .net framework 4.6.1 的 Asp.net Core 2.0 - 找不到参考程序集 '.NETFramework/v4.6.1/Microsoft.CSharp.dll - Asp.net Core 2.0 with .net framework 4.6.1 - Cannot find reference assembly '.NETFramework/v4.6.1/Microsoft.CSharp.dll 使用 Docker .NET 核心映像构建 WinForms C# 应用程序导致错误:.NETFramework,Version=v4.6.1 were not found - Building a WinForms C# application with Docker .NET Core image results to an error : .NETFramework,Version=v4.6.1 were not found 找不到Azure devops构建失败的NETFramework,Version = v4.6.1“ - Azure devops build failed NETFramework,Version=v4.6.1" were not found 使用'.NETFramework,Version = v4.6.1'而不是项目目标框架'.NETCoreApp,Version = v2.0'恢复了软件包'Faker.Net 1.0.3' - Package 'Faker.Net 1.0.3' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0' NETSDK1061:该项目已使用 Microsoft.NETCore.App 版本 1.0.0 恢复,但使用当前设置,将改用版本 2.0.9 - NETSDK1061: The project was restored using Microsoft.NETCore.App version 1.0.0, but with current settings, version 2.0.9 would be used instead Mac - 找不到框架“Microsoft.NETCore.App”,版本“3.1.0”(x64) - Mac - The framework 'Microsoft.NETCore.App', version '3.1.0' (x64) was not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM