Solving error “Microsoft.NETCore.App 1.0.0 does no

2019-02-08 11:23发布

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

After modifying project.json, I got this error:

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.

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:

Code: NU1002 Description: The dependency Microsoft.NETCore.App 1.0.0 does not support framework .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.

How do I resolve this error?

2条回答
贼婆χ
2楼-- · 2019-02-08 12:16

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:

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

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.

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

查看更多
Anthone
3楼-- · 2019-02-08 12:26

I referenced .net core class library in .net 4.6.1 by changing the following.

Before I was getting this error when trying to reference the .net core from .net 4.6.1 enter image description here

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" ]
    }
}
查看更多
登录 后发表回答