diff --git a/docs/articles/guides/dotnet-new-templates.md b/docs/articles/guides/dotnet-new-templates.md index a11064a1f2..e76ae70c4e 100644 --- a/docs/articles/guides/dotnet-new-templates.md +++ b/docs/articles/guides/dotnet-new-templates.md @@ -5,7 +5,7 @@ name: BenchmarkDotNet templates # BenchmarkDotNet templates -BenchmarkDotNet provides project templates to setup your benchmarks easily +BenchmarkDotNet provides project templates to setup your benchmarks easily. The template exists for each major .NET language ([C#](https://learn.microsoft.com/dotnet/csharp/), [F#](https://learn.microsoft.com/dotnet/fsharp/) and [VB](https://learn.microsoft.com/dotnet/visual-basic/)) with equivalent features and structure. ## How to install the templates @@ -43,22 +43,21 @@ dotnet new benchmark -lang VB The template projects has five additional options - all of them are optional. -By default a class library project targeting netstandard2.0 is created. -You can specify `-f` or `--frameworks` to change targeting to one or more frameworks: +By default a console app project targeting `net6.0` is created. +This lets you run the benchmarks from console (`dotnet run`) or from your favorite IDE. + +The option `-f` or `--framework` changes the target framework: ```log -dotnet new benchmark -f netstandard2.0;net472 +dotnet new benchmark -f net472 ``` -The option `--console-app` creates a console app project targeting `netcoreapp3.0` with an entry point: +You can specify `--console-app=false` to create a class library project targeting `netstandard2.0` by default: ```log -dotnet new benchmark --console-app +dotnet new benchmark --console-app=false ``` -This lets you run the benchmarks from console (`dotnet run`) or from your favorite IDE. -**Note:** option `-f` or `--frameworks` will be ignored when `--console-app` is set. - The option `-b` or `--benchmarkName` sets the name of the benchmark class: ```log diff --git a/templates/install-from-source.bat b/templates/install-from-source.bat index 30f65444f4..f399defbbc 100644 --- a/templates/install-from-source.bat +++ b/templates/install-from-source.bat @@ -1,4 +1,14 @@ -dotnet build -c Release BenchmarkDotNet.Templates.csproj -dotnet pack -c Release BenchmarkDotNet.Templates.csproj -dotnet new -u BenchmarkDotNet.Templates -dotnet new -i BenchmarkDotNet.Templates::0.0.0-* --nuget-source .\bin\Release\ \ No newline at end of file +:: Run only from the folder where the batch file is located! + +dotnet build BenchmarkDotNet.Templates.csproj -c Release +dotnet pack BenchmarkDotNet.Templates.csproj -c Release + +:: If we install the templates via a folder path, then it will have a different ID (ID=folder path). +:: It will conflict with BDN templates from nuget. +:: We need to install the templates via a FILE path in order to update the template from nuget. +:: +:: https://stackoverflow.com/questions/47450531/batch-write-output-of-dir-to-a-variable +for /f "delims=" %%a in ('dir /s /b BenchmarkDotNet.Templates*.nupkg') do set "nupkg_path=%%a" + +dotnet new --uninstall "BenchmarkDotNet.Templates" +dotnet new --install "%nupkg_path%" \ No newline at end of file diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json index d078cb9d9f..1dadbd681b 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json @@ -31,8 +31,54 @@ }, "framework": { "type": "parameter", - "datatype": "string", - "description": "The target framework for the project (e.g. netstandard2.0). Default \"net5.0\" if \"--console-app\" is true, \"netstandard2.0\" if \"--console-app\" is false", + "description": "The target framework for the project.", + "datatype": "choice", + "choices": [ + { + "choice": "net8.0", + "description": ".NET 8" + }, + { + "choice": "net7.0", + "description": ".NET 7" + }, + { + "choice": "net6.0", + "description": ".NET 6" + }, + { + "choice": "netstandard2.1", + "description": ".NET Standard 2.1" + }, + { + "choice": "netstandard2.0", + "description": ".NET Standard 2.0" + }, + { + "choice": "net481", + "description": ".NET Framework 4.8.1" + }, + { + "choice": "net48", + "description": ".NET Framework 4.8" + }, + { + "choice": "net472", + "description": ".NET Framework 4.7.2" + }, + { + "choice": "net471", + "description": ".NET Framework 4.7.1" + }, + { + "choice": "net47", + "description": ".NET Framework 4.7" + }, + { + "choice": "net462", + "description": ".NET Framework 4.6.2" + } + ], "defaultValue": "" }, "frameworkDefault": { @@ -45,7 +91,7 @@ "cases": [ { "condition": "(framework == '' && consoleApp == true)", - "value": "net5.0" + "value": "net6.0" }, { "condition": "(framework == '' && consoleApp == false)", @@ -92,13 +138,13 @@ "type": "parameter", "datatype": "bool", "description": "If specified, the project is set up as console app.", - "defaultValue": "false" + "defaultValue": "true" }, "version": { "type": "parameter", "datatype": "string", "description": "Version of BenchmarkDotNet that will be referenced.", - "defaultValue": "0.12.1", + "defaultValue": "0.13.5", "replaces": "$(BenchmarkDotNetVersion)" } }, diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/Program.cs b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/Program.cs index 3972b67f8d..34cf88b3bb 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/Program.cs +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/Program.cs @@ -1,3 +1,4 @@ +using BenchmarkDotNet.Configs; using BenchmarkDotNet.Running; namespace _BenchmarkProjectName_ @@ -6,7 +7,11 @@ public class Program { public static void Main(string[] args) { - var summary = BenchmarkRunner.Run<$(BenchmarkName)>(); + var config = DefaultConfig.Instance; + var summary = BenchmarkRunner.Run<$(BenchmarkName)>(config, args); + + // Use this to select benchmarks from the console: + // var summaries = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); } } } \ No newline at end of file diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json index 43d30c88cc..fe80939f35 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json @@ -31,8 +31,54 @@ }, "framework": { "type": "parameter", - "datatype": "string", - "description": "The target framework for the project (e.g. netstandard2.0). Default \"net5.0\" if \"--console-app\" is true, \"netstandard2.0\" if \"--console-app\" is false", + "description": "The target framework for the project.", + "datatype": "choice", + "choices": [ + { + "choice": "net8.0", + "description": ".NET 8" + }, + { + "choice": "net7.0", + "description": ".NET 7" + }, + { + "choice": "net6.0", + "description": ".NET 6" + }, + { + "choice": "netstandard2.1", + "description": ".NET Standard 2.1" + }, + { + "choice": "netstandard2.0", + "description": ".NET Standard 2.0" + }, + { + "choice": "net481", + "description": ".NET Framework 4.8.1" + }, + { + "choice": "net48", + "description": ".NET Framework 4.8" + }, + { + "choice": "net472", + "description": ".NET Framework 4.7.2" + }, + { + "choice": "net471", + "description": ".NET Framework 4.7.1" + }, + { + "choice": "net47", + "description": ".NET Framework 4.7" + }, + { + "choice": "net462", + "description": ".NET Framework 4.6.2" + } + ], "defaultValue": "" }, "frameworkDefault": { @@ -45,7 +91,7 @@ "cases": [ { "condition": "(framework == '' && consoleApp == true)", - "value": "net5.0" + "value": "net6.0" }, { "condition": "(framework == '' && consoleApp == false)", @@ -92,13 +138,13 @@ "type": "parameter", "datatype": "bool", "description": "If specified, the project is set up as console app.", - "defaultValue": "false" + "defaultValue": "true" }, "version": { "type": "parameter", "datatype": "string", "description": "Version of BenchmarkDotNet that will be referenced.", - "defaultValue": "0.12.1", + "defaultValue": "0.13.5", "replaces": "$(BenchmarkDotNetVersion)" } }, diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json index 923c83620e..bb0873fa1b 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json @@ -31,8 +31,54 @@ }, "framework": { "type": "parameter", - "datatype": "string", - "description": "The target framework for the project (e.g. netstandard2.0). Default \"net5.0\" if \"--console-app\" is true, \"netstandard2.0\" if \"--console-app\" is false", + "description": "The target framework for the project.", + "datatype": "choice", + "choices": [ + { + "choice": "net8.0", + "description": ".NET 8" + }, + { + "choice": "net7.0", + "description": ".NET 7" + }, + { + "choice": "net6.0", + "description": ".NET 6" + }, + { + "choice": "netstandard2.1", + "description": ".NET Standard 2.1" + }, + { + "choice": "netstandard2.0", + "description": ".NET Standard 2.0" + }, + { + "choice": "net481", + "description": ".NET Framework 4.8.1" + }, + { + "choice": "net48", + "description": ".NET Framework 4.8" + }, + { + "choice": "net472", + "description": ".NET Framework 4.7.2" + }, + { + "choice": "net471", + "description": ".NET Framework 4.7.1" + }, + { + "choice": "net47", + "description": ".NET Framework 4.7" + }, + { + "choice": "net462", + "description": ".NET Framework 4.6.2" + } + ], "defaultValue": "" }, "frameworkDefault": { @@ -45,7 +91,7 @@ "cases": [ { "condition": "(framework == '' && consoleApp == true)", - "value": "net5.0" + "value": "net6.0" }, { "condition": "(framework == '' && consoleApp == false)", @@ -92,13 +138,13 @@ "type": "parameter", "datatype": "bool", "description": "If specified, the project is set up as console app.", - "defaultValue": "false" + "defaultValue": "true" }, "version": { "type": "parameter", "datatype": "string", "description": "Version of BenchmarkDotNet that will be referenced.", - "defaultValue": "0.12.1", + "defaultValue": "0.13.5", "replaces": "$(BenchmarkDotNetVersion)" } },