【问题标题】:Identity does not exist in the namespace 'Microsoft.AspNetCore'命名空间“Microsoft.AspNetCore”中不存在标识
【发布时间】:2016-07-24 15:15:14
【问题描述】:

我正在尝试从 MVC6 beta (6.0.0-rc1-final) 升级到最新的 ASP.NET Core 1.0.0

我设法使用 asp.net 文档帮助升级了我的应用程序。

但是现在,当我使用 CTRL+F5 运行我的应用程序时,它给了我 /Views/_ViewImports.cshtml 文件的错误-

"命名空间中不存在类型或命名空间名称'Identity' 'Microsoft.AspNetCore'"

Complete error snap here

下面是我的 global.json-

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

package.json

{
  "name": "Apex",
  "version": "2.4.0",
  "devDependencies": {
    "gulp": "3.8.11",
    "gulp-concat": "2.5.2",
    "gulp-cssmin": "0.1.7",
    "gulp-uglify": "1.2.0",
    "rimraf": "2.2.8",
    "gulp-sass": "2.1.1",
    "node-sass": "3.4.2"
  }
}

appsettings.json

{
  "ApplicationInsights": {
    "InstrumentationKey": ""
  },
  "Data": {
    "DefaultConnection": {
      "ConnectionString": ""
    }
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Verbose",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

项目.json

{
  "userSecretsId": "",

  "buildOptions": {
    "emitEntryPoint": 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": {
    "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": {}
  },

  "publishOptions": {
    "exclude": [
      "**.user",
      "**.vspscc",
      "wwwroot",
      "node_modules"
    ]
  },

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

_ViewImports.cshtml

@using MVC6_Full_Version
@using MVC6_Full_Version.Models
@using MVC6_Full_Version.ViewModels.Account
@using MVC6_Full_Version.ViewModels.Manage
@using Microsoft.AspNetCore.Identity

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration

如果您在上面看到我的 _ViewImports.cshtml 文件,它具有 Identity 命名空间。

请指导我如何解决此运行时错误。

我的环境是-VS2015社区版和ASP.NET core1.0和.NET framework 4.6.1

提前致谢。

【问题讨论】:

  • 你跑dotnet restore了吗?
  • 是的......但没有运气!我可以在参考资料中看到 Microsoft.AspNetCore.Identity,并且我的项目正在成功构建。

标签: asp.net-core asp.net-core-mvc asp.net-core-1.0


【解决方案1】:

尝试在您的project.json 中添加"preserveCompilationContext": true

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

看看这是否有帮助。


编辑:

preserveCompilationContext 在使用 Razor 或任何其他类型的运行时编译时是必需的。没有它,Razor 视图的运行时编译将失败。

更多信息请参考this link

【讨论】:

  • 我会试试的。但这意味着什么?
  • 有人知道如何在 VS 2017 .csproj 中设置这个吗?
猜你喜欢
  • 2018-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 2011-10-11
  • 2011-10-19
  • 2023-04-02
相关资源
最近更新 更多