ASP.NET Core Tag Helper Intellisense in Visual Stu

2019-02-11 21:16发布

I am unable to get Intellisense for all tags (e.g. asp-for asp-action, etc.) I'm running Visual Studio 2017.

My .csproj file includes the following packages:

<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" Type=""/>
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="1.1.0" />

and my _ViewImports.cshtml file includes the following:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Is there something I need to edit or add?

4条回答
时光不老,我们不散
2楼-- · 2019-02-11 21:49

You can add/use the tag helpers by doing the following process:

  1. Create View with the name of _ViewImports.cshtml
  2. Add the following line into it, @addTagHelper "*,Microsoft.AspNetCore.Mvc.TagHelpers"
  3. Doneenter image description here

Go check _Layout.cshtml, it will be working fine.

查看更多
迷人小祖宗
3楼-- · 2019-02-11 21:50

EDIT1:

As suggested in VS2017 known issues, workaround is now available. For this, we need to install the Razor Language Service extension. This extension provides support for ASP.NET Core Razor Tag Helpers in Visual Studio 2017.


Original:

Razor Tag Helpers do not get colorization or special IntelliSense at design time in VS2017 RC.  They work normally at runtime. No workaround available at this moment.

Refer known-issues-vs2017 for more details.

查看更多
Summer. ? 凉城
4楼-- · 2019-02-11 22:03

For VS2017 RTM (if you've upgraded by now) you need to install Razor Language Services from Extensions and Updates... in Tools menu within Visual Studio.

Caveat: It seems as if you also have to remove any Microsoft.AspNetCore.Razor.Tools reference (I had version 1.1.0-preview4-final) from your .csproj file to enable IntelliSense after installing the extension above.

查看更多
相关推荐>>
5楼-- · 2019-02-11 22:04

[Solved] In my updated Visual Studio 2017 Enterprise 26430.13 i solved my problem with disable and re-enable Razor Language Services and it's working now.

I know that's little weird. I find Razor Language Services in Extension and Update from Tools menu and Disable it and restart Visual Studio and Enable it again and restart Visual Studio again and finally everything's right.

查看更多
登录 后发表回答