MVC package not compatible

2019-07-27 15:37发布

问题:

I am trying to update my project to dotnet core 1.1. I installed the given dotnet core SDK (1.0.0-preview2-1-003177 to be exact) and created a new Core WebAPI project and I updated the package as per given in upgrade document.

error: Package Microsoft.AspNetCore.Mvc 1.1.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). 
Package Microsoft.AspNetCore.Mvc 1.1.0 supports: 
error: - net451 (.NETFramework,Version=v4.5.1) 
error: - netstandard1.6 (.NETStandard,Version=v1.6) 
error: One or more packages are incompatible with .NETCoreApp,Version=v1.1.

Here is my package.json

{

  "dependencies": {
    "Microsoft.AspNetCore.Authentication": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    }
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "gcServer": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Can anyone help me with the same?

回答1:

Already added an answer in question itself, putting it as my own answer to this question.

  1. Go to command prompt and hit this command dotnet --version
  2. Copy the sdk version
  3. Go to global.json of solution and replace version with copied version number. global.json should look like this.

global.json

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}

alternative way is to remove version completely. (Thanks @Tseng for suggestion)

Clean, rebuild and restore packages. Should work.