Visual Studio .net 核心标签助手不起作用

Visual Studio .net core tag helpers not working(Visual Studio .net 核心标签助手不起作用)

本文介绍了Visual Studio .net 核心标签助手不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,让我们开始吧.我正在使用 Visual Studio 2015 和 ASP.NET 核心标签助手已经完全停止工作,不知道为什么,因为我没有改变任何东西.有一天我在工作,他们工作得很好,然后我第二天就来了,现在根本没有 ASP.NET 核心 Web 项目显示任何标签助手!?!我尝试创建一个全新的 ASP.NET 核心 mvc 项目,但它们也不在那里工作!!!我完全被卡住了,是否有一些设置可以在 Visual Studio 中完全关闭它们?

Well, lets get down to it. I'm using Visual Studio 2015 and ASP.NET core tag helpers have completely stopped working, no idea why as I've not changed anything. I was in work one day, they worked fine, then I came in the next day and now no ASP.NET core web project at all shows any tag helpers!?! I've tried creating a fresh new ASP.NET core mvc project and they don't work there either!!! I'm completely stuck, is there some setting somewhere that completely turns them off in Visual Studio?

请注意,根据大多数其他帖子,我已经检查了通常导致此问题的所有内容.我的 _ViewImports 有一行:-

Note that I've checked everything that usually causes this problem according to most other posts. My _ViewImports has the line:-

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

这是一个完整的 project.json 文件,来自我刚刚创建的一个新项目,并且根本没有进行任何更改:-

and here is a complete project.json file from a fresh project I just created and made NO changes to at all:-

{
  "dependencies": {
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
  },

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

  "frameworks": {
    "net452": { }
  },

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

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

此外,所有 _Layout 视图和其他视图都完全失去了以前出现的突出显示.到目前为止我在互联网上没有找到其他人似乎有这个问题,不认为其他人有任何想法吗?

Also, all the _Layout views and other views have completely lost their highlighting that used to appear. No one else I've found on the internet so far seems to be having this problem, don't suppose anyone else has any ideas?

以下答案之一已经解决了新解决方案中的新项目的问题,但我仍然遇到现有解决方案/项目的问题.这是这些现有项目之一的项目文件内容,希望有人能在这里发现一些东西......

One of the answers below has solved this for new projects in a new solution but I'm still having problems with existing solutions/projects. Here's the project file contents from one of these existing projects, hopefully someone can spot something here...

{
  "dependencies": {
    "BundlerMinifier.Core": "2.2.306",
    "Configuration.Web": "1.0.0-*",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.1.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "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.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools":  "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "net452": {
      "dependencies": {
        "Aristotle.Service": {
          "target": "project"
        },
        "Infrastructure": {
          "target": "project"
        }
      }
    }
  },

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

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

我已将所有使用 NuGet 的软件包更新到最新版本...

I've updated all packages using NuGet to latest versions...

推荐答案

我终于解决了这个问题,但不知道为什么修复工作或为什么它停止工作,但是......

I've finally fixed this, but have no idea why the fixed works or why it stopped working in the first place but...

在 _ViewImports 中的行是:-

in _ViewImports the line which is:-

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

我已更改为包含引号:-

I've changed to include quotes:-

@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"

然后我进行了重建并再次工作!?!所有的asp-"属性现在也像以前一样突出显示.为什么?!?诶?!?

Then I did a rebuild and its working again!?! All the 'asp-' attributes are also now highlighted as they were before. Why?!? Eh?!?

更奇怪的是,如果我删除引号并重建,它仍然有效!好吧,至少在我的同事将文件从源代码控制中取出之前,他们必须重新加上引号!

Stranger still, if I remove the quotes and rebuild, it still works! Well, at least until my colleagues get the file out of source control, they have to put the quotes back in!!

找出那个...

这篇关于Visual Studio .net 核心标签助手不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Visual Studio .net 核心标签助手不起作用

基础教程推荐