How do I use Visual Studio 2019 to remotely debug a .NetCore application on a Hyper-V Linux VM? - .net-core

I am attempting to remotely debug a .NetCore application in Ubuntu Linux from Visual Studio 2019 in Windows 10. I can see the remote ipaddress (ping thru command line). I can RDT to the ipaddress. I can successfully transfer files to it via WinSCP.
I created a simple .NetCore "HelloWorld" app and copied onto the Linux VM.
I used the following commands to build and publish:
dotnet build -r linux-x64
dotnet publish --self-contained -r linux-x64
I ran the following command on the Linux VM to ensure that ssh is functional:
sudo apt-get install openssh-server unzip curl
The app is running on Linux.
From VS I try to attach to the process:
I get prompted for logon:
I get the following error:
Is there a step I'm missing somewhere?
Is there a configuration/permissions issue I am unaware of?
Thanks, JohnB

Microsoft has documented debugging a Linux target from a Windows development machine at https://learn.microsoft.com/en-us/visualstudio/debugger/remote-debugging-dotnet-core-linux-with-ssh?view=vs-2022
Unfortunately, using that method, you will need to manually deploy and manually attach the debugger. If you'd like Microsoft to change that, then it would be wise to upvote this issue: https://developercommunity.visualstudio.com/t/Convenient-way-to-add-a-remote-debug-con/917516
A 3rd party developer has created a Visual Studio extension that provides this missing feature to Visual Studio. It can be downloaded from https://github.com/radutomy/VSRemoteDebugger

I had the same problem initially because I didn't enter the connection target in the first screen.
After having entered the correct target myusername#192.168.178.95 in the first screen the second screen did not show up any longer and I got the expected list of processes

Related

Bash terminal in Visual Studio dotnet not found

I have debian 11 installed in wsl2 on windows 10. I use the dotnet cli tools in visual studio and cmd windows but much prefer the linux syntax. The sdk commands are not exposed to wsl apparently as I get "bash: command dotnet not found" errors. Because WSL is essentially mapping linux commands to windows I don't think I should be installing the dotnet sdk again for linux, but can't really find any confirmation of that. Anyone here doing this who can advise? Just don't want to have to maintain two sets of the dotnet sdk if WSL does not require it.
The sdk commands are not exposed to wsl apparently as I get "bash: command dotnet not found" errors.
That's because WSL does not run Windows executables - it is, after all, a Linux subsystem.
I don't think I should be installing the dotnet sdk again for linux
You have two choices:
Use the Windows subsystem (drop WSL),
install the Linux applications you want to run.

Jetbains Rider remote debugging ASP.NET Core 6.0 apps through SSH kept failing

I am trying to remote debug via ssh on an ubuntu host at Ali with no success. I'm using the the latest Rider, 2022.1 EAP 10.
The error is:
Debugger worker was not initialized within 100,000 ms
I’m running Ubuntu 20.04 64bit on Ali Cloud. And one side note: for the following steps from Jetbrains documents, I wasn’t able to succeed:
cd /[application path]/WebApplication to go to the application root folder.
chmod +x ./WebApplication to add the executable bit if needed.
ASPNETCORE_URLS=http://0.0.0.0:5000 ./WebApplication to run the application
WebApplication is a directory, the OS kept complaining it's a directory even after chmod+x. I managed to run the self-contained executable.
It is always better to ask such questions in JetBrains public issue tracker.
This problem should already be fixed in the next Rider versions:
https://youtrack.jetbrains.com/issue/RIDER-76083

'Command not found' when running .NET Core console in Ubuntu on Windows Subsystem for Linux

I have downloaded .NET Core 3 (preview) and I have in Visual Studio 2019 (preview) created a hello world project consisting of class library and a console program. The program runs on Windows.
I have Windows Subsystem for Linux running Ubuntu 16.04 and I install dot net so that dotnet --info returns something (non error). Are there any other steps required?
If I go to my console apps binary folder and then shift+right mouse button click to get the 'Open Linux shell here' menu item and take that option then my Ubuntu window opens in the same directory as the console app executable.
From the bash prompt if I type the executable name (either with or without.exe) and of the correct casing it just reports 'Command not found'.
I am wondering what step I have missed.
The executable name is not a known command to the shell. You need dotnet <EXECUTABLENAME>

Self-contained deployment .NET Core app in Ubuntu

I wrote a test project using .NET Core and assembled the self-contained deployment for Ubuntu 16.04 as described here (see Self-contained deployment without third-party dependencies).
But when I run the app I get the following error:
An assembly specified in the application dependencies manifest (Test.deps.json) was not found:
package: 'runtime.linux-x64.Microsoft.NETCore.App', version: '2.0.0-preview2-25407-01'
path: 'runtimes/linux-x64/lib/netcoreapp2.0/Microsoft.CSharp.dll'
I am using .NET Core 2.0 Preview 2, VS2017 Preview.
I will be grateful for any help!
This is an old question, but I just ran across this when I was trying to run a .Net Core application on Linux and wanted to share the solution. If you are getting the error above, you are likely trying to execute the wrong binary. For those following along from scratch, follow these steps:
On Windows, open a command prompt in the directory of the project you want to run on Linux.
Build the project for Linux using dotnet publish -r linux-x64
I chose to target linux-x64, but you can target a specific runtime if you'd like. Runtime identifiers can be found here.
Copy the published files to the Linux workstation. Because the above command omitted the configuration flag -c, the configuration defaulted to debug. The published files will be in Debug\netcoreapp2.0\linux-x64\publish
Note: there will be binaries in Debug\netcoreapp2.0\linux-x64\ too. These are not the binaries you want to copy to your Linux workstation. If you run these binaries, you will get the error described in the OP. Copy all the files in the publish directory instead. Ignore whatever files might be in linux-x64.
On the Linux workstation, give execute permission to the binary file. My project was named ConsoleUI, so I used chmod 764 ConsoleUI
Execute the binary using ./ConsoleUI
Keep in mind that you will need to at least have the .Net Core runtime installed on your Linux workstation.

How to deploy asp.net application to docker container on Linux server?

I have installed docker engine on a Linux server. On my desktop's Visual Studio 2015, I created an asp.net application. Now I want to publish it to the Linux server and create a docker image.
I followed this step.
I don't have an azure account and I want to use my own Linux server. So next, I clicked the Docker Containers. The interface became:
Then I clicked Custom Docker Host and pressed OK button.
The interface was
Now I input the image name as DockerDemo. Also I type the server url something like tcp://12.16.45.56:8080. Validate connection is okay then go to the next step.
Finally I get this:
However I get an error during publish.
Severity Code Description Project File Line Suppression State
Error An error occured during publish.
The command [docker -H tcp://12.16.45.56:8080 build -t DockerDemo -f "C:\Users\me\AppData\Local\Temp\PublishTemp\DockerDemo63\approot\src\DockerDemo\Dockerfile" "C:\Users\me\AppData\Local\Temp\PublishTemp\DockerDemo63"] exited with code 1: 'docker' is not recognized as an internal or external command,
operable program or batch file.
Please visit http://go.microsoft.com/fwlink/?LinkID=529706 for troubleshooting guide. DockerDemo 0
By the way, the framework I am using is:
"frameworks": {
"dnx451": { },
"dnxcore50": { }
}
Thanks for help!
Visual Studio can't find the docker command on your local computer. It needs this as a client to connect to the docker daemon on your Linux server. The easiest way to do this is to install Docker Toolbox from here:
https://www.docker.com/products/docker-toolbox
You may have to uninstall and re-install "Visual Studio 2015 Tools for Docker" or manually add to Powershell's $env:Path if the docker command still can't be found.
Also, your Image Name must not contain uppercase characters. Use dockerdemo rather than DockerDemo.

Resources