Skip to content

vscode launch file absolute path workaround? #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adamfk opened this issue Jan 13, 2023 · 5 comments · Fixed by #753
Closed

vscode launch file absolute path workaround? #697

adamfk opened this issue Jan 13, 2023 · 5 comments · Fixed by #753
Labels

Comments

@adamfk
Copy link

adamfk commented Jan 13, 2023

dotnet-script is really, really cool! The only (minor) problem for me is the fixed file path in the .vscode/launch.json file.

Is there any chance that the vscode dotnet script launch configuration could be improved to not use a user specific absolute path?

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Script Debug",
            "type": "coreclr",
            "request": "launch",
            "program": "dotnet",
            "args": [
                "exec",
                "C:/Users/my_username/.dotnet/tools/.store/dotnet-script/1.4.0/dotnet-script/1.4.0/tools/net6.0/any/dotnet-script.dll",
                "${file}"
            ],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false
        }
    ]
}

I often share .vscode/launch.json files (with multiple configurations) for tutorials. It would be really helpful if the person downloading the tutorial could just run it (like a standard c# project) without having to adjust the launch file. The user can't run dotnet script init to set the path correctly because there is an existing launch file.

I spent a while trying to get around this by using vscode variable references, but I think the best I would be able to do is create a custom vscode extension that would just return the correct dotnet script path.

Maybe the dotnet command could be improved in the future to know the path to dotnet-script.dll?

Any other ideas?

Thanks! c# script files are pretty awesome!

@filipw
Copy link
Member

filipw commented Feb 8, 2023

We generate a better launch.json file when we detect that dotnet-script is installed as a global tool. Then it avoids the absolute paths:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Script Debug",
      "type": "coreclr",
      "request": "launch",
      "program": "${env:HOME}/.dotnet/tools/dotnet-script",
      "args": ["${file}"],
      "windows": {
        "program": "${env:USERPROFILE}/.dotnet/tools/dotnet-script.exe",
      },
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
    }
  ]
}

Is it an option for you to use it as global tool?

@filipw filipw added the question label Feb 8, 2023
@filipw
Copy link
Member

filipw commented Feb 8, 2023

Actually.. looks like your path is really a global tool paths, so maybe the scaffolder has some detection bug. However, you can try the launch.json I posted, and if you have a global tool installed it should be enough.

@adamfk
Copy link
Author

adamfk commented Feb 8, 2023

Thanks!!! ❤️ That is so much better than what I had been doing 😝 https://github.com/StateSmith/example-drawio-1/blob/bd8fb84bfc81e1339712c6129b87fc5361198a15/.vscode/launch.json#L21

@adamfk adamfk closed this as completed Feb 8, 2023
@adamfk
Copy link
Author

adamfk commented May 4, 2024

The behavior seems OS specific (Linux generates the good launch.json). Using dotnet-script version 1.5.0 for both windows and WSL2 creates different init results. Both installed globally.

windows (not ideal because of absolute path):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Script Debug",
            "type": "coreclr",
            "request": "launch",
            "program": "dotnet",
            "args": [
                "exec",
                "C:/Users/user/.dotnet/tools/.store/dotnet-script/1.5.0/dotnet-script/1.5.0/tools/net8.0/any/dotnet-script.dll",
                "${file}"
            ],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false
        }
    ]
}

WSL2 (good!):

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Script Debug",
      "type": "coreclr",
      "request": "launch",
      "program": "${env:HOME}/.dotnet/tools/dotnet-script",
      "args": ["${file}"],
      "windows": {
        "program": "${env:USERPROFILE}/.dotnet/tools/dotnet-script.exe",
      },
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
    }
  ]
}

Is it worth re-opening the issue to address at some point in the future?

@filipw
Copy link
Member

filipw commented May 6, 2024

Thanks for reporting this - this should fix it #753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants