You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中C#扩展覆盖主题语法高亮问题求助

VS Code C#扩展覆盖主题语法高亮问题解决

在VS Code中使用微软官方C#扩展(ms-dotnettools.csharp)时,主题设置的代码语法高亮会被该扩展覆盖——关闭扩展时显示正常,开启后颜色被强制替换。已关闭扩展的C#语义高亮设置,且VS Code全局语义高亮设为configureByTheme。

关闭扩展时的预期显示效果

关闭C#扩展后的正常高亮效果

using5 chars
language    csharp
standard token type Other
foreground  #009C8F
background  #E1F4F4
contrast ratio  3.00
textmate scopes keyword.other.using.cs
source.cs
foreground  keyword.other
{ "foreground": "#009C8F" }

开启扩展后的异常显示效果

开启C#扩展后的异常高亮效果

using5 chars
language    csharp
standard token type Other
foreground  #D0A00F
background  #E1F4F4
contrast ratio  2.12
semantic token type keyword
foreground  keyword.control
keyword.package.go
keyword.operator.pointer.go
keyword.control
keyword.control.conditional
storage.modifier
keyword.operator.new
keyword.operator.expression
keyword.begin.blade
keyword.end.blade
keyword.blade
keyword.type-alias
keyword.type
support.class.console
keyword.other.await
storage.type.class.jsdoc
punctuation.definition.block.tag.jsdoc
keyword.other.new
keyword.other.phpdoc
keyword.other.use.php
keyword.operator.logical.python
keyword.other.import.static.groovy
keyword.other.import.groovy
punctuation.definition.attribute.swift
source.svelte meta.scope.tag.main.svelte meta.tag.start.svelte variable.function.svelte
meta.directive.on.svelte entity.name.type.svelte
keyword.other.special-method.elixir
keyword.edge
entity.name.function.edge
support.constant.edge
keyword.other.gdscript
keyword.other.onready.gdscript
source.graphql meta.fragment.graphql keyword.on.graphql
source.graphql meta.type.interface.graphql keyword.implements.graphql
source.graphql meta.type.interface.graphql meta.type.object.graphql meta.type.list.graphql keyword.operator.nulltype.graphql
source.graphql meta.variables.graphql keyword.operator.nulltype.graphql
source.graphql meta.type.interface.graphql meta.type.object.graphql keyword.operator.nulltype.graphql
keyword.operator.class.php
keyword.operator.spread.php
keyword.operator.type.php
keyword.operator.increment-decrement.php
keyword.operator.increment-increment.php
punctuation.support.type.property-name.begin.json
punctuation.support.type.property-name.end.json
keyword.operator.string.php
keyword.operator.ternary.php
keyword.operator.variadic.php
keyword.operator.nullable-type.php
keyword.other.use-as.php
keyword.import.go
keyword.operator.address.go
keyword.operator.null-coalescing
keyword.operator.arrow
keyword.struct.go
keyword.operator.liquid
keyword.operator.optional.ts
keyword.cmake
{ "foreground": "#d0a00f" }
textmate scopes keyword.other.using.cs
source.cs
foreground  keyword.other
{ "foreground": "#009C8F" }

解决方法

  • 彻底禁用C#扩展语义高亮:打开VS Code设置,搜索C# Semantic Highlighting,将csharp.semanticHighlighting.enabled设为false,也可直接在settings.json中添加:
    "csharp.semanticHighlighting.enabled": false
    
  • 强制指定主题颜色:在settings.json中针对当前主题自定义C#文本范围的颜色,覆盖扩展样式:
    "editor.tokenColorCustomizations": {
      "[你的主题名称]": {
        "textMateRules": [
          {
            "scope": "keyword.other.using.cs",
            "settings": {
              "foreground": "#009C8F"
            }
          }
        ]
      }
    }
    
    替换[你的主题名称]为当前使用的主题名称。
  • 更新/重置扩展:将C#扩展更新至最新版本,或卸载后重新安装,排除版本缓存或bug冲突。
  • 确认全局语义高亮设置:确保editor.semanticHighlighting.enabled保持为configureByTheme:
    "editor.semanticHighlighting.enabled": "configureByTheme"
    

内容的提问来源于stack exchange,提问作者Bruno.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 03:47:11