.NET Core dotnet 命令大全

命令目录:

dotnet-new

dotnet-restore

dotnet-run

dotnet-build

dotnet-test

dotnet-pack

dotnet-publish

 

现在来详细讲解。

创建(dotnet new)

首先我们创建一个项目 ,这里我们创建控制台程序。

dotnet new

点击查看原图

 

dotnet 更多命令请参考帮助。

 

还原(dotnet restore 及 dotnet pack)

我们在创建一个 class lib  也就是类库。

dotnet new -t lib

点击查看原图

创建好以后,编写一些自己的代码然后进行打包。

点击查看原图

 

我编写了两个方法,现在来打包。

dotnet restore

dotnet pack

点击查看原图

.NET Core 怎样添加离线引用包呢?现在答案就揭晓了。

打包好以后,我们将applib 添加到 app的 project.json 。

点击查看原图

添加好以后切到app 目录,然后进行还原。

还原使用的命令是:dotnet restore -f E:\dotnet\applib\bin\Debug\

dotnet restore -f 包的路径

点击查看原图

这样我们就能直接在项目里调用applib 里面的方法。

我们在代码里编写对应的调用,然后执行程序。可以看到正确输出class lib 的结果。

点击查看原图

 

运行(dotnet build 及 dotnet run)

以app 为例:

dotnet build 编译代码

点击查看原图

 

dotnet run 执行程序

点击查看原图

 

dotnet xx.dll 也是执行程序

点击查看原图

 

测试(dotnet test)

这里我们要新建一个文件夹及项目了。

新建测试项目: dotnet new -t xunittest 

点击查看原图

 

新建好项目我们可以在里面添加测试方法,这里我直接运行测试。

dotnet restore

dotnet test

点击查看原图

 

发布(dotnet publish)

重点来了,发布项目使其可以跨平台运行。

dotnet publish 默认发布

点击查看原图

发布后定位到publish目录使用 dotnet xx.dll 执行应用。

 

下面来跨平台发布。

可以参考我之前的文章:http://www.cnblogs.com/linezero/p/5475246.html

在 project.json 加入 runtimes 节点 注释掉 "type": "platform"

点击查看原图

首先我们要dotnet restore

这里我还原的时候有些久,大家耐心等待一下。

dotnet publish -r win10-x64

点击查看原图

这里发布后,可以直接定位到发布publish目录,执行 app.exe 即可。 

dotnet publish -r ubuntu.14.04-x64

点击查看原图

将publish 文件夹上传至linux系统 ,设置app的权限为可执行,然后 ./app 就可以运行了。

dotnet publish -r 指定runtimes节点里系统ID

 

.

转自: http://www.cnblogs.com/linezero/p/dotnet.html

参考: https://docs.microsoft.com/en-us/dotnet/articles/core/tools/index

此条目发表在.net分类目录。将固定链接加入收藏夹。