fnm icon indicating copy to clipboard operation
fnm copied to clipboard

fnm is not working in Visual Studio Task Runner

Open jsalwen opened this issue 1 year ago • 4 comments

I am using VS 2019 and VS 2022. FNM is working correctly in PowerShell, cmd shell and bash on my Windows OS.

But I cannot get it to work in the VS 2019 / 2022 Task Runner.

  • note: This is not in VS Code, this is in Visual Studio
  • note: Task Runner was added to VS to allow it to run gulpfile.js for builds.

I am trying to figure out how to get Task Runner to work with fnm. Any suggestions are appreciated.

jsalwen avatar Nov 13 '24 18:11 jsalwen

Hi! Can you please share what Task Runner is? I’m not a VSCode user either ;D

Schniz avatar Nov 13 '24 19:11 Schniz

Hi! Can you please share what Task Runner is? I’m not a VSCode user either ;D

It's basically a custom shortcut in vscode to speed up things like building, testing, running code, etc

e.g.:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "echo hello",
      "type": "shell",
      "command": "echo",
      "args": ["Hello, World!"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": []
    }
  ]
}

Then you can do: "Run task"> "echo hello" and it will execute the code in a new terminal inside the ide

https://code.visualstudio.com/docs/editor/tasks

FabriBorgobello avatar Nov 18 '24 10:11 FabriBorgobello

I have this issue too. It might be happening in VSCode too, but Visual Studio Task runner is in Visual Studio and not in VSCode.

From what I can tell. The issue is that the profile.cmd solution documented in the README is not working when running commands from Visual Studio MSBuild tasks.

For example, I have the following profile.cmd and it works when I start cmd.exe.

@echo off
:: for /F will launch a new instance of cmd so we create a guard to prevent an infnite loop
if not defined FNM_AUTORUN_GUARD (
    set "FNM_AUTORUN_GUARD=AutorunGuard"
    FOR /f "tokens=*" %%z IN ('fnm env --use-on-cd') DO CALL %%z
)

However, when I build my dotnet project, this echo command does not include the changes fnm makes to the path and thus node, npm, and npx cannot be found.

  <Target Name="NSwag" BeforeTargets="Build" Condition="'$(Configuration)' == 'Debug'">
    <Exec Command="echo %PATH%" />
    <Exec Command="node --version"/>
    <Exec Command="npm install [email protected] --global" />
    <Exec Command="npx nswag run ../redacted.nswag" />
  </Target>

If I manually add C:\Users\MZawisa\AppData\Local\fnm_multishells\11236_1752008604096 to my path, will that cause any problems with fnm in other contexts. Looks like there are many aliases set up and they are different for git-bash, so I'll make sure it gets added to the end of my path and not the beginning. Or would it be better to add C:\Users\MZawisa\AppData\Roaming\fnm\aliases\default to the end of my path?

maxrzaw avatar Jul 08 '25 21:07 maxrzaw

I tested out adding %USERPROFILE%\AppData\Roaming\fnm\aliases\default to my PATH environment variable in the Windows Control Panel and it seems to have solved the problem. I'll report back if I find any side effects of this solution.

maxrzaw avatar Jul 08 '25 21:07 maxrzaw