Tag Helpers disabled in VS 2015

妖精的绣舞 提交于 2019-12-19 19:56:16

问题


I am having trouble getting Tag Helpers enabled in my project.

Here is a summary of the project setup:

  • VS 2015 RC Community Edition.
  • Project.json reference: Microsoft.AspNet.Mvc": "6.0.0-beta4
  • _GlobalImport.chtml has @addTagHelper"*,Microsoft.AspNet.Mvc.TagHelpers"

No build errors or warnings.

Must missing something, but I don't know what.

UPDATE:

Seems I am part of the way there. I added @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" to the _ViewStart.chtml. Razor is now processing things like <a asp-controller="Home" asp-action="Summary" title="Manage">TEST</a> as a link with a proper href attribute. However intellisense on not working.


回答1:


1) In your project.json dependencies, make sure you have these 3:

"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
  "version": "1.0.0-preview2-final",
  "type": "build"
},

2) In your project.json tools, make sure you have:

"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final"

3) In Your Views\_ViewImports.cshtml, make sure you have:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Then rebuild the project and you should be good to go. (If not try restarting VS.)




回答2:


After much back and forth I got the intellisense working.

As mentioned in the question update, I needed to add @addTagHelper "Microsoft.AspNet.Mvc.TagHelpers"

Finally, I looked at the NuGet page for tag helpers. I noticed some listed dependencies were not in my project. I added those, restarted VS, and got some intellisense.




回答3:


Try to add dependency "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5" to your project.json.

That fixed a similar issue for me.




回答4:


In my case I needed to deactivate the IntelliSense of ReSharper (9.2) which overrides the TagHelpers.

See: https://stackoverflow.com/a/40630217/909980



来源:https://stackoverflow.com/questions/30965430/tag-helpers-disabled-in-vs-2015

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!