Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core tag helper intellisense and color coding not working

I am having issues with .NET core and tag helpers. The color coding and the intellisense are not displaying or being registered when I type in asp-for. I've tried creating a new solution in a separate instance, verified that the intellisense works, and then copied the project.json into the project that doesn't have working intellisense/color coding, and it doesn't fix the issue.

Here is my project.json

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },

    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    }
  },

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

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

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

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

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

I've also made the reference/injection in the _ViewImports file for the mvc tag helpers. This is the view where I'm testing that it works. enter image description here

And here is my project structure, just in case you can see something that I'm not seeing.

enter image description here

If it helps at all, here is the version of Visual Studio I am using.

enter image description here

like image 230
ddeamaral Avatar asked Dec 02 '16 03:12

ddeamaral


People also ask

What is the difference between tag helper vs HTML helper?

Tag Helpers are attached to HTML elements inside your Razor views and can help you write markup that is both cleaner and easier to read than the traditional HTML Helpers. HTML Helpers, on the other hand, are invoked as methods that are mixed with HTML inside your Razor views.

What happens when you apply the tag helper opt out character?

The opt-out character (“!”) is used to disable the Tag Helper at the element level. With the opt-out character, the HTML will not be generated for the label tag in the above case. We can use this opt-out character if we want to conditionally control rendering of the HTML elements.

What is Taghelper?

A Tag Helper Component is a Tag Helper that allows you to conditionally modify or add HTML elements from server-side code. This feature is available in ASP.NET Core 2.0 or later. ASP.NET Core includes two built-in Tag Helper Components: head and body . They're located in the Microsoft. AspNetCore.


2 Answers

I fixed it in two steps.

1.Install Razor tool from package manager console. It is pre-release for now

Install-Package Microsoft.AspNetCore.Razor.Tools –Pre
  1. Download and install Razor Language Services from marketplace. (Your visual studio instance should be closed)

After restart visual studio, intellisense and coloring should be working for tag helpers.

enter image description here

like image 186
Murat Seker Avatar answered Oct 26 '22 16:10

Murat Seker


This is a semi-old Q&A, but I recently solved a similar problem where tag helper intellisense and highlighting/colorization suddenly stopped working, so I post this for posterity.

I tried to repair and reinstall Visual Studio to no avail. What ultimately solved this issue follows:

  1. Close all instances of Visual Studio.

  2. Download and install the latest .NET Core SDK.

  3. Open "Apps & features" (Add or remove programs)

  4. Search for ".NET Core SDK" and uninstall all except the latest version (x64 and/or x86).

  5. Reopen Visual Studio.

like image 38
Bjørn-Roger Kringsjå Avatar answered Oct 26 '22 17:10

Bjørn-Roger Kringsjå