Visual Studio 2017 uses SSH to debug. NET Core and SSH on Linux

Source: Internet
Author: User
Tags ssh server

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.