Visual Studio .net核心标记助手不起作用 [英] Visual Studio .net core tag helpers not working

查看:82
本文介绍了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...

导入以下行:-

@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核心标记助手不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆