在D盘新建文件夹测试,在此文件夹打开Power shell。输入命令dotnet new global.json --sdk-version 3.1.301,再输入命令dotnet --version即可查看当前文件夹使用的.Net Core的版本。此文件夹及其下面的子文件夹都会默认使用当前版本,若没有global.json文件,则向上级文件夹查找,若一直找不到,则默认使用系统最新版本。
创建项目帮助命令dotnet new
H:测试>dotnet new
用法: new [选项]
选项:
-h, --help Displays help for this command.
-l, --list Lists templates containing the specified name. If no name is specified, lists all templates.
-n, --name The name for the output being created. If no name is specified, the name of the current directory is used.
-o, --output Location to place the generated output.
-i, --install Installs a source or a template pack.
-u, --uninstall Uninstalls a source or a template pack.
--nuget-source Specifies a NuGet source to use during install.
--type Filters templates based on available types. Predefined values are "project", "item" or "other".
--dry-run Displays a summary of what would happen if the given command line were run if it would result in a template creation.
--force Forces content to be generated even if it would change existing files.
-lang, --language Filters templates based on language and specifies the language of the template to create.
--update-check Check the currently installed template packs for updates.
--update-apply Check the currently installed template packs for update, and install the updates.
Templates Short Name Language Tags
----------------------------------------------------------------------------------------------------------------------------------
Console Application console [C#], F#, VB Common/Console
Class library classlib [C#], F#, VB Common/Library
WPF Application wpf [C#] Common/WPF
WPF Class library wpflib [C#] Common/WPF
WPF Custom Control Library wpfcustomcontrollib [C#] Common/WPF
WPF User Control Library wpfusercontrollib [C#] Common/WPF
Windows Forms (WinForms) Application winforms [C#] Common/WinForms
Windows Forms (WinForms) Class library winformslib [C#] Common/WinForms
Worker Service worker [C#] Common/Worker/Web
Unit Test Project mstest [C#], F#, VB Test/MSTest
NUnit 3 Test Project nunit [C#], F#, VB Test/NUnit
NUnit 3 Test Item nunit-test [C#], F#, VB Test/NUnit
xUnit Test Project xunit [C#], F#, VB Test/xUnit
Razor Component razorcomponent [C#] Web/ASP.NET
Razor Page page [C#] Web/ASP.NET
MVC ViewImports viewimports [C#] Web/ASP.NET
MVC ViewStart viewstart [C#] Web/ASP.NET
Blazor Server App blazorserver [C#] Web/Blazor
Blazor WebAssembly App blazorwasm [C#] Web/Blazor/WebAssembly
ASP.NET Core Empty web [C#], F# Web/Empty
ASP.NET Core Web App (Model-View-Controller) mvc [C#], F# Web/MVC
ASP.NET Core Web App webapp [C#] Web/MVC/Razor Pages
ASP.NET Core with Angular angular [C#] Web/MVC/SPA
ASP.NET Core with React.js react [C#] Web/MVC/SPA
ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
Razor Class Library razorclasslib [C#] Web/Razor/Library/Razor Class Library
ASP.NET Core Web API webapi [C#], F# Web/WebAPI
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
dotnet gitignore file gitignore Config
global.json file globaljson Config
NuGet Config nugetconfig Config
Dotnet local tool manifest file tool-manifest Config
Web Config webconfig Config
Solution File sln Solution
Protocol Buffer File proto Web/gRPC
Examples:
dotnet new mvc --auth Individual
dotnet new web
dotnet new --help
H:测试>dotnet new --list --type project
用法: new [选项]
选项:
-h, --help Displays help for this command.
-l, --list Lists templates containing the specified name. If no name is specified, lists all templates.
-n, --name The name for the output being created. If no name is specified, the name of the current directory is used.
-o, --output Location to place the generated output.
-i, --install Installs a source or a template pack.
-u, --uninstall Uninstalls a source or a template pack.
--nuget-source Specifies a NuGet source to use during install.
--type Filters templates based on available types. Predefined values are "project", "item" or "other".
--dry-run Displays a summary of what would happen if the given command line were run if it would result in a template creation.
--force Forces content to be generated even if it would change existing files.
-lang, --language Filters templates based on language and specifies the language of the template to create.
--update-check Check the currently installed template packs for updates.
--update-apply Check the currently installed template packs for update, and install the updates.
Templates Short Name Language Tags
----------------------------------------------------------------------------------------------------------------------------------
Console Application console [C#], F#, VB Common/Console
Class library classlib [C#], F#, VB Common/Library
WPF Application wpf [C#] Common/WPF
WPF Class library wpflib [C#] Common/WPF
WPF Custom Control Library wpfcustomcontrollib [C#] Common/WPF
WPF User Control Library wpfusercontrollib [C#] Common/WPF
Windows Forms (WinForms) Application winforms [C#] Common/WinForms
Windows Forms (WinForms) Class library winformslib [C#] Common/WinForms
Worker Service worker [C#] Common/Worker/Web
Unit Test Project mstest [C#], F#, VB Test/MSTest
NUnit 3 Test Project nunit [C#], F#, VB Test/NUnit
xUnit Test Project xunit [C#], F#, VB Test/xUnit
Blazor Server App blazorserver [C#] Web/Blazor
Blazor WebAssembly App blazorwasm [C#] Web/Blazor/WebAssembly
ASP.NET Core Empty web [C#], F# Web/Empty
ASP.NET Core Web App (Model-View-Controller) mvc [C#], F# Web/MVC
ASP.NET Core Web App webapp [C#] Web/MVC/Razor Pages
ASP.NET Core with Angular angular [C#] Web/MVC/SPA
ASP.NET Core with React.js react [C#] Web/MVC/SPA
ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
Razor Class Library razorclasslib [C#] Web/Razor/Library/Razor Class Library
ASP.NET Core Web API webapi [C#], F# Web/WebAPI
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
Solution File
查找子项目模板
H:测试>dotnet new --list --type item
用法: new [选项]
选项:
-h, --help Displays help for this command.
-l, --list Lists templates containing the specified name. If no name is specified, lists all templates.
-n, --name The name for the output being created. If no name is specified, the name of the current directory is used.
-o, --output Location to place the generated output.
-i, --install Installs a source or a template pack.
-u, --uninstall Uninstalls a source or a template pack.
--nuget-source Specifies a NuGet source to use during install.
--type Filters templates based on available types. Predefined values are "project", "item" or "other".
--dry-run Displays a summary of what would happen if the given command line were run if it would result in a template creation.
--force Forces content to be generated even if it would change existing files.
-lang, --language Filters templates based on language and specifies the language of the template to create.
--update-check Check the currently installed template packs for updates.
--update-apply Check the currently installed template packs for update, and install the updates.
Templates Short Name Language Tags
--------------------------------------------------------------------------------------
NUnit 3 Test Item nunit-test [C#], F#, VB Test/NUnit
Razor Component razorcomponent [C#] Web/ASP.NET
Razor Page page [C#] Web/ASP.NET
MVC ViewImports viewimports [C#] Web/ASP.NET
MVC ViewStart viewstart [C#] Web/ASP.NET
dotnet gitignore file gitignore Config
global.json file globaljson Config
NuGet Config nugetconfig Config
Dotnet local tool manifest file tool-manifest Config
Web Config webconfig Config
Solution File sln Solution
Protocol Buffer File proto Web/gRPC
查找其它模板
H:测试>dotnet new --list --type other
用法: new [选项]
选项:
-h, --help Displays help for this command.
-l, --list Lists templates containing the specified name. If no name is specified, lists all templates.
-n, --name The name for the output being created. If no name is specified, the name of the current directory is used.
-o, --output Location to place the generated output.
-i, --install Installs a source or a template pack.
-u, --uninstall Uninstalls a source or a template pack.
--nuget-source Specifies a NuGet source to use during install.
--type Filters templates based on available types. Predefined values are "project", "item" or "other".
--dry-run Displays a summary of what would happen if the given command line were run if it would result in a template creation.
--force Forces content to be generated even if it would change existing files.
-lang, --language Filters templates based on language and specifies the language of the template to create.
--update-check Check the currently installed template packs for updates.
--update-apply Check the currently installed template packs for update, and install the updates.
Templates Short Name Language Tags
---------------------------------------------------------
Solution File sln Solution
创建项目
H:测试>dotnet new console --name helloword
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on hellowordhelloword.csproj...
正在确定要还原的项目…
已还原 H:测试hellowordhelloword.csproj (用时 167 ms)。
Restore succeeded.
-n 项目名称
-o 输出路径
H:测试>dotnet new console -n helloword -o test
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on testhelloword.csproj...
正在确定要还原的项目…
已还原 H:测试testhelloword.csproj (用时 153 ms)。
Restore succeeded
创建解决方案
创建解决方案文件
PS H:测试> dotnet new sln -o Demo
The template "Solution File" was created successfully.
进入解决方案目录
PS H:测试> cd Demo
创建类库项目
PS H:测试Demo> dotnet new classlib -o Demo.Core
The template "Class library" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on Demo.CoreDemo.Core.csproj...
正在确定要还原的项目…
已还原 H:测试DemoDemo.CoreDemo.Core.csproj (用时 258 ms)。
Restore succeeded.
创建命令行项目
PS H:测试Demo> dotnet new console -o Demo.main
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on Demo.mainDemo.main.csproj...
正在确定要还原的项目…
已还原 H:测试DemoDemo.mainDemo.main.csproj (用时 159 ms)。
Restore succeeded.
PS H:测试Demo> dotnet list .Demo.Main reference
项目引用
----
..Demo.CoreDemo.Core.csproj
项目添加Nuget包
PS H:测试Demo> dotnet add .Demo.Core package NLog
正在确定要还原的项目…
Writing C:UsershomeAppDataLocalTemptmp53E7.tmp
info : 正在将包“NLog”的 PackageReference 添加到项目“H:测试DemoDemo.CoreDemo.Core.csproj”。
info : 正在还原 H:测试DemoDemo.CoreDemo.Core.csproj 的包...
info : GET https://api.nuget.org/v3-flatcontainer/nlog/index.json
info : OK https://api.nuget.org/v3-flatcontainer/nlog/index.json 944 毫秒
info : GET https://api.nuget.org/v3-flatcontainer/nlog/4.7.4/nlog.4.7.4.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/nlog/4.7.4/nlog.4.7.4.nupkg 787 毫秒
info : 正在安装 NLog 4.7.4。
info : 包“NLog”与项目“H:测试DemoDemo.CoreDemo.Core.csproj”中指定的所有框架均兼容。
info : 包“NLog”(版本为 4.7.4)的 PackageReference 已添加到文件“H:测试DemoDemo.CoreDemo.Core.csproj”。
info : 正在提交还原...
info : 将资产文件写入磁盘。路径: H:测试DemoDemo.Coreobjproject.assets.json
log : 已还原 H:测试DemoDemo.CoreDemo.Core.csproj (用时 5.91 sec)。
PS H:测试Demo> dotnet nuget push .nupkgsDemo.Core.1.0.0.nupkg -k your key -s https://api.nuget.org/v3/index.json
正在将 Demo.Core.1.0.0.nupkg 推送到 'https://www.nuget.org/api/v2/package'...
PUT https://www.nuget.org/api/v2/package/
Forbidden https://www.nuget.org/api/v2/package/ 9249 毫秒
error: Response status code does not indicate success: 403 (The specified API key is invalid, has expired, or does not have permission to access the specified package.).
Usage: dotnet nuget push [arguments] [options]
Arguments:
[root] 指定包路径和 API 密钥,将包推送到服务器。
Options:
-h|--help Show help information
--force-english-output 使用不变的基于英语的区域性强制应用程序运行。
-s|--source 要使用的包源(URL、UNC/文件夹路径或包源名称)。如果在 NuGet.Config 中指定,则默认为 DefaultPushSource。
-ss|--symbol-source 要使用的符号服务器 URL。
-t|--timeout 推送到服务器的超时值(以秒为单位)。默认为 300 秒(5 分钟)。
-k|--api-key 服务器的 API 密钥。
-sk|--symbol-api-key 符号服务器的 API 密钥。
-d|--disable-buffering 推送到 HTTP(S) 服务器时禁用缓存可减少内存使用。
-n|--no-symbols 如果存在符号包,系统不会将该符号包推送到符号服务器。
--no-service-endpoint 请勿将 "api/v2/package" 追加到源 URL。
--interactive 对于身份验证等操作,允许命令阻止并要求手动操作。
--skip-duplicate 如果包和版本已存在,则跳过它并继续推送中的下一个包(若有)。
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { param($commandName, $wordToComplete, $cursorPosition) dotnet complete --position
c
u
r
s
o
r
P
o
s
i
t
i
o
n
"
cursorPosition "
cursorPosition"wordToComplete" | ForEach-Object { [System.Management.Automation.CompletionResult]::new($, $, ‘ParameterValue’, $_) } }(输入脚本,保存)