Mvc icon indicating copy to clipboard operation
Mvc copied to clipboard

IServiceCollection does not contain a definition for 'AddMvc'

Open brijmailid opened this issue 11 years ago • 7 comments

my project is not getting build it shows error - IServiceCollection does not contain a definition for 'AddMvc',

My Project.json file is:

{
    "webroot": "wwwroot",
    "userSecretsId": "aspnet5-WebApplication3-153c8f5d-b846-40ea-a6ca-8250c0529bab",
    "version": "1.0.0-*",

    "dependencies": {
        "EntityFramework.SqlServer": "7.0.0-beta5",
         "EntityFramework.Commands": "7.0.0-beta5",
        "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
        "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
        "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta5",
        "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta5",
        "Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
        "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
        "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta5",
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
        "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
        "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta5",
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
        "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
        "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta5",
        "Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
        "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5",
        "Microsoft.Framework.Logging": "1.0.0-beta5",
        "Microsoft.Framework.Logging.Console": "1.0.0-beta5",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta5"
    },

    "commands": {
        "web": "Microsoft.AspNet.Hosting --config hosting.ini",
        "ef": "EntityFramework.Commands"
    },

    "frameworks": {
        "dnx451": {
            "dependencies": {
                "DreamFactory": "1.0.0-*",
                "DreamFactoryCRUD.Contracts": "1.0.0-*",
                "unirest-net": "1.0.0-*"
            },
            "frameworkAssemblies": {
                "System.Web": "4.0.0.0"
            }
        }
    },

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

brijmailid avatar Nov 28 '15 05:11 brijmailid

Look at the amount of beta5 references in your project. My advice would be to create a new one using the rc1 tooling

davidfowl avatar Nov 28 '15 05:11 davidfowl

I have VS2015 Community edition, Should i install "Visual Studio 2015 Update 1 RC"

brijmailid avatar Nov 28 '15 06:11 brijmailid

Installing VS2015 Update 1 RC is optional, but you definitely want ASP.NET 5 RC 1.

Eilon avatar Nov 29 '15 02:11 Eilon

I am having the same problem.

  • ASP.NET 5 RC 1 is installed.
  • project.json:
{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": 
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}
  • global.json
{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-rc1-final"
  }
}
  • dnvm list
C:\Program Files (x86)\Microsoft Visual Studio 14.0>dnvm list

Active Version         Runtime Architecture OperatingSystem Alias
------ -------         ------- ------------ --------------- -----
       1.0.0-beta4     clr     x64          win
       1.0.0-beta4     clr     x86          win
       1.0.0-beta4     coreclr x64          win
       1.0.0-beta4     coreclr x86          win
       1.0.0-beta5     clr     x64          win
       1.0.0-beta5     clr     x86          win
       1.0.0-beta5     coreclr x64          win
       1.0.0-beta5     coreclr x86          win
       1.0.0-beta6     clr     x86          win             latest
       1.0.0-beta8     clr     x86          win
  *    1.0.0-rc1-final clr     x64          win
       1.0.0-rc1-final clr     x86          win             default
       1.0.0-rc1-final coreclr x64          win
       1.0.0-rc1-final coreclr x86          win

tmarinov avatar Dec 03 '15 22:12 tmarinov

The version for "Microsoft.AspNet.Mvc": should be "6.0.0-rc1-final"

rynowak avatar Dec 03 '15 23:12 rynowak

Finally saw a repo with the answer to this problem....it's AddMvcCore

so... never mind //////////////

I'm getting this now with the latest (?) bits on OSX. I used the startup & project.json files from current samples (in https://github.com/aspnet/Mvc/tree/dev/test/WebSites). From my nuget.config:

<packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="AspNetCiDev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" /> 
    </packageSources>
  <disabledPackageSources />
  <activePackageSource>
     <add key="AspNetCiDev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json"/> 
   </activePackageSource>

here's project.json so you don't have to go look at the samples:

{
"commands": {
"web": "TestRC2WebAPI"
},
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.0-*",
"Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.0.0-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNetCore.Session": "1.0.0-*",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*"
},
"frameworks": {
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}

Surely I'm missing something but it's been hours and I can't figure it out. Thanks

julielerman avatar Jan 31 '16 15:01 julielerman

AddMvc and AddMvcCore are different: see here

StephenLujan avatar Sep 27 '16 15:09 StephenLujan