Formatting Razor Files in Visual Studio Code

Anyone have a good solution for formatting Razor files inside VSCode? I tried to get it to work with prettify-vscode and decorate. But in both cases, it cannot detect cshtml files. I do not want to change my razor to html as I will lose a lot of razors.

+12
source share
2 answers

You can represent them as HTML files (File → Preferences → Preferences) without any third-party extensions:

{
  "editor.formatOnSave": true,
  "emmet.includeLanguages": {
    "razor": "html"
  },
  "files.associations": {
    "*.cshtml": "html"
  }
}

Update: v1.17.0 C# for Visual Studio Codeadd-on; C# for Visual Studio Codeadded preview of Razor Language Service (cshtml) with support for improvements and C # diagnostics.

+19
source

, : changeLanguageMode.change

js, html cshtml:

 {
    "key":"ctrl+k j", 
    "command":"changeLanguageMode.change", 
    "args": {
        "languageId":"javascript"
    }
},  
{
    "key":"ctrl+k h", 
    "command":"changeLanguageMode.change", 
    "args": {
        "languageId":"html"
    }
},  
{
    "key":"ctrl+k k", 
    "command":"changeLanguageMode.change", 
    "args": {
        "languageId":"aspnetcorerazor"
    }
}

keybindings.json :

CTRL + SHIFT + P " Preferences: Open Keyboard Shortcuts File Preferences: Open Keyboard Shortcuts File.

Ctrl + K, Ctrl + F .

0

Source: https://habr.com/ru/post/1692124/


All Articles