Syntax highlighting and intellisense not working .

2019-07-26 09:30发布

I am trying to work on a .net core project and syntax highlighting is not functioning properly for razor views. Is there a dev dependency or configuration property that I am missing. Intellisense is also not working properly for asp-* tags. Any suggestions? I've already tried deleting the ComponentModelCache in appdata.

enter image description here

Here is my project.json so you can see what packages I'm using. It seems to be project setup related, most likely a package. I am importing the tag helpers in my _ViewImports.cshtml file. I'm just not sure what's different in this project compared to default .NET Core projects. This project was started with an empty web core project.

{
  "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%" ]
  }
}

2条回答
ゆ 、 Hurt°
2楼-- · 2019-07-26 10:03

After hours of trying different packages and searching forums and issue threads, I gave this package a shot Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final and this seemed to do the trick. All the syntax highlighting seemed to take effect once I referenced this package.

查看更多
仙女界的扛把子
3楼-- · 2019-07-26 10:14

Do you have Resharper installed? It seems there's a problem with it and .NET Core syntax highlighting and intellisense.

http://blog.jetbrains.com/dotnet/2016/05/27/resharper-ultimate-2016-2-eap-kicks-off/

Initial support of ASP.NET Core 1.0 RC2, including support for tag helpers in terms of code completion, navigation, search and refactorings. At this point, ASP.NET Core web applications are supported if they’re targeting .NET Framework but are not supported if they’re targeting .NET Core. We’re looking to improve this in subsequent builds.

So if you have a library targeting .netstandard1.5 Resharper will not correctly display intellisense information but the project will compile.

However if you add the .netcoreapp1.0 framework as an additional framework to the project.json file Resharper will work and you get full intellisense support.

 frameworks": {
    "netstandard1.5": {
      "imports": [ "dnxcore50", "portable-net45+win8" ],
      "dependencies": {
        "NETStandard.Library": "1.5.0-rc2-24027",

        "System.Security.Principal": "4.0.1-rc2-24027"
      }
    },
    ".netcoreapp1.0": {
      "imports": [ "dnxcore50", "portable-net45+win8" ]
    }
 },

How to fix intellisense with referenced netstandard1.5 library projects in Visual Studio 2015?

查看更多
登录 后发表回答