Visual studio 2017 debugs Linux via SSH NET Core

Time:2022-1-6

Visual studio 2017 debugs Linux via SSH Net core application.

Article environment

Development environment: win10 x64 visual studio 2017

Deployment environment: Ubuntu 14.04 x64 NET Core SDK 1.0.1

Install on Ubuntu NET Core SDK

Ubuntu 14.04 x64


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 installation, execute dotnet — info as follows:

Indicates that the SDK was successfully installed.

Next, on the Linux server, you need to install ssh server, unzip and curl or WGet. The command is as follows:


sudo apt-get install openssh-server unzip curl

After installation, everything is ready.

New program

Open vs 2017 and create a new console application Net core Name: linuxdemo.

In program CS add the following code:


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 startup program by default, and then open debugging – > attach to process in vs 2017

Select SSH as the connection type, then enter the Ubuntu IP at the connection and target, and press enter. A dialogue will pop up and enter the corresponding user name and password.

to configure:

Attach process:

Select type:

Then wait, enter a few characters in Linux, and press enter to break:

be careful:

If it is found that the attachment cannot be disconnected, stop debugging, restart vs, then exit the program and rerun the attachment. Just try a few more times.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.

Recommended Today

Why is reids fast

1. What is redis? Redis is completely open source and complies with the BSD protocol. It is a high-performance key value database. Redis is also one of the most popular NoSQL databases at present. It contains a variety of data structures, supports network, is memory based, and has an optional key value pair storage database […]