From f87ead8b41a4273c729e3d72414cf4a6ab9c51b8 Mon Sep 17 00:00:00 2001 From: Yegor Stepanov Date: Tue, 20 Jun 2023 14:55:45 +0300 Subject: [PATCH 1/7] Fix batch file --- templates/install-from-source.bat | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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 From 1b0b518adbde240c44dd047ab49afbf05fab827e Mon Sep 17 00:00:00 2001 From: Yegor Stepanov Date: Wed, 21 Jun 2023 10:48:52 +0300 Subject: [PATCH 2/7] Update Program.cs --- .../Program.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 From b94a00ca3af25152936d0338d2f4150fe4a8c39a Mon Sep 17 00:00:00 2001 From: Yegor Stepanov Date: Tue, 20 Jun 2023 02:57:25 +0300 Subject: [PATCH 3/7] Fix type of framework parameter --- .../.template.config/template.json | 54 +++++++++++++++++-- .../.template.config/template.json | 54 +++++++++++++++++-- .../.template.config/template.json | 54 +++++++++++++++++-- 3 files changed, 150 insertions(+), 12 deletions(-) diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json index d078cb9d9f..efa4d21bf0 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)", @@ -98,7 +144,7 @@ "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.FSharp/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json index 43d30c88cc..a91ebd322b 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)", @@ -98,7 +144,7 @@ "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..1a678c195f 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)", @@ -98,7 +144,7 @@ "type": "parameter", "datatype": "string", "description": "Version of BenchmarkDotNet that will be referenced.", - "defaultValue": "0.12.1", + "defaultValue": "0.13.5", "replaces": "$(BenchmarkDotNetVersion)" } }, From bbe43af4526d65495123dd3950ae23c0caf459ba Mon Sep 17 00:00:00 2001 From: Yegor Stepanov Date: Wed, 21 Jun 2023 16:09:38 +0300 Subject: [PATCH 4/7] Fix docs --- docs/articles/guides/dotnet-new-templates.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/articles/guides/dotnet-new-templates.md b/docs/articles/guides/dotnet-new-templates.md index a11064a1f2..dc47ed0407 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,7 +43,7 @@ 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. +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: ```log From e93e60fcad861ebf5dbce4785a5e160431b1c485 Mon Sep 17 00:00:00 2001 From: Yegor Stepanov Date: Sat, 1 Jul 2023 13:01:38 +0300 Subject: [PATCH 5/7] Set consoleApp=true by default --- .../.template.config/template.json | 2 +- .../.template.config/template.json | 2 +- .../.template.config/template.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json index efa4d21bf0..1dadbd681b 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json @@ -138,7 +138,7 @@ "type": "parameter", "datatype": "bool", "description": "If specified, the project is set up as console app.", - "defaultValue": "false" + "defaultValue": "true" }, "version": { "type": "parameter", diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json index a91ebd322b..fe80939f35 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json @@ -138,7 +138,7 @@ "type": "parameter", "datatype": "bool", "description": "If specified, the project is set up as console app.", - "defaultValue": "false" + "defaultValue": "true" }, "version": { "type": "parameter", diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json index 1a678c195f..bb0873fa1b 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json @@ -138,7 +138,7 @@ "type": "parameter", "datatype": "bool", "description": "If specified, the project is set up as console app.", - "defaultValue": "false" + "defaultValue": "true" }, "version": { "type": "parameter", From 5189f50fe3a9883bd6360eb3bba98bb524dcde13 Mon Sep 17 00:00:00 2001 From: Yegor Stepanov Date: Sat, 1 Jul 2023 13:45:46 +0300 Subject: [PATCH 6/7] Remove outdated info. The parameter was changed in #1632 --- docs/articles/guides/dotnet-new-templates.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/articles/guides/dotnet-new-templates.md b/docs/articles/guides/dotnet-new-templates.md index dc47ed0407..aae2ca57dd 100644 --- a/docs/articles/guides/dotnet-new-templates.md +++ b/docs/articles/guides/dotnet-new-templates.md @@ -44,10 +44,10 @@ 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: +You can specify `-f` or `--framework` to change 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: @@ -57,7 +57,6 @@ dotnet new benchmark --console-app ``` 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: From 56a81ae4df9b92a779dea95486a0ade416c513d0 Mon Sep 17 00:00:00 2001 From: Yegor Stepanov Date: Sat, 1 Jul 2023 13:51:22 +0300 Subject: [PATCH 7/7] Update docs --- docs/articles/guides/dotnet-new-templates.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/articles/guides/dotnet-new-templates.md b/docs/articles/guides/dotnet-new-templates.md index aae2ca57dd..e76ae70c4e 100644 --- a/docs/articles/guides/dotnet-new-templates.md +++ b/docs/articles/guides/dotnet-new-templates.md @@ -43,21 +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 `--framework` to change the target framework: +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 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. - The option `-b` or `--benchmarkName` sets the name of the benchmark class: ```log