Skip to content

Commit 57d449e

Browse files
authored
Enhanced dotnet new project template. (#1061)
* Enhanced dotnet new project template. - Added support for net10.0 and xunit.v3 - Removes package reference to Microsoft.Net.Test.Sdk when using TUnit - Sets output type to Exe when using TUnit - Adds global using directives to the csproj when appropriate - Removes 'using Reqnroll;' from the CalculatorStepDefinitions.cs when global usings is in effect. * Removed FluentAssertions from the template. Renamed template flag to useImplicitUsings. * Fix template of stepDefinition template
1 parent 5708c62 commit 57d449e

5 files changed

Lines changed: 156 additions & 128 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# [vNext]
22

33
## Improvements:
4+
* Improve the command line dotnet new project templates to support .NET 10, xUnit v3 and support of implicit usings when appropriate. Removed the option to include FluentAssertions from the template.
45

56
## Bug fixes:
67
* Fix: Formatters incorrectly handle Unicode text file content of attachments.

Templates/Reqnroll.Templates.DotNet/templates/reqnroll-project/.template.config/dotnetcli.host.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
"targetFramework": {
88
"longName": "framework",
99
"shortName": "f"
10-
},
11-
"includeFluentAssertions": {
12-
"longName": "includeFluentAssertions",
13-
"shortName": "fa"
1410
}
1511
}
1612
}

Templates/Reqnroll.Templates.DotNet/templates/reqnroll-project/.template.config/template.json

Lines changed: 130 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -10,134 +10,141 @@
1010
"type": "project"
1111
},
1212
"sourceName": "Template",
13-
"symbols": {
14-
"targetFramework": {
15-
"type": "parameter",
16-
"description": "Target Framework",
17-
"datatype": "choice",
18-
"defaultValue": "net8.0",
19-
"replaces": "$target$",
20-
"choices": [
21-
{
22-
"choice": "net8.0",
23-
"description": ".NET 8.0"
24-
},
25-
{
26-
"choice": "net9.0",
27-
"description": ".NET 9.0"
28-
},
29-
{
30-
"choice": "net462",
31-
"description": ".NET Framework 4.6.2"
32-
},
33-
{
34-
"choice": "net472",
35-
"description": ".NET Framework 4.7.2"
36-
},
37-
{
38-
"choice": "net481",
39-
"description": ".NET Framework 4.8.1"
40-
}
41-
]
13+
"symbols": {
14+
"targetFramework": {
15+
"type": "parameter",
16+
"description": "Target Framework",
17+
"datatype": "choice",
18+
"defaultValue": "net8.0",
19+
"replaces": "$target$",
20+
"choices": [
21+
{
22+
"choice": "net8.0",
23+
"description": ".NET 8.0"
4224
},
43-
"testExecutionFramework": {
44-
"type": "parameter",
45-
"description": "Test Execution Framework",
46-
"datatype": "choice",
47-
"defaultValue": "nunit",
48-
"choices": [
49-
{
50-
"choice": "xunit",
51-
"description": "xUnit"
52-
},
53-
{
54-
"choice": "nunit",
55-
"description": "NUnit"
56-
},
57-
{
58-
"choice": "mstest",
59-
"description": "MSTest"
60-
},
61-
{
62-
"choice": "tunit",
63-
"description": "TUnit"
64-
}
65-
]
25+
{
26+
"choice": "net9.0",
27+
"description": ".NET 9.0"
6628
},
67-
"includeFluentAssertions": {
68-
"type": "parameter",
69-
"datatype": "bool",
70-
"description": "Add FluentAssertions library",
71-
"defaultValue": "true"
29+
{
30+
"choice": "net10.0",
31+
"description": ".NET 10.0"
7232
},
73-
"ReqnrollNugetPackages": {
74-
"type": "generated",
75-
"generator": "switch",
76-
"replaces": "$ReqnrollNugetPackages$",
77-
"parameters": {
78-
"evaluator": "C++",
79-
"datatype": "string",
80-
"cases": [
81-
{
82-
"condition": "(testExecutionFramework == 'xunit')",
83-
"value": "<PackageReference Include=\"Reqnroll.xUnit\" Version=\"$$$NuGetPackageVersion$$$\" />"
84-
},
85-
{
86-
"condition": "(testExecutionFramework == 'mstest')",
87-
"value": "<PackageReference Include=\"Reqnroll.MsTest\" Version=\"$$$NuGetPackageVersion$$$\" />"
88-
},
89-
{
90-
"condition": "(testExecutionFramework == 'nunit')",
91-
"value": "<PackageReference Include=\"Reqnroll.NUnit\" Version=\"$$$NuGetPackageVersion$$$\" />"
92-
},
93-
{
94-
"condition": "(testExecutionFramework == 'tunit')",
95-
"value": "<PackageReference Include=\"Reqnroll.TUnit\" Version=\"$$$NuGetPackageVersion$$$\" />"
96-
}
97-
]
98-
}
33+
{
34+
"choice": "net462",
35+
"description": ".NET Framework 4.6.2"
9936
},
100-
"AdditionalNugetPackages": {
101-
"type": "generated",
102-
"generator": "switch",
103-
"replaces": "$additionalNugetPackages$",
104-
"parameters": {
105-
"evaluator": "C++",
106-
"datatype": "string",
107-
"cases": [
108-
{
109-
"condition": "(testExecutionFramework == 'xunit')",
110-
"value": "<PackageReference Include=\"xunit\" Version=\"2.6.6\" />\n <PackageReference Include=\"xunit.runner.visualstudio\" Version=\"2.5.6\">\n <PrivateAssets>all</PrivateAssets>\n <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>\n </PackageReference>"
111-
},
112-
{
113-
"condition": "(testExecutionFramework == 'mstest')",
114-
"value": "<PackageReference Include=\"MSTest.TestFramework\" Version=\"3.1.1\" />\n <PackageReference Include=\"MSTest.TestAdapter\" Version=\"3.1.1\" />"
115-
},
116-
{
117-
"condition": "(testExecutionFramework == 'nunit')",
118-
"value": "<PackageReference Include=\"nunit\" Version=\"4.4.0\" />\n <PackageReference Include=\"NUnit3TestAdapter\" Version=\"5.2.0\" />"
119-
},
120-
{
121-
"condition": "(testExecutionFramework == 'tunit')",
122-
"value": "<PackageReference Include=\"TUnit\" Version=\"0.25.21\" />"
123-
}
124-
]
125-
}
37+
{
38+
"choice": "net472",
39+
"description": ".NET Framework 4.7.2"
12640
},
127-
"FluentAssertionsNugetPackage": {
128-
"type": "generated",
129-
"generator": "switch",
130-
"replaces": "$fluentAssertionsNugetPackage$",
131-
"parameters": {
132-
"evaluator": "C++",
133-
"datatype": "string",
134-
"cases": [
135-
{
136-
"condition": "(includeFluentAssertions)",
137-
"value": "<PackageReference Include=\"FluentAssertions\" Version=\"6.12.0\" />"
138-
}
139-
]
140-
}
41+
{
42+
"choice": "net481",
43+
"description": ".NET Framework 4.8.1"
14144
}
45+
]
46+
},
47+
"testExecutionFramework": {
48+
"type": "parameter",
49+
"description": "Test Execution Framework",
50+
"datatype": "choice",
51+
"defaultValue": "nunit",
52+
"choices": [
53+
{
54+
"choice": "xunit",
55+
"description": "xUnit"
56+
},
57+
{
58+
"choice": "xunit.v3",
59+
"description": "xUnit.v3"
60+
},
61+
{
62+
"choice": "nunit",
63+
"description": "NUnit"
64+
},
65+
{
66+
"choice": "mstest",
67+
"description": "MSTest"
68+
},
69+
{
70+
"choice": "tunit",
71+
"description": "TUnit"
72+
}
73+
]
74+
},
75+
"ReqnrollNugetPackages": {
76+
"type": "generated",
77+
"generator": "switch",
78+
"replaces": "$ReqnrollNugetPackages$",
79+
"parameters": {
80+
"evaluator": "C++",
81+
"datatype": "string",
82+
"cases": [
83+
{
84+
"condition": "(testExecutionFramework == 'xunit')",
85+
"value": "<PackageReference Include=\"Reqnroll.xUnit\" Version=\"$$$NuGetPackageVersion$$$\" />"
86+
},
87+
{
88+
"condition": "(testExecutionFramework == 'xunit.v3')",
89+
"value": "<PackageReference Include=\"Reqnroll.xunit.v3\" Version=\"$$$NuGetPackageVersion$$$\" />"
90+
},
91+
{
92+
"condition": "(testExecutionFramework == 'mstest')",
93+
"value": "<PackageReference Include=\"Reqnroll.MsTest\" Version=\"$$$NuGetPackageVersion$$$\" />"
94+
},
95+
{
96+
"condition": "(testExecutionFramework == 'nunit')",
97+
"value": "<PackageReference Include=\"Reqnroll.NUnit\" Version=\"$$$NuGetPackageVersion$$$\" />"
98+
},
99+
{
100+
"condition": "(testExecutionFramework == 'tunit')",
101+
"value": "<PackageReference Include=\"Reqnroll.TUnit\" Version=\"$$$NuGetPackageVersion$$$\" />"
102+
}
103+
]
104+
}
105+
},
106+
"AdditionalNugetPackages": {
107+
"type": "generated",
108+
"generator": "switch",
109+
"replaces": "$additionalNugetPackages$",
110+
"parameters": {
111+
"evaluator": "C++",
112+
"datatype": "string",
113+
"cases": [
114+
{
115+
"condition": "(testExecutionFramework == 'xunit')",
116+
"value": "<PackageReference Include=\"xunit\" Version=\"2.9.3\" />\n <PackageReference Include=\"xunit.runner.visualstudio\" Version=\"3.1.5\">\n <PrivateAssets>all</PrivateAssets>\n <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>\n </PackageReference>"
117+
},
118+
{
119+
"condition": "(testExecutionFramework == 'xunit.v3')",
120+
"value": "<PackageReference Include=\"xunit.v3\" Version=\"3.2.2\" />\n <PackageReference Include=\"xunit.runner.visualstudio\" Version=\"3.1.5\">\n <PrivateAssets>all</PrivateAssets>\n <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>\n </PackageReference>"
121+
},
122+
{
123+
"condition": "(testExecutionFramework == 'mstest')",
124+
"value": "<PackageReference Include=\"MSTest.TestFramework\" Version=\"4.1.0\" />\n <PackageReference Include=\"MSTest.TestAdapter\" Version=\"4.1.0\" />"
125+
},
126+
{
127+
"condition": "(testExecutionFramework == 'nunit')",
128+
"value": "<PackageReference Include=\"nunit\" Version=\"4.5.1\" />\n <PackageReference Include=\"NUnit3TestAdapter\" Version=\"6.1.0\" />"
129+
},
130+
{
131+
"condition": "(testExecutionFramework == 'tunit')",
132+
"value": "<PackageReference Include=\"TUnit\" Version=\"1.20.0\" />"
133+
}
134+
]
135+
}
136+
},
137+
"isNetFramework": {
138+
"type": "computed",
139+
"value": "(targetFramework == 'net462' || targetFramework == 'net472' || targetFramework == 'net481')"
140+
},
141+
"useImplicitUsings": {
142+
"type": "computed",
143+
"value": "(!isNetFramework)"
144+
},
145+
"includeMicrosoftNetTestSdk": {
146+
"type": "computed",
147+
"value": "(!( testExecutionFramework == 'tunit' ) )"
142148
}
149+
}
143150
}

Templates/Reqnroll.Templates.DotNet/templates/reqnroll-project/StepDefinitions/CalculatorStepDefinitions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
<!--#if (!useImplicitUsings) -->
12
using Reqnroll;
3+
<!--#endif -->
24

35
namespace Template.StepDefinitions;
46

Templates/Reqnroll.Templates.DotNet/templates/reqnroll-project/Template.csproj

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,35 @@
22

33
<PropertyGroup>
44
<TargetFramework>$target$</TargetFramework>
5+
<!--#if (useImplicitUsings) -->
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<!--#endif -->
9+
<!--#if (testExecutionFramework == "tunit") -->
10+
<OutputType>Exe</OutputType>
11+
<!--#endif -->
512
</PropertyGroup>
613

714
<ItemGroup>
15+
<!--#if (includeMicrosoftNetTestSdk) -->
816
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
17+
<!--#endif -->
918
$ReqnrollNugetPackages$
1019
$additionalNugetPackages$
11-
$fluentAssertionsNugetPackage$
1220
</ItemGroup>
1321

22+
<!--#if (useImplicitUsings) -->
23+
<ItemGroup>
24+
<Using Include="Reqnroll" />
25+
<!--#if (testExecutionFramework == "mstest") -->
26+
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
27+
<!--#endif -->
28+
<!--#if (testExecutionFramework == "nunit") -->
29+
<Using Include="NUnit.Framework" />
30+
<!--#endif -->
31+
<!--#if (testExecutionFramework == "xunit" || testExecutionFramework == "xunit.v3") -->
32+
<Using Include="Xunit" />
33+
<!--#endif -->
34+
</ItemGroup>
35+
<!--#endif -->
1436
</Project>

0 commit comments

Comments
 (0)