dotnet newdotnet new

本文適用于: ✔️ .net CORE 2.0 SDK 和更新版本This article applies to: ✔️ .NET Core 2.0 SDK and later versions

NameName

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.

dotnet restore 明確還原的特定情況下,此命令仍然很有用,例如Azure DevOps Services 中的持續整合組建,或在需要明確控制還原發生時機的組建系統中。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 值不完全符合所傳回資料表之 [樣板Templates ] 或 [簡短名稱] 資料行中的文字,則會在這兩個數據行上執行子字串相符。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:

    • 如果 CLI 在叫用時找不到相符的範本 dotnet new ,甚至不是部分。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#][C#] Common/WPFCommon/WPF 3.03.0
WPF 類別庫WPF Class library wpflibwpflib [C#][C#] Common/WPFCommon/WPF 3.03.0
WPF 自訂控制項程式庫WPF Custom Control Library wpfcustomcontrollibwpfcustomcontrollib [C#][C#] Common/WPFCommon/WPF 3.03.0
WPF 使用者控制項程式庫WPF User Control Library wpfusercontrollibwpfusercontrollib [C#][C#] Common/WPFCommon/WPF 3.03.0
Windows Forms (WinForms)應用程式Windows Forms (WinForms) Application winformswinforms [C#][C#] Common/WinFormsCommon/WinForms 3.03.0
Windows Forms (WinForms)類別庫Windows Forms (WinForms) Class library winformslibwinformslib [C#][C#] Common/WinFormsCommon/WinForms 3.03.0
背景工作服務Worker Service 工作worker [C#][C#] 一般/背景工作/WebCommon/Worker/Web 3.03.0
單元測試專案Unit Test Project mstest.exemstest [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 本頁page [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
Blazor 伺服器應用程式Blazor Server App blazorserverblazorserver [C#][C#] Web/BlazorWeb/Blazor 3.03.0
Blazor WebAssembly 應用程式Blazor WebAssembly App blazorwasm [C#][C#] Web/Blazor/WebAssemblyWeb/Blazor/WebAssembly 3.1.3003.1.300
空的 ASP.NET CoreASP.NET Core Empty 網路web [C#]、F#[C#], F# Web/空白Web/Empty 1.01.0
ASP.NET Core Web 應用程式 (模型檢視控制器)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 頁面Web/MVC/Razor Pages 2.2、2。02.2, 2.0
ASP.NET Core 與 AngularASP.NET Core with Angular angularangular [C#][C#] Web/MVC/SPAWeb/MVC/SPA 2.02.0
ASP.NET Core 與 React.jsASP.NET Core with React.js 反應react [C#][C#] Web/MVC/SPAWeb/MVC/SPA 2.02.0
ASP.NET Core 與 React.js 和 ReduxASP.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 ConfigConfig 3.03.0
global.json 檔案global.json file globaljsonglobaljson ConfigConfig 2.02.0
NuGet 組態NuGet Config nugetconfig ConfigConfig 1.01.0
Dotnet 本機工具資訊清單檔Dotnet local tool manifest file tool-manifest ConfigConfig 3.03.0
Web 組態Web Config webconfig ConfigConfig 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>

    從或提供的安裝範本 PATH 套件 NUGET_IDInstalls 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. 預先定義的值為 projectitemotherPredefined values are project, item, and other.

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

    在或提供的上卸載範本套件 PATH NUGET_IDUninstalls 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:

consoleconsole

  • -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>

    指定要設為目標的架構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>

    指定要設為目標的架構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在建立的專案檔中設定屬性。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>

    指定要設為目標的架構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>

    指定要設為目標的架構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>

    指定要設為目標的架構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>

    產生之程式碼的命名空間。Namespace for the generated code. 預設值為 MyApp.NamespaceThe default value is MyApp.Namespace.

  • -np|--no-pagemodel

    建立不含 PageModel 的頁面。Creates the page without a PageModel.


viewimports.cshtml,protoviewimports, proto

  • -na|--namespace <NAMESPACE_NAME>

    產生之程式碼的命名空間。Namespace for the generated code. 預設值為 MyApp.NamespaceThe default value is MyApp.Namespace.


blazorserverblazorserver

  • -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>

    此專案的登入和註冊原則識別碼。The sign-in and sign-up policy ID for this project. 搭配 IndividualB2C 驗證使用。Use with IndividualB2C authentication.

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

    此專案的重設密碼原則識別碼。The reset password policy ID for this project. 搭配 IndividualB2C 驗證使用。Use with IndividualB2C authentication.

  • -ep|--edit-profile-policy-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>

    此專案的用戶端識別碼。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 識別碼。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. 只有當 IndividualIndividualB2CSingleOrg 或不是用於時 MultiOrg--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

    從產生的範本排除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>

    要使用的驗證類型。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>

    此專案的登入和註冊原則識別碼。The sign-in and sign-up policy ID for this project. 搭配 IndividualB2C 驗證使用。Use with IndividualB2C authentication.

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

    此專案的重設密碼原則識別碼。The reset password policy ID for this project. 搭配 IndividualB2C 驗證使用。Use with IndividualB2C authentication.

  • -ep|--edit-profile-policy-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>

    此專案的用戶端識別碼。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 識別碼。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

    判斷專案是否設定為使用 Debug 組建中的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, react

  • -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. 只有在驗證為時,才會套用此選項 NoneThis 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

    從產生的範本排除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

    在專案建立期間不會執行隱含還原。Doesn't execute an implicit restore during project creation.

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

    支援將傳統的 Razor 頁面和 Views 新增至此程式庫的元件。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>

    要使用的驗證類型。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>

    此專案的登入和註冊原則識別碼。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>

    此專案的用戶端識別碼。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 識別碼。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.Configureapp.UseHsts and app.UseHttpsRedirection aren't added to Startup.Configure. 只有當 IndividualB2C 或未用於驗證時,此選項才適用 SingleOrgThis 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>

    指定要在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
    
  • 在目前目錄中建立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