Файли
openidea/generators/dotnet.toml
T
l0ng-ai ad95695588 fix(new-project): name a .NET project's top folder after its solution (#5819)
With "Create solution" checked and a solution name that differs from the
project name, the new project's top folder was still named after the project
(MyProject/MySolution.slnx, MyProject/MyProject/MyProject.csproj).

Generators can now give the project folder its own name with a `directory`
template; .NET uses the solution name, so the result is
MySolution/MySolution.slnx and MySolution/MyProject/MyProject.csproj. Without
a solution, or with an empty name, the folder is the project's as before. The
New Project dialog shows that folder in its path hint and checks it for an
existing non-empty folder.

Fixes #5732
2026-11-25 16:08:44 +08:00

109 рядки
3.0 KiB
TOML

id = "dotnet"
name = ".NET"
group = ".NET"
icon = "project-dotnet"
description = "A .NET project from dotnet new."
# With a solution, the top folder is named after it (MySolution/MyProject/MyProject.csproj).
# `solution-name` is sent only while "Create solution" is checked; otherwise it renders the name.
directory = "{{solution-name}}"
# `dotnet --version` fails without an SDK (a runtime-only install). Blazor Web App and the
# other templates' current options need SDK 8.
[[requires]]
program = "dotnet"
min = "8.0"
hint = "Install the .NET SDK: https://dotnet.microsoft.com/download"
[[fields]]
id = "template"
label = "Template:"
type = "choice"
options = [
{ value = "console", label = "Console App" },
{ value = "classlib", label = "Class Library" },
{ value = "webapi", label = "ASP.NET Core Web API" },
{ value = "mvc", label = "ASP.NET Core MVC" },
{ value = "blazor", label = "Blazor Web App" },
{ value = "xunit", label = "xUnit Test Project" },
]
default = "console"
[[fields]]
id = "lang"
label = "Language:"
type = "choice"
segmented = true
options = [{ value = "C#", label = "C#" }, { value = "F#", label = "F#" }]
default = "C#"
visible = { template = ["console", "classlib", "webapi", "mvc", "xunit"] }
[[fields]]
id = "sdk"
label = "SDK version:"
type = "sdk"
sdk = "dotnet"
version = true
min = "8.0"
hint = "Pinned in global.json; later patches and feature bands of the same .NET version also qualify. Automatic lets dotnet choose the SDK."
[[fields]]
id = "solution"
label = "Create solution"
type = "checkbox"
default = "true"
hint = "As in Visual Studio: the solution file at the top, the project in its own folder."
[[fields]]
id = "solution-name"
label = "Solution name:"
type = "text"
pattern = '^[^/\\:*?"<>|.\s][^/\\:*?"<>|]*$'
default = "{{name}}"
visible = { solution = "true" }
# Write the pin before the SDK resolver runs, even under an incompatible parent global.json.
[[files]]
path = "global.json"
if-set = "sdk"
content = '''
{
"sdk": {
"version": "{{sdk|json}}",
"rollForward": "latestFeature"
}
}
'''
[[after]]
label = "Creating the solution"
program = "dotnet"
args = ["new", "sln", "--name", "{{solution-name}}"]
when = { solution = "true" }
env = { DOTNET_CLI_TELEMETRY_OPTOUT = "1", DOTNET_NOLOGO = "1" }
[[after]]
label = "Running dotnet new"
program = "dotnet"
args = [
"new", "{{template}}", "--name", "{{name}}",
{ when = { solution = "true" }, args = ["--output", "{{name}}"] },
{ when = { solution = "false" }, args = ["--output", "."] },
{ when = { template = ["console", "classlib", "webapi", "mvc", "xunit"] }, args = ["--language", "{{lang}}"] },
]
env = { DOTNET_CLI_TELEMETRY_OPTOUT = "1", DOTNET_NOLOGO = "1" }
[[after]]
label = "Adding the project to the solution"
program = "dotnet"
args = ["sln", "add", "{{name}}"]
when = { solution = "true" }
env = { DOTNET_CLI_TELEMETRY_OPTOUT = "1", DOTNET_NOLOGO = "1" }
[[after]]
label = "Adding a .gitignore"
program = "dotnet"
args = ["new", "gitignore"]
env = { DOTNET_CLI_TELEMETRY_OPTOUT = "1", DOTNET_NOLOGO = "1" }
optional = true