dotnet newdotnet new

本文适用于: ✔️ .NET Core 2.0 SDK 及更高版本This article applies to: ✔️ .NET Core 2.0 SDK and later versions

“属性”Name

dotnet new - 根据指定的模板,创建新的项目、配置文件或解决方案。dotnet new - Creates a new project, configuration file, or solution based on the specified template.

摘要Synopsis

dotnet new <TEMPLATE> [--dry-run] [--force] [-i|--install {PATH|NUGET_ID}]
    [-lang|--language {"C#"|"F#"|VB}] [-n|--name <OUTPUT_NAME>]
    [--nuget-source <SOURCE>] [-o|--output <OUTPUT_DIRECTORY>]
    [-u|--uninstall] [--update-apply] [--update-check] [Template options]

dotnet new <TEMPLATE> [-l|--list] [--type <TYPE>]

dotnet new -h|--help

描述Description

dotnet new 命令基于模板创建 .NET Core 项目或其他项目。The dotnet new command creates a .NET Core project or other artifacts based on a template.

命令调用模板引擎,以根据指定的模板和选项在磁盘上创建项目。The command calls the template engine to create the artifacts on disk based on the specified template and options.

隐式还原Implicit restore

无需运行 dotnet restore,因为它由所有需要还原的命令隐式运行,如 dotnet newdotnet builddotnet rundotnet testdotnet publishdotnet packYou don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. 若要禁用隐式还原,请使用 --no-restore 选项。To disable implicit restore, use the --no-restore option.

在执行显式还原有意义的某些情况下,例如 Azure DevOps Services 中的持续集成生成中,或在需要显式控制还原发生时间的生成系统中,dotnet restore 命令仍然有用。The dotnet restore command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.

有关如何使用 NuGet 源的信息,请参阅 dotnet restore 文档For information about how to manage NuGet feeds, see the dotnet restore documentation.

自变量Arguments

  • TEMPLATE

    调用命令时要实例化的模板。The template to instantiate when the command is invoked. 每个模板可能具有可传递的特定选项。Each template might have specific options you can pass. 有关详细信息,请参阅模板选项For more information, see Template options.

    可以运行 dotnet new --listdotnet new -l 以查看所有已安装模板的列表。You can run dotnet new --list or dotnet new -l to see a list of all installed templates. 如果 TEMPLATE 值与返回表中的“模板”或“短名称”列中的文本不完全匹配,则会对这两列执行 substring 匹配。If the TEMPLATE value isn't an exact match on text in the Templates or Short Name column from the returned table, a substring match is performed on those two columns.

    从 .NET Core 3.0 SDK 开始,当你在以下情况下调用 dotnet new 命令时,CLI 将在 NuGet.org 中搜索模板:Starting with .NET Core 3.0 SDK, the CLI searches for templates in NuGet.org when you invoke the dotnet new command in the following conditions:

    • 如果在调用 dotnet new 时 CLI 找不到模板匹配项,即使是部分匹配也不行。If the CLI can't find a template match when invoking dotnet new, not even partial.
    • 如果有较新版本的模板可用。If there's a newer version of the template available. 在这种情况下,将创建项目或工件,但 CLI 会就模板的更新版本发出警告。In this case, the project or artifact is created but the CLI warns you about an updated version of the template.

    下表显示了随 .NET Core SDK 一起预安装的模板。The following table shows the templates that come pre-installed with the .NET Core SDK. 模板的默认语言显示在括号内。The default language for the template is shown inside the brackets. 单击短名称链接可查看特定的模板选项。Click on the short name link to see the specific template options.

模板Templates 短名称Short name 语言Language TagsTags 已引入Introduced
控制台应用程序Console Application 控制台console [C#]、F#、VB[C#], F#, VB 常用/控制台Common/Console 1.01.0
类库Class library classlibclasslib [C#]、F#、VB[C#], F#, VB 常用/库Common/Library 1.01.0
WPF 应用程序WPF Application wpfwpf [C#]、VB[C#], VB 常用/WPFCommon/WPF 3.0(对于 VB,则为 5.0)3.0 (5.0 for VB)
WPF 类库WPF Class library wpflibwpflib [C#]、VB[C#], VB 常用/WPFCommon/WPF 3.0(对于 VB,则为 5.0)3.0 (5.0 for VB)
WPF 自定义控件库WPF Custom Control Library wpfcustomcontrollibwpfcustomcontrollib [C#]、VB[C#], VB 常用/WPFCommon/WPF 3.0(对于 VB,则为 5.0)3.0 (5.0 for VB)
WPF 用户控件库WPF User Control Library wpfusercontrollibwpfusercontrollib [C#]、VB[C#], VB 常用/WPFCommon/WPF 3.0(对于 VB,则为 5.0)3.0 (5.0 for VB)
Windows 窗体 (WinForms) 应用程序Windows Forms (WinForms) Application winformswinforms [C#]、VB[C#], VB 常用/WinFormsCommon/WinForms 3.0(对于 VB,则为 5.0)3.0 (5.0 for VB)
Windows 窗体 (WinForms) 类库Windows Forms (WinForms) Class library winformslibwinformslib [C#]、VB[C#], VB 常用/WinFormsCommon/WinForms 3.0(对于 VB,则为 5.0)3.0 (5.0 for VB)
Worker ServiceWorker Service workerworker [C#][C#] 常用/Worker/WebCommon/Worker/Web 3.03.0
单元测试项目Unit Test Project mstestmstest [C#]、F#、VB[C#], F#, VB 测试/MSTestTest/MSTest 1.01.0
NUnit 3 测试项目NUnit 3 Test Project nunitnunit [C#]、F#、VB[C#], F#, VB 测试/NUnitTest/NUnit 2.1.4002.1.400
NUnit 3 测试项NUnit 3 Test Item nunit-test [C#]、F#、VB[C#], F#, VB 测试/NUnitTest/NUnit 2.22.2
xUnit 测试项目xUnit Test Project xunitxunit [C#]、F#、VB[C#], F#, VB 测试/xUnitTest/xUnit 1.01.0
Razor 组件Razor Component razorcomponent [C#][C#] Web/ASP.NETWeb/ASP.NET 3.03.0
Razor 页Razor Page pagepage [C#][C#] Web/ASP.NETWeb/ASP.NET 2.02.0
MVC ViewImportsMVC ViewImports viewimportsviewimports [C#][C#] Web/ASP.NETWeb/ASP.NET 2.02.0
MVC ViewStartMVC ViewStart viewstart [C#][C#] Web/ASP.NETWeb/ASP.NET 2.02.0
:::no-loc(Blazor)::: 服务器应用:::no-loc(Blazor)::: Server App blazorserverblazorserver [C#][C#] Web/:::no-loc(Blazor):::Web/:::no-loc(Blazor)::: 3.03.0
:::no-loc(Blazor)::: :::no-loc(WebAssembly)::: 应用:::no-loc(Blazor)::: :::no-loc(WebAssembly)::: App blazorwasm [C#][C#] Web/:::no-loc(Blazor):::/:::no-loc(WebAssembly):::Web/:::no-loc(Blazor):::/:::no-loc(WebAssembly)::: 3.1.3003.1.300
ASP.NET Core 空ASP.NET Core Empty webweb [C#],F#[C#], F# Web/空Web/Empty 1.01.0
ASP.NET Core Web 应用程序 (Model-View-Controller)ASP.NET Core Web App (Model-View-Controller) mvcmvc [C#],F#[C#], F# Web/MVCWeb/MVC 1.01.0
ASP.NET Core Web 应用程序ASP.NET Core Web App webapp、razorwebapp, razor [C#][C#] Web/MVC/Razor PagesWeb/MVC/Razor Pages 2.2、2.02.2, 2.0
含 Angular 的 ASP.NET CoreASP.NET Core with Angular angularangular [C#][C#] Web/MVC/SPAWeb/MVC/SPA 2.02.0
含 React.js 的 ASP.NET CoreASP.NET Core with React.js reactreact [C#][C#] Web/MVC/SPAWeb/MVC/SPA 2.02.0
含 React.js 和 Redux 的 ASP.NET CoreASP.NET Core with React.js and Redux reactreduxreactredux [C#][C#] Web/MVC/SPAWeb/MVC/SPA 2.02.0
Razor 类库Razor Class Library razorclasslibrazorclasslib [C#][C#] Web/Razor/库/Razor 类库Web/Razor/Library/Razor Class Library 2.12.1
ASP.NET Core Web APIASP.NET Core Web API webapiwebapi [C#],F#[C#], F# Web/WebAPIWeb/WebAPI 1.01.0
ASP.NET Core gRPC 服务ASP.NET Core gRPC Service grpcgrpc [C#][C#] Web/gRPCWeb/gRPC 3.03.0
dotnet gitignore 文件dotnet gitignore file gitignore 配置Config 3.03.0
global.json 文件global.json file globaljsonglobaljson 配置Config 2.02.0
NuGet 配置NuGet Config nugetconfig 配置Config 1.01.0
Dotnet 本地工具清单文件Dotnet local tool manifest file tool-manifest 配置Config 3.03.0
Web 配置Web Config webconfig 配置Config 1.01.0
解决方案文件Solution File sln 解决方案Solution 1.01.0
协议缓冲区文件Protocol Buffer File protoproto Web/gRPCWeb/gRPC 3.03.0

选项Options

  • --dry-run

    显示有关以下内容的摘要:给定命令运行导致模板创建时发生的情况。Displays a summary of what would happen if the given command were run if it would result in a template creation. 自 .NET Core 2.2 SDK 起可用。Available since .NET Core 2.2 SDK.

  • --force

    强制生成内容,即使会更改现有文件,也不例外。Forces content to be generated even if it would change existing files. 当选择的模板将覆盖输出目录中的现有文件时,需要执行此操作。This is required when the template chosen would override existing files in the output directory.

  • -h|--help

    打印命令帮助。Prints out help for the command. 可针对 dotnet new 命令本身或任何模板调用它。It can be invoked for the dotnet new command itself or for any template. 例如 dotnet new mvc --helpFor example, dotnet new mvc --help.

  • -i|--install <PATH|NUGET_ID>

    从提供的 PATHNUGET_ID 安装模板包。Installs a template pack from the PATH or NUGET_ID provided. 若要安装模板包的预发布版本,需要以 <package-name>::<package-version> 格式指定该版本。If you want to install a prerelease version of a template package, you need to specify the version in the format of <package-name>::<package-version>. 默认情况下,dotnet new 为该版本传递 *,它表示最新的稳定包版本。By default, dotnet new passes * for the version, which represents the latest stable package version. 请在示例部分查看示例。See an example in the Examples section.

    如果在运行此命令时已经安装了模板的某个版本,则该模板将更新到指定版本,如果没有指定版本,则将更新到最新的稳定版本。If a version of the template was already installed when you run this command, the template will be updated to the specified version, or to the latest stable version if no version was specified.

    若要了解如何创建自定义模板,请参阅 dotnet new 自定义模板For information on creating custom templates, see Custom templates for dotnet new.

  • -l|--list

    列出包含指定名称的模板。Lists templates containing the specified name. 如果未指定名称,则列出所有模板。If no name is specified, lists all templates.

  • -lang|--language {C#|F#|VB}

    要创建的模板的语言。The language of the template to create. 接受的语言因模板而异(请参阅参数部分中的默认值)。The language accepted varies by the template (see defaults in the arguments section). 对于某些模板无效。Not valid for some templates.

    备注

    某些 shell 将 # 解释为特殊字符。Some shells interpret # as a special character. 在这些情况下,请将语言参数值括在引号中。In those cases, enclose the language parameter value in quotes. 例如 dotnet new console -lang "F#"For example, dotnet new console -lang "F#".

  • -n|--name <OUTPUT_NAME>

    所创建的输出的名称。The name for the created output. 如果未指定名称,使用的是当前目录的名称。If no name is specified, the name of the current directory is used.

  • --nuget-source <SOURCE>

    指定在安装期间要使用的 NuGet 源。Specifies a NuGet source to use during install. 自 .NET Core 2.1 SDK 起可用。Available since .NET Core 2.1 SDK.

  • -o|--output <OUTPUT_DIRECTORY>

    用于放置生成的输出的位置。Location to place the generated output. 默认为当前目录。The default is the current directory.

  • --type <TYPE>

    根据可用类型筛选模板。Filters templates based on available types. 预定义的值为 projectitemPredefined values are project and item.

  • -u|--uninstall [PATH|NUGET_ID]

    在提供的 PATHNUGET_ID 中卸载模板包。Uninstalls a template pack at the PATH or NUGET_ID provided. 如果未指定 <PATH|NUGET_ID> 值,将显示所有当前安装的模板包及其关联的模板。When the <PATH|NUGET_ID> value isn't specified, all currently installed template packs and their associated templates are displayed. 指定 NUGET_ID 时,请勿包含版本号。When specifying NUGET_ID, don't include the version number.

    如果未指定此选项的参数,该命令将列出已安装的模板及其详细信息。If you don't specify a parameter to this option, the command lists the installed templates and details about them.

    备注

    若要使用 PATH 卸载模板,需要完全限定路径。To uninstall a template using a PATH, you need to fully qualify the path. 例如,C:/Users/<USER>/Documents/Templates/GarciaSoftware.ConsoleTemplate.CSharp 有效,但是包含文件夹中的 ./GarciaSoftware.ConsoleTemplate.CSharp 无效 。For example, C:/Users/<USER>/Documents/Templates/GarciaSoftware.ConsoleTemplate.CSharp will work, but ./GarciaSoftware.ConsoleTemplate.CSharp from the containing folder will not. 模板路径中不要包含最后的终止目录斜杠。Don't include a final terminating directory slash on your template path.

  • --update-apply

    检查是否有可用于当前安装的模板包的更新并安装这些更新。Checks if there are updates available for the template packs that are currently installed and installs them. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

  • --update-check

    检查是否有可用于当前安装的模板包的更新。Checks if there are updates available for the template packs that are currently installed. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

模板选项Template options

每个项目模板都可能有附加选项。Each project template may have additional options available. 核心模板有以下附加选项:The core templates have the following additional options:

控制台console

  • -f|--framework <FRAMEWORK>

    指定目标框架Specifies the framework to target. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

    下表根据所使用的 SDK 版本号列出了默认值:The following table lists the default values according to the SDK version number you're using:

    SDK 版本SDK version 默认值Default value
    3.13.1 netcoreapp3.1
    3.03.0 netcoreapp3.0
  • --langVersion <VERSION_NUMBER>

    在已创建的项目文件中设置 LangVersion 属性。Sets the LangVersion property in the created project file. 例如,使用 --langVersion 7.3 以使用 C# 7.3。For example, use --langVersion 7.3 to use C# 7.3. 不支持 F#。Not supported for F#. 自 .NET Core 2.2 SDK 起可用。Available since .NET Core 2.2 SDK.

    有关默认的 C# 版本列表,请参阅默认For a list of default C# versions, see Defaults.

  • --no-restore

    如已指定,则在项目创建期间不执行隐式还原。If specified, doesn't execute an implicit restore during project creation. 自 .NET Core 2.2 SDK 起可用。Available since .NET Core 2.2 SDK.

****

classlibclasslib

  • _ -f|--framework <FRAMEWORK>*_ -f|--framework <FRAMEWORK>*

    指定目标框架Specifies the framework to target. 值:netcoreapp<version>(要创建 .NET Core 类库的话)或 netstandard<version>(要创建 .NET Standard 类库的话)。Values: netcoreapp<version> to create a .NET Core Class Library or netstandard<version> to create a .NET Standard Class Library. 默认值为 netstandard2.0The default value is netstandard2.0.

  • --langVersion <VERSION_NUMBER>

    在已创建的项目文件中设置 LangVersion 属性。Sets the LangVersion property in the created project file. 例如,使用 --langVersion 7.3 以使用 C# 7.3。For example, use --langVersion 7.3 to use C# 7.3. 不支持 F#。Not supported for F#. 自 .NET Core 2.2 SDK 起可用。Available since .NET Core 2.2 SDK.

    有关默认的 C# 版本列表,请参阅默认For a list of default C# versions, see Defaults.

  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

****

wpf、wpflib、wpfcustomcontrollib、wpfusercontrollibwpf, wpflib, wpfcustomcontrollib, wpfusercontrollib

  • _ -f|--framework <FRAMEWORK>*_ -f|--framework <FRAMEWORK>*

    指定目标框架Specifies the framework to target. 默认值为 netcoreapp3.1The default value is netcoreapp3.1. 自 .NET Core 3.1 SDK 起可用。Available since .NET Core 3.1 SDK.

  • --langVersion <VERSION_NUMBER>

    在已创建的项目文件中设置 LangVersion 属性。Sets the LangVersion property in the created project file. 例如,使用 --langVersion 7.3 以使用 C# 7.3。For example, use --langVersion 7.3 to use C# 7.3.

    有关默认的 C# 版本列表,请参阅默认For a list of default C# versions, see Defaults.

  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

****

winforms、winformslibwinforms, winformslib

  • _ --langVersion <VERSION_NUMBER>*_ --langVersion <VERSION_NUMBER>*

    在已创建的项目文件中设置 LangVersion 属性。Sets the LangVersion property in the created project file. 例如,使用 --langVersion 7.3 以使用 C# 7.3。For example, use --langVersion 7.3 to use C# 7.3.

    有关默认的 C# 版本列表,请参阅默认For a list of default C# versions, see Defaults.

  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

****

worker、grpcworker, grpc

  • _ -f|--framework <FRAMEWORK>*_ -f|--framework <FRAMEWORK>*

    指定目标框架Specifies the framework to target. 默认值为 netcoreapp3.1The default value is netcoreapp3.1. 自 .NET Core 3.1 SDK 起可用。Available since .NET Core 3.1 SDK.

  • --exclude-launch-settings

    从生成的模板中排除 launchSettings.json。Excludes launchSettings.json from the generated template.

  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

****

mstest、xunitmstest, xunit

  • _ -f|--framework <FRAMEWORK>*_ -f|--framework <FRAMEWORK>*

    指定目标框架Specifies the framework to target. 自 .NET Core 3.0 SDK 起可用的选项。Option available since .NET Core 3.0 SDK.

    下表根据所使用的 SDK 版本号列出了默认值:The following table lists the default values according to the SDK version number you're using:

    SDK 版本SDK version 默认值Default value
    3.13.1 netcoreapp3.1
    3.03.0 netcoreapp3.0
  • -p|--enable-pack

    允许使用 dotnet pack 为项目打包。Enables packaging for the project using dotnet pack.

  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

****

nunitnunit

  • _ -f|--framework <FRAMEWORK>*_ -f|--framework <FRAMEWORK>*

    指定目标框架Specifies the framework to target.

    下表根据所使用的 SDK 版本号列出了默认值:The following table lists the default values according to the SDK version number you're using:

    SDK 版本SDK version 默认值Default value
    3.13.1 netcoreapp3.1
    3.03.0 netcoreapp3.0
    2.22.2 netcoreapp2.2
    2.12.1 netcoreapp2.1
  • -p|--enable-pack

    允许使用 dotnet pack 为项目打包。Enables packaging for the project using dotnet pack.

  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

****

page

  • _ -na|--namespace <NAMESPACE_NAME>*_ -na|--namespace <NAMESPACE_NAME>*

    已生成代码的命名空间。Namespace for the generated code. 默认值为 MyApp.NamespaceThe default value is MyApp.Namespace.

  • -np|--no-pagemodel

    创建不含 PageModel 的页。Creates the page without a PageModel.

****

viewimports、protoviewimports, proto

  • _ -na|--namespace <NAMESPACE_NAME>*_ -na|--namespace <NAMESPACE_NAME>*

    已生成代码的命名空间。Namespace for the generated code. 默认值为 MyApp.NamespaceThe default value is MyApp.Namespace.

****

blazorserverblazorserver

  • _ -au|--auth <AUTHENTICATION_TYPE>*_ -au|--auth <AUTHENTICATION_TYPE>*

    要使用的身份验证类型。The type of authentication to use. 可能的值为:The possible values are:

    • None - 不进行身份验证(默认)。None - No authentication (Default).
    • Individual - 个人身份验证。Individual - Individual authentication.
    • IndividualB2C - 使用 Azure AD B2C 进行个人身份验证。IndividualB2C - Individual authentication with Azure AD B2C.
    • SingleOrg - 对一个租户进行组织身份验证。SingleOrg - Organizational authentication for a single tenant.
    • MultiOrg - 对多个租户进行组织身份验证。MultiOrg - Organizational authentication for multiple tenants.
    • Windows - Windows 身份验证。Windows - Windows authentication.
  • --aad-b2c-instance <INSTANCE>

    要连接到的 Azure Active Directory B2C 实例。The Azure Active Directory B2C instance to connect to. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication. 默认值为 https://login.microsoftonline.com/tfp/The default value is https://login.microsoftonline.com/tfp/.

  • -ssp|--susi-policy-id <ID>

    此项目的登录和注册策略 ID。The sign-in and sign-up policy ID for this project. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication.

  • -rp|--reset-password-policy-id <ID>

    此项目的重置密码策略 ID。The reset password policy ID for this project. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication.

  • -ep|--edit-profile-policy-id <ID>

    此项目的编辑配置文件策略 ID。The edit profile policy ID for this project. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication.

  • --aad-instance <INSTANCE>

    要连接到的 Azure Active Directory 实例。The Azure Active Directory instance to connect to. SingleOrgMultiOrg 身份验证结合使用。Use with SingleOrg or MultiOrg authentication. 默认值为 https://login.microsoftonline.com/The default value is https://login.microsoftonline.com/.

  • --client-id <ID>

    此项目的客户端 ID。The Client ID for this project. IndividualB2CSingleOrgMultiOrg 身份验证结合使用。Use with IndividualB2C, SingleOrg, or MultiOrg authentication. 默认值为 11111111-1111-1111-11111111111111111The default value is 11111111-1111-1111-11111111111111111.

  • --domain <DOMAIN>

    目录租户的域。The domain for the directory tenant. SingleOrgIndividualB2C 身份验证结合使用。Use with SingleOrg or IndividualB2C authentication. 默认值为 qualified.domain.nameThe default value is qualified.domain.name.

  • --tenant-id <ID>

    要连接到的目录的 TenantId ID。The TenantId ID of the directory to connect to. SingleOrg 身份验证结合使用。Use with SingleOrg authentication. 默认值为 22222222-2222-2222-2222-222222222222The default value is 22222222-2222-2222-2222-222222222222.

  • --callback-path <PATH>

    重定向 URI 的应用程序基路径中的请求路径。The request path within the application's base path of the redirect URI. SingleOrgIndividualB2C 身份验证结合使用。Use with SingleOrg or IndividualB2C authentication. 默认值为 /signin-oidcThe default value is /signin-oidc.

  • -r|--org-read-access

    允许此应用程序对目录进行读取访问。Allows this application read-access to the directory. 仅适用于 SingleOrgMultiOrg 身份验证。Only applies to SingleOrg or MultiOrg authentication.

  • --exclude-launch-settings

    从生成的模板中排除 launchSettings.json。Excludes launchSettings.json from the generated template.

  • --no-https

    关闭 HTTPS。Turns off HTTPS. 此选项仅适用于 IndividualIndividualB2CSingleOrgMultiOrg 未用于 --auth 的情况。This option only applies if Individual, IndividualB2C, SingleOrg, or MultiOrg aren't being used for --auth.

  • -uld|--use-local-db

    指定应使用 LocalDB,而不使用 SQLite。Specifies LocalDB should be used instead of SQLite. 仅适用于 IndividualIndividualB2C 身份验证。Only applies to Individual or IndividualB2C authentication.

  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

****

Webweb

  • _ --exclude-launch-settings*_ --exclude-launch-settings*

    从生成的模板中排除 launchSettings.json。Excludes launchSettings.json from the generated template.

  • -f|--framework <FRAMEWORK>

    指定目标框架Specifies the framework to target. 选项在 .NET Core 2.2 SDK 中不可用。Option not available in .NET Core 2.2 SDK.

    下表根据所使用的 SDK 版本号列出了默认值:The following table lists the default values according to the SDK version number you're using:

    SDK 版本SDK version 默认值Default value
    3.13.1 netcoreapp3.1
    3.03.0 netcoreapp3.0
    2.12.1 netcoreapp2.1
  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

  • --no-https

    关闭 HTTPS。Turns off HTTPS.

****

mvc、webappmvc, webapp

  • _ -au|--auth <AUTHENTICATION_TYPE>*_ -au|--auth <AUTHENTICATION_TYPE>*

    要使用的身份验证类型。The type of authentication to use. 可能的值为:The possible values are:

    • None - 不进行身份验证(默认)。None - No authentication (Default).
    • Individual - 个人身份验证。Individual - Individual authentication.
    • IndividualB2C - 使用 Azure AD B2C 进行个人身份验证。IndividualB2C - Individual authentication with Azure AD B2C.
    • SingleOrg - 对一个租户进行组织身份验证。SingleOrg - Organizational authentication for a single tenant.
    • MultiOrg - 对多个租户进行组织身份验证。MultiOrg - Organizational authentication for multiple tenants.
    • Windows - Windows 身份验证。Windows - Windows authentication.
  • --aad-b2c-instance <INSTANCE>

    要连接到的 Azure Active Directory B2C 实例。The Azure Active Directory B2C instance to connect to. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication. 默认值为 https://login.microsoftonline.com/tfp/The default value is https://login.microsoftonline.com/tfp/.

  • -ssp|--susi-policy-id <ID>

    此项目的登录和注册策略 ID。The sign-in and sign-up policy ID for this project. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication.

  • -rp|--reset-password-policy-id <ID>

    此项目的重置密码策略 ID。The reset password policy ID for this project. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication.

  • -ep|--edit-profile-policy-id <ID>

    此项目的编辑配置文件策略 ID。The edit profile policy ID for this project. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication.

  • --aad-instance <INSTANCE>

    要连接到的 Azure Active Directory 实例。The Azure Active Directory instance to connect to. SingleOrgMultiOrg 身份验证结合使用。Use with SingleOrg or MultiOrg authentication. 默认值为 https://login.microsoftonline.com/The default value is https://login.microsoftonline.com/.

  • --client-id <ID>

    此项目的客户端 ID。The Client ID for this project. IndividualB2CSingleOrgMultiOrg 身份验证结合使用。Use with IndividualB2C, SingleOrg, or MultiOrg authentication. 默认值为 11111111-1111-1111-11111111111111111The default value is 11111111-1111-1111-11111111111111111.

  • --domain <DOMAIN>

    目录租户的域。The domain for the directory tenant. SingleOrgIndividualB2C 身份验证结合使用。Use with SingleOrg or IndividualB2C authentication. 默认值为 qualified.domain.nameThe default value is qualified.domain.name.

  • --tenant-id <ID>

    要连接到的目录的 TenantId ID。The TenantId ID of the directory to connect to. SingleOrg 身份验证结合使用。Use with SingleOrg authentication. 默认值为 22222222-2222-2222-2222-222222222222The default value is 22222222-2222-2222-2222-222222222222.

  • --callback-path <PATH>

    重定向 URI 的应用程序基路径中的请求路径。The request path within the application's base path of the redirect URI. SingleOrgIndividualB2C 身份验证结合使用。Use with SingleOrg or IndividualB2C authentication. 默认值为 /signin-oidcThe default value is /signin-oidc.

  • -r|--org-read-access

    允许此应用程序对目录进行读取访问。Allows this application read-access to the directory. 仅适用于 SingleOrgMultiOrg 身份验证。Only applies to SingleOrg or MultiOrg authentication.

  • --exclude-launch-settings

    从生成的模板中排除 launchSettings.json。Excludes launchSettings.json from the generated template.

  • --no-https

    关闭 HTTPS。Turns off HTTPS. 此选项仅适用于未使用 IndividualIndividualB2CSingleOrgMultiOrg 的情况。This option only applies if Individual, IndividualB2C, SingleOrg, or MultiOrg aren't being used.

  • -uld|--use-local-db

    指定应使用 LocalDB,而不使用 SQLite。Specifies LocalDB should be used instead of SQLite. 仅适用于 IndividualIndividualB2C 身份验证。Only applies to Individual or IndividualB2C authentication.

  • -f|--framework <FRAMEWORK>

    指定目标框架Specifies the framework to target. 自 .NET Core 3.0 SDK 起可用的选项。Option available since .NET Core 3.0 SDK.

    下表根据所使用的 SDK 版本号列出了默认值:The following table lists the default values according to the SDK version number you're using:

    SDK 版本SDK version 默认值Default value
    3.13.1 netcoreapp3.1
    3.03.0 netcoreapp3.0
  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

  • --use-browserlink

    在项目中添加 BrowserLink。Includes BrowserLink in the project. 选项在 .NET Core 2.2 和 3.1 SDK 中不可用。Option not available in .NET Core 2.2 and 3.1 SDK.

  • -rrc|--razor-runtime-compilation

    确定项目是否配置为在调试生成中使用 Razor 运行时编译Determines if the project is configured to use Razor runtime compilation in Debug builds. 自 .NET Core 3.1.201 SDK 起可用的选项。Option available since .NET Core 3.1.201 SDK.

****

angular、reactangular, react

  • _ -au|--auth <AUTHENTICATION_TYPE>*_ -au|--auth <AUTHENTICATION_TYPE>*

    要使用的身份验证类型。The type of authentication to use. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

    可能的值为:The possible values are:

    • None - 不进行身份验证(默认)。None - No authentication (Default).
    • Individual - 个人身份验证。Individual - Individual authentication.
  • --exclude-launch-settings

    从生成的模板中排除 launchSettings.json。Excludes launchSettings.json from the generated template.

  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

  • --no-https

    关闭 HTTPS。Turns off HTTPS. 仅当身份验证为 None 时,此选项才适用。This option only applies if authentication is None.

  • -uld|--use-local-db

    指定应使用 LocalDB,而不使用 SQLite。Specifies LocalDB should be used instead of SQLite. 仅适用于 IndividualIndividualB2C 身份验证。Only applies to Individual or IndividualB2C authentication. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

  • -f|--framework <FRAMEWORK>

    指定目标框架Specifies the framework to target. 选项在 .NET Core 2.2 SDK 中不可用。Option not available in .NET Core 2.2 SDK.

    下表根据所使用的 SDK 版本号列出了默认值:The following table lists the default values according to the SDK version number you're using:

    SDK 版本SDK version 默认值Default value
    3.13.1 netcoreapp3.1
    3.03.0 netcoreapp3.0
    2.12.1 netcoreapp2.0

****

reactreduxreactredux

  • _ --exclude-launch-settings*_ --exclude-launch-settings*

    从生成的模板中排除 launchSettings.json。Excludes launchSettings.json from the generated template.

  • -f|--framework <FRAMEWORK>

    指定目标框架Specifies the framework to target. 选项在 .NET Core 2.2 SDK 中不可用。Option not available in .NET Core 2.2 SDK.

    下表根据所使用的 SDK 版本号列出了默认值:The following table lists the default values according to the SDK version number you're using:

    SDK 版本SDK version 默认值Default value
    3.13.1 netcoreapp3.1
    3.03.0 netcoreapp3.0
    2.12.1 netcoreapp2.0
  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

  • --no-https

    关闭 HTTPS。Turns off HTTPS.

****

razorclasslibrazorclasslib

  • _ --no-restore*_ --no-restore*

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

  • -s|--support-pages-and-views

    除了将组件添加到此库以外,还支持添加传统的 Razor 页面和视图。Supports adding traditional Razor pages and Views in addition to components to this library. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

****

webapiwebapi

  • _ -au|--auth <AUTHENTICATION_TYPE>*_ -au|--auth <AUTHENTICATION_TYPE>*

    要使用的身份验证类型。The type of authentication to use. 可能的值为:The possible values are:

    • None - 不进行身份验证(默认)。None - No authentication (Default).
    • IndividualB2C - 使用 Azure AD B2C 进行个人身份验证。IndividualB2C - Individual authentication with Azure AD B2C.
    • SingleOrg - 对一个租户进行组织身份验证。SingleOrg - Organizational authentication for a single tenant.
    • Windows - Windows 身份验证。Windows - Windows authentication.
  • --aad-b2c-instance <INSTANCE>

    要连接到的 Azure Active Directory B2C 实例。The Azure Active Directory B2C instance to connect to. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication. 默认值为 https://login.microsoftonline.com/tfp/The default value is https://login.microsoftonline.com/tfp/.

  • -ssp|--susi-policy-id <ID>

    此项目的登录和注册策略 ID。The sign-in and sign-up policy ID for this project. IndividualB2C 身份验证结合使用。Use with IndividualB2C authentication.

  • --aad-instance <INSTANCE>

    要连接到的 Azure Active Directory 实例。The Azure Active Directory instance to connect to. SingleOrg 身份验证结合使用。Use with SingleOrg authentication. 默认值为 https://login.microsoftonline.com/The default value is https://login.microsoftonline.com/.

  • --client-id <ID>

    此项目的客户端 ID。The Client ID for this project. IndividualB2CSingleOrg 身份验证结合使用。Use with IndividualB2C or SingleOrg authentication. 默认值为 11111111-1111-1111-11111111111111111The default value is 11111111-1111-1111-11111111111111111.

  • --domain <DOMAIN>

    目录租户的域。The domain for the directory tenant. IndividualB2CSingleOrg 身份验证结合使用。Use with IndividualB2C or SingleOrg authentication. 默认值为 qualified.domain.nameThe default value is qualified.domain.name.

  • --tenant-id <ID>

    要连接到的目录的 TenantId ID。The TenantId ID of the directory to connect to. SingleOrg 身份验证结合使用。Use with SingleOrg authentication. 默认值为 22222222-2222-2222-2222-222222222222The default value is 22222222-2222-2222-2222-222222222222.

  • -r|--org-read-access

    允许此应用程序对目录进行读取访问。Allows this application read-access to the directory. 仅适用于 SingleOrg 身份验证。Only applies to SingleOrg authentication.

  • --exclude-launch-settings

    从生成的模板中排除 launchSettings.json。Excludes launchSettings.json from the generated template.

  • --no-https

    关闭 HTTPS。Turns off HTTPS. app.UseHstsapp.UseHttpsRedirection 未添加到 Startup.Configure 中。app.UseHsts and app.UseHttpsRedirection aren't added to Startup.Configure. 此选项仅适用于 IndividualB2CSingleOrg 未用于身份验证的情况。This option only applies if IndividualB2C or SingleOrg aren't being used for authentication.

  • -uld|--use-local-db

    指定应使用 LocalDB,而不使用 SQLite。Specifies LocalDB should be used instead of SQLite. 仅适用于 IndividualB2C 身份验证。Only applies to IndividualB2C authentication.

  • -f|--framework <FRAMEWORK>

    指定目标框架Specifies the framework to target. 选项在 .NET Core 2.2 SDK 中不可用。Option not available in .NET Core 2.2 SDK.

    下表根据所使用的 SDK 版本号列出了默认值:The following table lists the default values according to the SDK version number you're using:

    SDK 版本SDK version 默认值Default value
    3.13.1 netcoreapp3.1
    3.03.0 netcoreapp3.0
    2.12.1 netcoreapp2.1
  • --no-restore

    在项目创建期间不执行隐式还原。Doesn't execute an implicit restore during project creation.

****

globaljsonglobaljson

  • _ --sdk-version <VERSION_NUMBER>*_ --sdk-version <VERSION_NUMBER>*

    指定要在 global.json 文件中使用的 .NET Core SDK 版本。Specifies the version of the .NET Core SDK to use in the global.json file.


示例Examples

  • 通过指定模板名称,创建 C# 控制台应用程序项目:Create a C# console application project by specifying the template name:

    dotnet new "Console Application"
    
  • 在当前目录中创建 F# 控制台应用程序项目:Create an F# console application project in the current directory:

    dotnet new console -lang "F#"
    
  • 在指定的目录中创建 .NET Standard 类库项目:Create a .NET Standard class library project in the specified directory:

    dotnet new classlib -lang VB -o MyLibrary
    
  • 在当前目录中新建没有设置身份验证的 ASP.NET Core C# MVC 项目:Create a new ASP.NET Core C# MVC project in the current directory with no authentication:

    dotnet new mvc -au None
    
  • 创建新的 xUnit 项目:Create a new xUnit project:

    dotnet new xunit
    
  • 列出可用于单页应用程序 (SPA) 模板的所有模板:List all templates available for Single Page Application (SPA) templates:

    dotnet new spa -l
    
  • 列出与“we”子字符串匹配的所有模板。List all templates matching the we substring. 找不到完全匹配,因此子字符串匹配针对短名称和名称列运行。No exact match is found, so substring matching runs against both the short name and name columns.

    dotnet new we -l
    
  • 尝试调用与 ng 匹配的模板。Attempt to invoke the template matching ng . 如果无法确定单个匹配项,请列出部分匹配项的模板。If a single match can't be determined, list the templates that are partial matches.

    dotnet new ng
    
  • 安装 ASP.NET Core 的 SPA 模板 2.0 版:Install version 2.0 of the SPA templates for ASP.NET Core:

    dotnet new -i Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0
    
  • 列出已安装的模板及其详细信息,包括如何卸载它们:List the installed templates and details about them, including how to uninstall them:

    dotnet new -u
    
  • 在当前目录中创建 global.json,将 SDK 版本设置为 3.1.101:Create a global.json in the current directory setting the SDK version to 3.1.101:

    dotnet new globaljson --sdk-version 3.1.101
    

请参阅See also