Skip to content

Project discovery with UNC Paths doesn't work (and workaround) #179

Closed
@VisualMelon

Description

@VisualMelon

VS Code 1.30.2, Windows 10

Project discovery doesn't work with UNC file paths. It seems this is a consequence of issues with node-glob and executing via child_process, because it uses a shell, and cmd dislikes UNC paths.

If the workspace has a UNC path, and you set the testProjectPath setting to something (e.g. "*/*.csproj"), then it fails, with node-glob returning nothing. Stuffing some code into TestDirectories.parseTestDirectories to change how it handles UNC resolves this issue. The next problem comes in testDiscovery.js, function executeDotnetTest, which tries to pass this UNC path to child_process.exec as the working directory; it seems that the working directoy is not ultimately set (I think this is CMD's fault), as the dotnet process complains it can't find a project (MSB1003), even when one exists (and compiles, etc. same code on a non-UNC path works).

I can't find much information about child_process support for UNC, but it seems that exec runs in a shell, and the shell (CMD) is swallowing the UNC path before defaulting to C:\Windows. It seems this can be worked around by calling through powershell (alternatively, the csproj could be detected manually and full address provided). This issue of course applies to all calls that go through Executor.exec.

The workaround is as follows, making 2 changes to files in formulahendry.dotnet-test-explorer-0.6.1\out\src.

Code to fix UNC in TestDirectories.cs (might have side-effects I've not noticed):

let isUnc = globPattern.startsWith("\\\\");
if (isUnc)
{
    const partialPaths = glob.sync(testDirectoryGlob, {cwd: folder.uri.fsPath});
    const matchingDirsForWorkspaceFolder = partialPaths.map(x => folder.uri.fsPath + "/" + x);
    
    matchingDirs.push(...matchingDirsForWorkspaceFolder);
    logger_1.Logger.Log(`Found ${matchingDirsForWorkspaceFolder.length} matches for pattern in folder ${folder.uri.fsPath}`);
}
else
{
    const matchingDirsForWorkspaceFolder = glob.sync(globPattern);
    
    matchingDirs.push(...matchingDirsForWorkspaceFolder);
    logger_1.Logger.Log(`Found ${matchingDirsForWorkspaceFolder.length} matches for pattern in folder ${folder.uri.fsPath}`);
}

Escaping the quotes and passing commands through powershell in executor.js seems to make everything work thereafter:

command = command.replace(/\"/g, "\\\"");
command = `powershell -command "cd '${cwd}'; ${command} | ft"`;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions