visual-studio-codeterminal.net-core-3.1vscode-tasks

how to run a pre-configured command when new terminal is created in vs code for only opened folder


Actually the problem I'm having right now is same as Process terminated. Couldn't find a valid ICU package installed on the system in Asp.Net Core 3 - Ubuntu.

To solve this, I need to run export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 command whenever I open a new terminal in VS Code. But I don't want this to happen all Linux session but only for specific project.

So far, I've tried launch.json and tasks.json config files. But I couldn't succeeded. If I run dotnet --version I'm getting the same error from another stackoverflow questions as I provided link above.

Can you help for this.

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "core31_invariant",
                "command": "export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1",
                "type": "shell",
                "args": [],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }

Solution

  • I've figured out. It was all about setting env. variable in settings.json inside the project folder

    Note: This is for only if you especially want to do it for per project not every folder you open by VS Code. If you want to make it available for all folders are opened in VS Code, you need to add it this setting to global file not local.

    Actually, you can run any command by adding following settings in your settings.json

        {
            "terminal.integrated.profiles.linux": {
                "BashWithStartup": {
                    "path": "bash",
                    "args": ["--init-file", "./pre_config.sh"]
                }
            },
            "terminal.integrated.defaultProfile.linux": "BashWithStartup"
        }
    

    and then you need to write the commands in your ./pre_config.sh file. But for some reason this doesn't work for me.

    So I've found another way to get around thanks to Nathan Almeida who asked question How to run a bash command or set env variables when VSCode open a workspace

    There is a terminal.integrated.env.linux setting in VS Code which you can pass the all variables those you want to make it available for every terminal you open in that particular folder/project you open in VS Code.

    To do that add following option in your settings.json file like this:

        {
            "terminal.integrated.env.linux": {
                "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT": "1"
            }
        }