microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.46k stars 822 forks source link

[WSL 2] The hostname could not be parsed. (Unable to load .csproj from inside WSL) #4308

Closed rasolo closed 9 months ago

rasolo commented 5 years ago

Build number: Microsoft Windows [Version 10.0.18932.1000]

Added .NET Framework projects inside the WSL file system per the recommendation for increased speed. Opened the solutions in Visual Studio 2019. Projects does not load. I have mapped my Ubuntu.18.04 to a network drive.

The projects in the solution does not load. They should load.

Error message: error : The project file could not be loaded. Invalid URI: The hostname could not be parsed. \wsl$\Ubuntu-18.04\home\rasolo\dev{project}/.csproj.

Someone else opened an identical issue in the VSCode repo here but for .NET Core: https://github.com/OmniSharp/omnisharp-vscode/issues/3099

rasolo commented 5 years ago

This problem is solved in build version: Microsoft Windows [Version 10.0.18936.1000]

rasolo commented 5 years ago

It works for a Web forms project but not for ASP.NET web project.

rasolo commented 5 years ago

If I open the .sln without mapped network drive, I will receive the "The hostname could not be parsed." error. If I map the network drive, Visual Studio can not find WSL

rasolo commented 5 years ago

"Workaround": Map WSL to Network drive and then open the solution file with JetBrains Rider. BUT it is excruciatingly slow to restore nuget packages and compile so it is not really worth it.

craigloewen-msft commented 5 years ago

I was able to reproduce this issue, we're tracking it! Thanks for filing.

tebeco commented 5 years ago

Not sure i'm competent enought here, the workaround is to map the drive from wsl to windows ? or the other way ?

I would very much love to know if/how i can do that so i would be able to add it to the ~/.zshrc (if it's on wsl side)

rasolo commented 5 years ago

Not sure i'm competent enought here, the workaround is to map the drive from wsl to windows ? or the other way ?

I would very much love to know if/how i can do that so i would be able to add it to the ~/.zshrc (if it's on wsl side)

What I did was this: Open WSL interface. Write cd and enter (to go to root) Explorer.exe to open folder in file explorer. Click on Wsl in file explorer Right click the Ubuntu folder and click "Map to network drive".

This made it possible to open the project in Jetbrains Rider IDE but it took like 20 minutes for Rider to compile so it doesn't really work to use it like that, hence "workaround"

tebeco commented 5 years ago

@rasolo wow thx a lot i feel dumb now i though it was on the linux side ;)

i ended up doing the other way around i forgot i could just use the tar package , following zip install for linux

mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-2.2.401-linux-x64.tar.gz -C $HOME/dotnet
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet

then update my .zshrc with

export PATH=$PATH:$HOME/dotnet
export DOTNET_ROOT=$HOME/dotnet
rasolo commented 5 years ago

I was able to reproduce this issue, we're tracking it! Thanks for filing.

Hi Craig, @craigloewen-msft Do you know the progress of this? Do you know an ETA for when this will work?

Thanks

craigloewen-msft commented 5 years ago

Currently the Visual Studio team is investigating how they can enable Visual Studio to open project files inside of the Linux root file system in WSL, I'm not aware of an ETA yet.

In the meantime, using VSCode with the Remote Extension may go a long way to resolving this problem for you.

summatix commented 4 years ago

By mapping the network drive I am able to open the project inside Visual Studio. Building is slow, as expected, but otherwise everything else seems functional.

TheLordDrake commented 4 years ago

Is there any new information on this issue? Or a link to a public issue for the Visual Studio team?

drwatson85 commented 4 years ago

I found a nice workaround:

Create a soft symlink to the target directory e.g.: mklink /D D:\shareLink \wsl$\etc

Then create a symlink junction to the soft symlink: mklink /J D:\junctionLink D:\shareLink

You can now open D:\junctionLink\etc in VS and it should load everything as usual. Speed should be fine aswell. @rasolo @TheLordDrake @summatix Let me know if it works for you.

tebeco commented 4 years ago

would this official extension work ? https://marketplace.visualstudio.com/items?itemName=ms-azuretools.Dot-Net-Core-Debugging-With-Wsl2

It's a preview one, but I suppose that will somehow be the target

josemojena commented 4 years ago

October 2020, I still unable to load projects from WSl2, with the latest VS version and the .NET Core Debugging with WSL 2 extension installed too, any hint or help would be appreciated. image

rawrspace commented 3 years ago

@tebeco's workaround works as a temporary solution for me

tebeco commented 3 years ago

which msg are you referring to as a workaround ?

the remote dev pack is the official set of extensions for docker / ssh / wsl etc... it's not supposed to be a workaround ^^

rawrspace commented 3 years ago

My mistake I tagged the wrong user, I meant to reference @drwatson85's symlink solution.

I wanted my repos to be located on the linux filesystem but still be able to open them in visual studio. That solution worked for me for now.

I am still having issues running Azure Functions this way but at least I can have all my source code in one places and still use Visual Studio when VS Code is not enough.

tebeco commented 3 years ago

@rawrspace @josemojena @drwatson85 @summatix

image

Vs 2019 16.9 Preview 5 ==> .Net Core Debugging in WSL 2

(thx @andreandersen / @jcotton42 for pointing that up)

rawrspace commented 3 years ago

I installed vs 2019 16.9 preview 5 but when opening a project that is on the linux filesystem I still receive an error when opening a database .sqlproj file:

image

It looks like opening a normal console .csproj worked though but when trying to run it I got: image

Are you not seeing these issues?

tebeco commented 3 years ago

edit: loading from windows partion works fine

Try closing VS, open the installer / run a repair

chrsmrtn- commented 3 years ago

I recently came across this issue. I tried to use the drive mapping workaround like @drwatson85 mentioned. This issue went away; however, I started encountering other issues. Odd issues.

The visual studio IDE compiler was not keeping up with my changes. Like i'll add a public property on a class and i was unable to reference that property in another file. It was saying the property didn't exist. I was able to do a compile just fine though.

Also the "Errors" window would not update when there was a valid compilation error. I removed a public static from a static class and it was properly failing the build, but the errors was not showing anything. I had to look at the output to see what was hte issue.

And finally, while debugging a unit test it would complain that the source was modified and i could either stop the debug or edit. I didn't make any changes to the source file at all, and git was not detecting any code changes either.

These issues are in regards to Visual Studio 2019 Professional, version Version 16.10.0. Also these oddities were appeaing in our unit test project which had project references to the main code. The unit test project is using:

drwatson85 commented 3 years ago

I ran into this problem aswell. Seems like Visual Studio and some other applications have problems noticing file changes inside the WSL file system. Many times i had to reopen files for the changes to appear. I had to go back to purely Windows and ditch WSL2 for now, because of too many issues.

setaskin commented 2 years ago

Hi, any progress on this ? @craigloewen-msft

pha377 commented 2 years ago

From: https://docs.microsoft.com/en-us/windows/wsl/setup/environment

For example, when storing your WSL project files:

Use the Linux file system root directory: \wsl$\\home\\Project Not the Windows file system root directory: C:\Users\\Project or /mnt/c/Users//Project$

@craigloewen-msft

the "use de linux file system root directory" isn't working

craigloewen-msft commented 2 years ago

Please check the instructions at this docs page to see how to debug .NET apps with Visual Studio and WSL: https://docs.microsoft.com/en-us/visualstudio/debugger/debug-dotnet-core-in-wsl-2?view=vs-2022

And here's also the guide for C++.

Does using this guide help unblock you??

chrsmrtn- commented 2 years ago

I too am having this issue. The article describes how to debug code running in WSL. What I am looking to do (not sure if pha377 is doing the same thing) is to run the IDE in windows, debug the code running in windows, but just use the files in WSL file system. So my project files and source are all in WSL 2.

AmadeusW commented 2 years ago

Are you able to use Visual Studio when opening your project from \\wsl.localhost\ instead of \\wsl$\? It seems that \\wsl.localhost\ is available in Windows 11 with wsl2.

The issues that you are running into might be related to the fact that \\wsl$\ is not a valid URI due to the dollar sign, and a bunch of VS features internally uses URIs to identify files.

microsoft-github-policy-service[bot] commented 9 months ago

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!