Let's go

.NET Core命令行

一、

使用cmd或者Windows PowerShell进行输入命令的方式

1、dotnet - info  -- 查看dotnet信息

2、dotnet --version  -- 查看版本

3、dotnet new global.json --sdk-version 3.1.200  -- 切换版本

 

 

dotnet new   查看项目

dotnet new --list --type project

dotnet new --list --type item

dotnet new --list --type other  -- 其他

 

dotnet new console --name HelloWrold 创建项目

ls -- 查看目录

dotnet new console -o HelloWrold01  -- o  输出目录

 

 

 

 

 dotnet new console -n HelloWrold01 -o Demo   -- 输入文件Demo

 

 

 

 tab  自动补全

if (!(Test-Path -Path $PROFILE)) {New-Item -ItemType File -Path $PROFILE -Force}

 

notepad $PROFILE

 

Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
     param($commandName, $wordToComplete, $cursorPosition)
         dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
         }
 }

 

 

 创建解决方案

dotnet new sln -o Demo   -- 在刚刚创建的Demo目录下创建解决方案;没有Demo会默认创建一个Demo文件

 

dotnet new classlib -o Demo.Core  -- 创建Demo.Core类库

 

 dotnet new console -o Demo.Main  -- 创建一个Demo.Main控制台应用

 

 

上面创建的不在一个文件下

cd Demo

dotnet new classlib -o Demo.Core  -- 创建Demo.Core类库

dotnet new console -o Demo.Main  -- 创建一个Demo.Main控制台应用

 dotnet sln list  -- 查看解决方案里有没有项目

 

 将上面两类库(Demo.Core 、Demo.Main)加入到解决方案中;建立关系。

dotnet sln add Demo.Core Demo.Main

 

装了vscode

code Demo  -- 进入代码

dotnet sln remove Demo.Core Demo.Main  -- 删除两个(Demo.Core、Demo.Main)类库

dotnet sln add **/*.csproj  --  Linux下 添加项目,当前目录下的所有项目

 

dotnet add .\Demo.Main\ reference .\Demo.Core\   -- 添加引用

dotnet add .\Demo.Main\ reference **/*.csproj  -- Linux下使用通配符  

 

dotnet list .\Demo.Main\ reference  -- 查看项目下的引用

 

dotnet remove .\Demo.Main\ reference .\Demo.Core\   -- 删除引用

dotnet add .\Demo.Core\ package NLog  -- 添加包

 

dotnet list .\Demo.Core\ package  -- 查看所以安装引用的包

dotnet remove .\Demo.Core\ package NLog  -- 删除NLog包

 

编译项目:MSBuild(开源)

dotnet build [<PROJECT>|<SOLUTION>]
 [-o|--output]  -- 输出目录
 [-f|--framework]  --以哪个目标框架生成
 [-c|--configuration] --Debug/Realse
 [-r|--runtime]  -- RID=[os].[version]-[arch]    [osx.10.11-x64] 不填默认当前系统
 [--no-incremental] -- 全量 默认增量
 [--no-dependencies]
 [-v|--verbosity] --基本很多命令都有这个参数,输出日志  d详细,q静默,最少

 dotnet build [-h|--help]

dotnet build   -- 默认生成

 

dotnet build --configuration Release -- runtime ubuntu.18.04-x64   使用ubuntu版本来生成

 

 

项目发布

dotnet publish [<PROJECT>|<SOLUTION>] [-o|--output] [-f|--framework] [-c|--configuration]
                         [-r|--runtime] [--no-incremental] [--no-dependencies]
                         [-v|--verbosity] [--self-contained] [--no-self-contained]
 
--执行时会先判断当前目录是否在上一个构建之后有改动。直接打包

  --SDK(开发工具包,CLI)   Runtime(安装包)

   dotnet publish [-h|--help]

self-contained (自包含) 独立运行,不能跨平台(自带运行时,针对系统进行发布,文件会大一些,多一些)

   系统里的运行时版本变量额,但是你的应用用了某个版本的API

no-self-contained (不是自包含) 依赖运行,跨平台,需要装运行时

SDK 开发用
dotnet publish --runtime osx.10.11-x64 --self-contained

dotnet run -- 运行源代码

 

 

 

 

 

打包

 

 

 

 

 推送包

dotnet nuget push [<ROOT>] [-s|--source] [-ss|--symbol-source] [-t|--timeout] 
[-k|--api-key] [-sk|--symbol-api-key]

官方nuget上的包,删不了;可以取消。

 

 

 

 本地包缓存

dotnet nuget locals

 

 

 

dotnet nuget locals all -l  -- nuget包缓存地址

 

 

dotnet nuget locals all --clear  --清除包缓存

 

 

创建mvc的项目:dotnet new mvc -o Demo.Web

创建mvc的项目:dotnet new webapi-o Demo.Service

 

posted @ 2021-05-19 21:36  chenze  阅读(589)  评论(0编辑  收藏  举报
有事您Q我