dotnet Core Learning (iii): Multi-Project

Source: Internet
Author: User
Tags dotnet

The process of program development is basically composed of multiple projects to form a complete solution. Learn how to do multi-project development in visual Studio code today.

1. Project Creation

First create a folder multiproject similar to the solution folder in Visual Studio.

Create Dotnetcoreapp and Dotnetcorelib folders separately in Multiproject.

Here Dotnetcoreapp for a console application project, Dotnetcorelib for the class library project to be referenced. The relevant commands are as follows:

Create folder Multiproject:

mkdir Multiproject

Create Project: Dotnetcoreapp:

New -T Console

Create Project: Dotnetcorelib:

New -T Lib

2. Project References

Open the Multiproject folder by using Visual Studio code, as shown in:

Open the Project.json file under the Dotnetcoreapp folder and add a reference to the Dotnetcorelib project.

{  "version":"1.0.0-*",  "buildoptions": {    "Debugtype":"Portable",    "Emitentrypoint":true  },  "Dependencies": {},  "Frameworks": {    "netcoreapp1.1": {      "Dependencies": {        "Microsoft.NETCore.App": {          "type":"Platform",          "version":"1.1.0"        },        "Dotnetcorelib": {"target": "Project"        }      },      "Imports":"Dnxcore50"    }  }}

Modify the namespace name in the Dotnetcorelib project to Dotnetcorelib, add the Libray class in the Dotnetcorelib project, and new Method1 method:

using System; namespace dotnetcorelib{    publicclass  libray    {         public  String  Method1 ()        {                return"Hello dotnetcoreapp" ;        }    }}

In Dotnetcoreapp reference and invoke the Method1 method in the Dotnetcorelib class library:

using System; using Dotnetcorelib; namespace consoleapplication{    publicclass  program    {        public Static void Main (string[] args)        {            library lib=new   Library ();            Console.WriteLine (Lib. Method1 ());            Console.ReadLine ();     }}}

3. Multi-Project Commissioning

Debugging a single project with visual Studio Code 1.7.2 basically without having to modify any of the configurations, and multi-project debugging is a little cumbersome.

First select Debug environment. Net Core, generate Launc.json, as shown in:

The target platform and project names in Visual Studio Code 1.7.2 are now automatically populated, but for multiple projects or as before

So we need to change the place as follows:

"configurations": [        {            "name":". NET Core Launch (console)",            "type":"coreclr",            "Request":"Launch",            "Prelaunchtask":"Build",            " Program":"${workspaceroot}/bin/debug/netcoreapp1.1/dotnetcoreapp.dll ",            "args": [],            "CWD":"${workspaceroot}",            "Stopatentry":false,            "Externalconsole":false        },

After configuring Launch.json, clicking the Debug button prompts us to "Configure the task to run the program" as shown in:

Click on "Configure Tasks to run the program" and the selection will appear, of course we choose. Net Core. As shown

Next the Task.json file is generated and then the "Debug" button is clicked again, which appears as an error: Prelaunchtask "Build" terminated with exit code 1.

This is where we need to focus on multi-project commissioning, where we need to make the following modifications to the Task.json file:

{    // Seehttps://go.microsoft.com/fwlink/?LinkId=733558    //For the documentation about the Tasks.json format    "version":"0.1.0",    "Command":"dotnet",    "Isshellcommand":true,    "args": [],    "Tasks": [        {            "TaskName":"Build",            "args": [                 "${workspaceroot}/dotnetcoreapp/project.json"            ],            "Isbuildcommand":true,            "Showoutput":"Silent",            "Problemmatcher":"$msCompile"        }    ]}

The Project.json path for our main project is configured here.

After the configuration is complete, when we click the "Debug" button again, the discovery still cannot pass, the error is as follows:

This error is very obvious, and once again we make the following changes to Launch.json:

"configurations": [        {            "name":". NET Core Launch (console)",            "type":"coreclr",            "Request":"Launch",            "Prelaunchtask":"Build",            " Program":"${workspaceroot}/dotnetcoreapp/bin/debug/netcoreapp1.1/dotnetcoreapp.dll",            "args": [],            "CWD":"${workspaceroot}",            "Stopatentry":false,            "Externalconsole":false        },

It's OK to get here and start debugging again. Started successfully.

dotnet Core Learning (iii): Multi-Project

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.