【先定一个小目标】dotnet core 命令详解
本篇博客来了解一下dotnet这个神奇的命令。我会依次对dotnet,dotnet new,dotnet restore,dotnet build,dotnet test,dotnet run,dotnet pack,dotnet publish这些个命令的用法做个简单的介绍以及演示。
1、基本的信息命令
dotnet命令主要是用来查看一些基本的信息,如平台、版本号等。经常会用到的参数有–version,–info,–help,下面依次运行下看看输出
dotnet –version
1.0.-preview2-
dotnet –info
.NET Command Line Tools (1.0.-preview2-) Product Information:
Version: 1.0.-preview2-
Commit SHA- hash: 1e9d529bc5 Runtime Environment:
OS Name: Mac OS X
OS Version: 10.11
OS Platform: Darwin
RID: osx.10.11-x64
dotnet –help
.NET Command Line Tools (1.0.-preview2-)
Usage: dotnet [host-options] [command] [arguments] [common-options] Arguments:
[command] The command to execute
[arguments] Arguments to pass to the command
[host-options] Options specific to dotnet (host)
[common-options] Options common to all commands Common options:
-v|–verbose Enable verbose output
-h|–help Show help Host options (passed before the command):
-v|–verbose Enable verbose output
–version Display .NET CLI Version Number
–info Display .NET CLI Info Common Commands:
new Initialize a basic .NET project
restore Restore dependencies specified in the .NET project
build Builds a .NET project
publish Publishes a .NET project for deployment (including the runtime)
run Compiles and immediately executes a .NET project
test Runs unit tests using the test runner specified in the project
pack Creates a NuGet package
2、dotnet new
dotnet new命令用来创建一个.net core项目,该命令包含两个选项,分别是-t(或–type)和-l(或-lang),用来指定项目类型和编程语言。
-l, –lang [C#|F#]
-l的默认值是c#,也可以设置为f#。VB的话应该很快就能支持了。
-t, –type [console|web|lib|xunittest]
-t的默认值是concole,控制台项目。其它几个参数分别代表web项目,类库项目和测试项目。例如:dotnet new命令会创建一个控制台项目,dotnet new -t web会创建一个web项目(asp.NET mvc)。
3、dotnet restore
dotnet restore [–source] [–packages] [–disable-parallel] [–fallbacksource] [–configfile] [–verbosity] []
dotnet restore命令通过NuGet来下载定义在project.json文件中的依赖,然后放到用户目录下的.nuget/packages文件夹中。默认情况下,下载依赖组建的过程是并行进行的。
–packages选项可以指定存放已下载组件的位置,默认是用户目录下的.nuget/packages文件夹。
–disable-parallel选项用来禁用并行下载。
–configfile选项用来指定使用哪个NuGet.config文件。
dotnet restore命令运行完毕后,会生成project.lock.json文件。
4、dotnet build
dotnet build [–output] [–build-base-path] [–framework] [–configuration] [–runtime] [–version-suffix]
[–build-profile] [–no-incremental] [–no-dependencies] []
dotnet build命令将项目中的所有源代码文件和依赖的组件编译为二进制的dll文件。该命令会读取project.lock.json,如果项目中找不到该文件,则需要先运行dotnet restore命令。
执行完dotnet build命令后,会在bin/Debug/netcoreapp1.0文件夹下生成.dll文件和.pbd文件等,例如:
bash-3.2$ ls -al bin/Debug/netcoreapp1./
total
drwxr-xr-x jingjing staff : .
drwxr-xr-x jingjing staff : ..
-rw-r–r–@ jingjing staff : .DS_Store
-rwxr–r– jingjing staff : app.deps.json
-rwxr–r– jingjing staff : app.dll
-rwxr–r– jingjing staff : app.pdb
-rwxr–r– jingjing staff : app.runtimeconfig.dev.json
-rwxr–r– jingjing staff : app.runtimeconfig.json
-rwxr–r– jingjing staff : library.dll
-rwxr–r– jingjing staff : library.pdb
drwxr-xr-x jingjing staff : publish
5、dotnet test
dotnet test [–configuration] [–output] [–build-base-path] [–framework] [–runtime] [–no-build] [–parentProcessId]
[–port] []
dotnet test命令用来运行单元测试项目中的测试代码,单元测试项目需要依赖一个单元测试框架(如nunit或xunit)以及对应的单元测试运行器,单元测试运行器在project.json文件中通过testRunner节点来指定。下面是一个使用xunit作为单元测试框架的项目的project.json文件
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable"
},
"dependencies": {
"System.Runtime.Serialization.Primitives": "4.1.1",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-192208-24"
},
"testRunner": "xunit",
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
}
}
其中,”testRunner”: “xunit”指明了需要的单元测试运行器。
6、dotnet run
dotnet run [–framework] [–configuration] [–project] [–help] [–]
dotnet run命令是一个比较便捷的运行代码的命令。它会编译代码,输出信息,并运行代码。
7、dotnet pack
dotnet pack [–output] [–no-build] [–build-base-path] [–configuration] [–version-suffix] []
dotnet pack命令编译代码并生成一个NuGet包,具体来说就是在bin\Debug目录下生成一个.nupkg文件和一个.symbols.nupkg文件。
8、dotnet publish
dotnet publish [–framework] [–runtime] [–build-base-path] [–output] [–version-suffix] [–configuration] []
dotnet publish命令会编译代码,然后读取project.json文件中定义的所有依赖组件,最后将这些东西输出到一个文件夹中。生成的文件默认会输出到\bin\Debug\netcoreapp1.0\publish中,你可以通过-o或–output选项来修改输出位置。当你需要发布你的代码时,该命令的输出文件将是你所需要的全部文件。
【先定一个小目标】dotnet core 命令详解的更多相关文章
- 先定一个小目标,自己封装个ajax
你是否发现项目中有很多页面只用到了框架不到十分之一的内容,还引了压缩后还有70多kb的jquery库 你是否发现项目中就用了两三个underscore提供的方法,其他大部分的你方法你甚至从来没有看过 ...
- 先定一个小目标:10天自学C语言编程,教你如何改变一生
C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...
- 【先定一个小目标】Asp.net Core 在IIS上的托管运行
1.安装 .NET Core Framework 下载.net core地址:官网地址 2.Install IIS 在控制面板->程序与功能->Internet Infomation Se ...
- 【先定一个小目标】怎么解决mysql不允许远程连接的错误
最近使用Navicat for MySQl访问远程mysql数据库,出现报错,显示“1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to ...
- 【先定一个小目标】windows下安装RabbitMQ消息服务器
RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public License开源协议. 1:安装RabbitMQ 需要先安装Erlang语言开发包.下载地址 ...
- 【先定一个小目标】Windows下安装MongoDB 3.2
1.MongoDB 安装 官网提供了三个版本下载: - MongoDB for Windows 64-bit 适合 64 位的 Windows Server 2008 R2, Windows 7 , ...
- 【先定一个小目标】在Windows下的安装Elasticsearch
ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用Java开发的,并作为Apach ...
- 【先定一个小目标】Windows下Redis的安装使用
Redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...
- 【先定一个小目标】Ubuntu 16.04 搭建 zookeeper
ZooKeeper 是 Apache 的一个顶级项目,为分布式应用提供高效.高可用的分布式协调服务,提供了诸如数据发布/订阅.负载均衡.命名服务.分布式协调/通知和分布式锁等分布式基础服务.由于 Zo ...
随机推荐
- OCR简介及使用
OCR (Optical Character Recognition,光学字符识别)是指电子设备(例如扫描仪或数码相机)检查纸上打印的字符,通过检测暗.亮的模式确定其形状,然后用字符识别方法将形状翻译 ...
- 同步定制 Unity团队 程序的C#文件模板
孙广东 2015.7.30 就是把程序制定好的模板(不论什么人能够更改并同步git)放到,unity项目的Editor 目录下, 当程序新建一个C#脚本后就是这个模板了. "81-C# ...
- jsp导出身份证到excel时候格式不正确
今天早上客户跟我说excel导出身份证的时候显示有的对有的不对,我一看原来身份证以X结尾的能够,其他都显示不对.身份正显示如图所看到的: 在网上搜了一下发现,原来excel看你数字列超过12位就会显示 ...
- request.getAttribute()与request.setAttribute()
request.getAttribute()与request.setAttribute() request.getAttribute("nameOfObj")可得到JSP页面一表单 ...
- 求出全部的正整数对 使他们最大公约数为n,最小公倍数为m
题目大概是这种:cid=1021&pid=5http://" target="_blank">点击打开链接 大意就是 求出全部的正整数对 使他们最大公约数为 ...
- Cocos2d-x 3.2 Lua演示样例CurrentLanguageTest(当前语言环境)
Cocos2d-x 3.2 Lua演示样例CurrentLanguageTest(当前语言环境) 转载请注明:IT_xiao小巫 本篇博客介绍Cocos2d-x 3.2给我们提供的一个样例.获取当前程 ...
- docker大全集
1,什么是docker docker 最初是dotCloud公司创始人 Solomon Hykes 在法国期间发起的一个公司内部醒目,于 2013年 3 月以 Apache 2.0 授权协议开源, 主 ...
- 设置Table边框的CSS
<!DOCTYPE html> <html> <head> <style> table, td, th { border: 1px solid blac ...
- leetcode 659. Split Array into Consecutive Subsequences
You are given an integer array sorted in ascending order (may contain duplicates), you need to split ...
- codeforces 688D D. Remainders Game(中国剩余定理)
题目链接: D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input stan ...