Visual Studio 2017 uses SSH to debug. NET Core and SSH on Linux
Visual Studio 2017 uses SSH to debug the. NET Core application on Linux.
Environment
Development Environment: Win10 x64 Visual Studio 2017
Deployment environment: Ubuntu 14.04x64. NET Core SDK 1.0.1
Install. NET Core SDK on Ubuntu
Ubuntu 14.04x64
sudo sh -c 'echo "deb [arch = amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main"> /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver hkp: //keyserver.ubuntu.com: 80 --recv-keys 417A0893
sudo apt-get update
If you have installed the preview version before, be sure to update it.
Then install the latest version of SDK 1.0.1
sudo apt-get install dotnet-dev-1.0.1
After the installation is complete, execute dotnet --info as follows:
The SDK installation is successful.
Then on the Linux server, you need to install the SSH server, unzip and curl or wget. The command is as follows:
sudo apt-get install openssh-server unzip curl
After the installation is complete, everything is ready.
New program
Open VS 2017 and create a new console application .NET Core named: LinuxDemo.
Add the following code to Program.cs:
class Program
{
static void Main (string [] args)
{
Console.WriteLine ("Hello World! LineZero");
Console.WriteLine ("Linux .NET Core Debug");
Console.WriteLine ("'q' exit");
while (true)
{
var result = Console.ReadLine ();
if (result.Equals ("q"))
return;
Console.WriteLine (result);
}
}
}
After writing the code, upload the code to Ubuntu.
Then run the program on Ubuntu and execute it successfully.
dotnet restore
dotnet build
dotnet run
Additional debugging
Then run the program by default, then open it in VS 2017 Debug-> Attach to Process
Select the connection type as SSH, and then enter the Ubuntu IP at the connection and destination, and then press Enter. A dialogue will pop up and enter the corresponding username and password.
Configuration:
Additional process:
select type:
Then wait for a while, enter a few characters in Linux, and press Enter to break:
note:
If you find that you cannot disconnect after attaching, stop debugging, restart VS, then exit the program, re-run and attach. Just try a few more times.
If you think this article is helpful to you, please click "Recommended", thank you.