dotnet / dotnet/vscode-csharp

Slight code update to enable the use to dotNet portable binaries with custom folder path in VSCode.

Open
#5,694 0 comments 1 reaction 0 assignees View on GitHub
OmniSharp
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
18h 40m
Merged PRs (30d)
31

Description

## Environment data
`dotnet --info` output: not relevent
VS Code version: 1.78.2
C# Extension version: 1.25.7

## OmniSharp log
not required

## Steps to reproduce
1. Add the following values in setting.json
```json
{
"omnisharp.useModernNet": true,
"omnisharp.dotNetCliPaths": [
"D:\\Test Project\\dotnet"
]
}
```
2. Restart OmniSharp

## Expected behavior
By pointing the ``dotNetCliPaths`` to the folder containing `dontnet.exe` , OmniSharp should run the server using the pointed `dotnet.exe`.

## Actual behavior
In actual case, this does not happen. Due to the space present in the `Test Project` folder name, the shell cannot execute the `--info` command to retrieve the data, as `--info` breaks due to the space.

Gives error as
```
'D:\\Test' is not recognized as an internal or external command,
operable program or batch file.
```

## Additional context
To successfully execute the command to retrieve the `--info` slight modification is required in the code.
Modification is to be done in `src\utils\getDotnetInfo.ts` file on `line 21`.
Old Code:
```javascript
const data = await execChildProcess(`${dotnetExecutablePath ?? 'dotnet'} --info`, process.cwd(), process.env);

```
Suggested code:
```javascript
const validInfoCommand = dotnetExecutablePath === undefined ? `dotnet --info` : `"${dotnetExecutablePath}" --info`;
const data = await execChildProcess(validInfoCommand, process.cwd(), process.env);

````
Reason:
If the value in `dotNetCliPaths` is pointed to the values with spaces in between, the resulting `--info` command will evaluate to :
```bash
D:\\Test Project\\dotnet\\dotnet.exe --info
```
and will fail (error given above).

When the code is updated, the resulting `--info` command will evaluate to:
```bash
"D:\\Test Project\\dotnet\\dotnet.exe" --info.
```
with double quotes in the path and will successfully retrieve the required data.

## Exception
This issue does not occur when there is no space (`"D:\\Test-Project\\dotnet"`) between the folder name and works fine.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.