DEV Community

loading...
Cover image for VSCode - .Net Flavored

VSCode - .Net Flavored

equiman profile image Camilo Martinez Updated on ・5 min read

VSCode without a doubt it's an amazing tool, but for me, is missing an important setting to enable/disable extensions depending on language or workspace.

Almost me, jump all day between projects in different languages and I have a lot of extensions and settings that are useless in each scenario consuming resources. You can disable it manually on each project, but if you create a new one, you gonna need to make it all again. That's a waste of time.

While the VSCode team solves that, we can use a little workaround, creating our dedicated profile for .Net development.

It's not perfect, because you can share those extensions that you use in multiples scenarios. But I prefer missing a little space on the disk in favor of fast settings configurations.

Create Profile

We are going to create a new profile folder for extensions and data using --extensions-dir and --user-data-dir parameters.

OS Command
mac code --extensions-dir "$HOME/.vscode/profiles/dotnet/extensions" --user-data-dir "$HOME/.vscode/profiles/dotnet/data"
linux code --extensions-dir "$HOME/.vscode/profiles/dotnet/extensions" --user-data-dir "$HOME/.vscode/profiles/dotnet/data"
win code --extensions-dir "%HOMEPATH%/.vscode/profiles/dotnet/extensions" --user-data-dir "%HOMEPATH%/.vscode/profiles/dotnet/data"

How to use?

Are you crazy? We need to write and memorize this long command each time we want to work with .Net?.

No, of course not.

On macOS/Linux

On this path $HOME/.vscode/profiles/dotnet/ download this image:

icon-mac

Dock Launcher

On same path, create a file called code-dotnet.command with this code inside:

open -n -a "Visual Studio Code.app" --args --extensions-dir="$HOME/.vscode/profiles/dotnet/extensions" --user-data-dir="$HOME/.vscode/profiles/dotnet/data"
Enter fullscreen mode Exit fullscreen mode

Save it and execute permission with chmod +x code-dotnet.command.

Copy the icon-dotnet.png content on the Clipboard. One way to do this is to open the picture in Preview, choose Edit > Select All, then choose Edit > Copy or press Command-C.

Select code-dotnet.command file, then choose File > Get Info. At the top of the Info window, click the picture of the icon to select it, then choose Edit > Paste or press Command-V.

Select code-dotnet.command file, then choose File > Make Alias or press Command-L name it as VSCode .Net (with blank space between). Just drag and drop this alias shortcut to your Dock or Desktop.

dock-macos

Recommended configurations: Open a terminal window, go to 'Preference > Profiles. Set Auto close terminal on exit: inside 'Shell' tab, select "Close if the shell exited cleanly" on "When the shell exits" option.

Alias

An alias can be our best friend in those cases. Open your .zshrc or .bash_profile and paste this.

alias code-dotnet="code --extensions-dir \"$HOME/.vscode/profiles/dotnet/extensions\" --user-data-dir \"$HOME/.vscode/profiles/dotnet/data\""
Enter fullscreen mode Exit fullscreen mode

Save your file and restart your terminal window. Now you can open a folder project in VSCode with code . command, but now, if you going to work with .Net use code-dotnet . instead.

On Windows

On this path %HOMEPATH%/.vscode/profiles/dotnet/extensions download this icon:

icon-win

Shortcut

On the same path, create a shortcut file and set with these properties:

Named as: VSCode .Net

Set target as:

"C:\Users\%USERNAME%\AppData\Local\Programs\Microsoft VS Code\Code.exe" --extensions-dir "%HOMEPATH%/.vscode/profiles/dotnet/extensions" --user-data-dir "%HOMEPATH%/.vscode/profiles/dotnet/data"
Enter fullscreen mode Exit fullscreen mode

Start In as :

"C:\Users\%USERNAME%\AppData\Local\Programs\Microsoft VS Code"
Enter fullscreen mode Exit fullscreen mode

And use the icon downloaded previously.

Sadly on Windows create an alias it slightly more complicated than macOS/Linux, then you only can open it using the shortcut and can't open it directly from the project path. But if you are using WSL you can use the same alias approach from mac/linux.


Colors

It will be good to recognize when are using your VSCode and your .Net flavored VSCode version.

{
    "workbench.colorCustomizations": {
        "activityBar.background": "#753ca1",
        "activityBar.foreground": "#ffffff",
        "activityBar.inactiveForeground": "#ffffff99",
        "activityBarBadge.background": "#d211fd",
        "activityBarBadge.foreground": "#ffffff",
        "statusBar.noFolderBackground": "#642596",
        "statusBar.background": "#753ca1",
        "statusBar.foreground": "#ffffff",
        "statusBarItem.hoverBackground": "#642596"
    }
}
Enter fullscreen mode Exit fullscreen mode
settings.json

vscode-dotnet


That's all. Now it's up to you what settings and extensions do you want to install. Those are my favorite recommendations.

Extensions

Editor

Debugging

Containers

REST

Testing


Settings

Specific purposes for all .Net projects.

{
    "cSpell.words": ["dotnet"],
    "editor.tabSize": 4,
    "emmet.excludeLanguages": [],
    "emmet.triggerExpansionOnTab": true,
    "emmet.includeLanguages": {
        "aspnetcorerazor": "HTML"
    },
    "search.exclude": {
        "**/obj": true,
        "**/coverage": true
    }
}
Enter fullscreen mode Exit fullscreen mode
settings.json

There are a lot of VSCode extensions out there. If you are hungry for more check my essentials extensions and configurations.


Auto Formating

Is enough with these settings.

{
    "editor.formatOnSave": true,
}
Enter fullscreen mode Exit fullscreen mode
settings.json

Sync

I'm not a big fan of the built-in VSCode Sync option because you can use more than one GitHub user account and also you can't create profiles.

But don't worry, we can use the well known Setting Sync extension.

Please create another GitHub account, adding -dotnet to your username and +dotnet to your Gmail account.

github-user

With this trick, you can have another GitHub account without creating a new email account. Just use your new username-dotnet account and voilà, your .Net flavored VSCode version can be sync across multiple devices.


That’s All Folks!
Happy Coding 🖖

Buy me a cofee

Discussion

pic
Editor guide