本练习要使用Visual studio code完成一个包含多个项目的解决方案,包括类库和Web项目。结合Visual Studio Code和.NET Core CLI,创建项目结构如下:

piedpiper

└── src

├── piedpiper.domain

├── piedpiper.sln

├── piedpiper.tests

└── piedpiper.website

任务1:创建解决方案

首先,我们将创建我们的解决方案(.sln)文件,我一直都喜欢在顶级源文件夹中创建解决方案文件D:\WorkTest\piedpiper, 打开Visual Studio Code的集成终端,

PS D:\WorkTest\piedpiper> cd src

PS D:\WorkTest\piedpiper\src> dotnet new sln -n piedpiper

这将创建一个sln名为的新文件piedpiper.sln。

接下来,我们使用dotnet new <projecttype>命令中的output参数在特定文件夹中创建一个项目:

PS D:\WorkTest\piedpiper\src> dotnet new mvc -o piedpiper.website

已成功创建模板“ASP.NET Core Web App (Model-View-Controller)”。

这将在同一目录中的piedpiper.website文件夹中创建一个ASP.NET Core MVC应用程序。如果我们目前看到我们的文件夹结构,它看起来像这样:

接下来我们可以为我们的域名和测试项目做同样的事情:

PS D:\WorkTest\piedpiper\src> dotnet new classlib -o piedpiper.domain

PS D:\WorkTest\piedpiper\src> dotnet new xunit -o piedpiper.tests

任务2:将项目添加到我们的解决方案中

在这一点上,我们有一个没有引用项目的解决方案文件,我们可以通过调用list命令来验证这一点:

PS D:\WorkTest\piedpiper\src> dotnet sln list

未在解决方案中找到项目。

接下来我们将我们的项目添加到我们的解决方案文件,我们很容易在Visual Studio 2017中打开解决方案,然后手动添加对每个项目的引用。Visual Studio Code也可以通过.NET Core CLI完成。

现在开始使用以下命令添加每个项目,我们通过引用.csproj文件来执行此操作:

PS D:\WorkTest\piedpiper\src> dotnet sln add piedpiper.website/piedpiper.website.csproj

PS D:\WorkTest\piedpiper\src> dotnet sln add piedpiper.domain/piedpiper.domain.csproj

PS D:\WorkTest\piedpiper\src> dotnet sln add piedpiper.tests/piedpiper.tests.csproj

注意:如果您使用的是基于Linux / Unix的shell,您可以使用globbing模式在单个命令中执行此操作!

dotnet sln add **/*.csproj

现在,当我们调用list我们的解决方案文件时,我们应该得到以下输出:

S D:\WorkTest\piedpiper\src> dotnet sln list

项目引用

----

piedpiper.website\piedpiper.website.csproj

piedpiper.domain\piedpiper.domain.csproj

piedpiper.tests\piedpiper.tests.csproj

任务3:向项目添加项目引用

接下来,我们要开始向我们的项目添加项目引用,通过dotnet add reference命令将我们的域库链接到我们的网站和单元测试库:

PS D:\WorkTest\piedpiper\src> dotnet add piedpiper.tests reference piedpiper.domain/piedpiper.domain.csproj

已将引用“..\piedpiper.domain\piedpiper.domain.csproj”添加到项目。

现在,如果要查看测试项目的内容,我们将看到我们的domain 已被引用:

PS D:\WorkTest\piedpiper\src> cd .\piedpiper.tests\

PS D:\WorkTest\piedpiper\src\piedpiper.tests> cat .\piedpiper.tests.csproj

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>

<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>

</PropertyGroup>

<ItemGroup>

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />

<PackageReference Include="xunit" Version="2.2.0" />

<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />

</ItemGroup>

<ItemGroup>

<ProjectReference Include="..\piedpiper.domain\piedpiper.domain.csproj" />

</ItemGroup>

</Project>

接下来,我们将为我们的网站项目做同样的事情,所以让我们去我们的网站文件夹并运行相同的命令:

dotnet add piedpiper.website reference piedpiper.domain/piedpiper.domain.csproj

如果我们返回到我们的根源文件夹并运行build命令,我们应该看到所有的构建成功:

PS D:\WorkTest\piedpiper\src> dotnet build

用于 .NET Core 的 Microsoft (R) 生成引擎版本 15.3.409.57025

版权所有(C) Microsoft Corporation。保留所有权利。

piedpiper.domain -> D:\WorkTest\piedpiper\src\piedpiper.domain\bin\Debug\netstandard2.0\piedpiper.domain.dll

piedpiper.tests -> D:\WorkTest\piedpiper\src\piedpiper.tests\bin\Debug\netcoreapp2.0\piedpiper.tests.dll

piedpiper.website -> D:\WorkTest\piedpiper\src\piedpiper.website\bin\Debug\netcoreapp2.0\piedpiper.website.dll

已成功生成。

0 个警告

0 个错误

任务4:将NuGet包添加到项目或更新它

假设我们要将NuGet包添加到我们的一个项目中,我们可以使用该add package命令来执行此操作。

首先导航到要添加NuGet软件包的项目:

PS D:\WorkTest\piedpiper\src> cd .\piedpiper.tests\

PS D:\WorkTest\piedpiper\src\piedpiper.tests> dotnet add package shouldly

Writing C:\Users\dell\AppData\Local\Temp\tmp68E4.tmp

info : Adding PackageReference for package 'shouldly' into project 'D:\WorkTest\piedpiper\src\piedpiper.tests\piedpiper.tests.csproj'.

log : Restoring packages for D:\WorkTest\piedpiper\src\piedpiper.tests\piedpiper.tests.csproj...

info : GET https://api.nuget.org/v3-flatcontainer/shouldly/index.json

info : OK https://api.nuget.org/v3-flatcontainer/shouldly/index.json 512ms

info : GET https://api.nuget.org/v3-flatcontainer/shouldly/2.8.3/shouldly.2.8.3.nupkg

info : OK https://api.nuget.org/v3-flatcontainer/shouldly/2.8.3/shouldly.2.8.3.nupkg 84ms

log : Installing Shouldly 2.8.3.

info : Package 'shouldly' is compatible with all the specified frameworks in project 'D:\WorkTest\piedpiper\src\piedpiper.tests\piedpiper.tests.csproj'.

info : PackageReference for package 'shouldly' version '2.8.3' added to file 'D:\WorkTest\piedpiper\src\piedpiper.tests\piedpiper.tests.csproj'.

或者,我们可以使用版本参数指定要安装的版本:

dotnet add package shouldly -v 2.8.3

更新NuGet包

将NuGet软件包更新到最新版本也是一样简单,只需使用相同的命令而不使用版本参数:

dotnet add package shouldly

VS Code 管理 .NET Core解决方案的更多相关文章

  1. 【实验手册】使用Visual Studio Code 开发.NET Core应用程序

    .NET Core with Visual Studio Code 目录 概述... 2 先决条件... 2 练习1: 安装和配置.NET Core以及Visual Studio Code 扩展... ...

  2. 使用Visual Studio Code开发.NET Core看这篇就够了

    作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9926078.html 在本文中,我将带着大家一步一步的通过图文的形式来演示如何在Visual Studi ...

  3. 如何使用 VS Code开发.NET Core应用程序

    Visual Studio Code(VS Code)是Microsoft为Windows,Linux和Mac操作系统开发的免费,跨平台,轻量级的源代码编辑器,它是源代码编辑器,而Visual Stu ...

  4. VS Code调试.NET Core

    VS Code调试.NET Core应用遇到的坑 为什么会有”坑“ 博客园里有好多介绍怎么使用VS Code以及调试.NET Core的文章,但是都是基于直接构建Asp.Net Core Mvc单项目 ...

  5. 轻松掌握VS Code开发.Net Core及创建Xunit单元测试

    前言 本篇文章主要还是介绍使用 VS Code 进行.Net Core开发和常用 CLI命令的使用,至于为啥要用VS Code ,因为它是真的是好看又好用 :) ,哈哈,主要还是为了跨平台开发做准备. ...

  6. mac os 下 vs code 开发 .net core

    1.软件下载 .net core 2.0 sdk: vs code 最新版: 2.用 dotnet 命令行 dotnet cli 创建项目 打开终端,创建这次项目的文件夹,mkdir Demo1: c ...

  7. 在windows下使用visual studio code建立.NET Core console程序

    开发环境准备 下载vs code,.NET Core sdk: https://www.microsoft.com/net/core#windowscmd 目前最新版为code 1.8.1,.NET ...

  8. 使用VS Code 开发.NET Core 应用程序 部署到Linux 跨平台

    使用VS Code 开发.NET Core 应用程序 部署到Linux 跨平台. 前面讲解了VSCode开发调试 .NET Core.都只是在windows下运行. .NET Core真正的核心是跨平 ...

  9. Maven-008-Nexus 私服部署发布报错 Failed to deploy artifacts: Failed to transfer file: ... Return code is: 4XX, ReasonPhrase: ... 解决方案

    我在部署构件至 maven nexus 私服时,有时会出现 Failed to deploy artifacts: Failed to transfer file: ... Return code i ...

随机推荐

  1. PI SQL 语句

    insert [piarchive]..[picomp2](tag,time,value) values('ppnie_test','t',100) INSERT into pipoint..clas ...

  2. react实现多行文本超出加省略号

    http://www.css88.com/archives/5206 overflow : hidden; text-overflow: ellipsis; display: -webkit-box; ...

  3. ABBYY FineReader 12使用教程

    说到OCR图文识别软件,自然少不了ABBYY FineReader 12.ABBYY FineReader 12可快速方便地将扫描纸质文档.PDF文件和数码相机的图像转换成可编辑.可搜索的文本.我们已 ...

  4. c __cplusplus详解

    Code:#ifdef __cplusplusextern "C" { #endif ... #ifdef __cplusplus} #endif 解释:1.c++中定义了__cp ...

  5. PullToRefreshListView 应用讲解

    转载于http://blog.csdn.net/mmjiajia132/article/details/40397813 PullToRefreshListView 用法和ListView 没有什么区 ...

  6. redis aof和rdb区别

    转自https://blog.csdn.net/m0_38110132/article/details/76906422 1.前言 最近在项目中使用到Redis做缓存,方便多个业务进程之间共享数据.由 ...

  7. 【react】---styled-components的基本使用---【巷子】

    一.官网地址 https://www.styled-components.com/ 二.styled-components 1.styled-components 样式化组件,主要作用是它可以编写实际 ...

  8. Android源码服务专家(申明:来源于网络)

    Android源码服务专家(申明:来源于网络) 地址:http://www.javaapk.com/topics/demo/page/20/

  9. python金融与量化分析----Jupyter Notebook使用

    Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言.在本文中,我们将介绍 Jupyter notebook 的主要特性,以 ...

  10. ASP.NET Core 的Windows和IIS宿主(自动翻译记录)

    https://docs.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x 支持的操作系统 以下操作系统的支持: Win ...