Skip to content

Commit c4debea

Browse files
authored
adjust defaultBenchmarkDotNetVersion on build (#1879)
* adjust defaultBenchmarkDotNetVersion on build * fix #1879 (comment) * fix #1879 (comment) * fix #1879 (comment) * add install-from-source.sh (for macOS for example) * fix copy paste
1 parent 609e484 commit c4debea

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

build/common.props

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,28 @@
6262
<PrivateAssets>all</PrivateAssets>
6363
</PackageReference>
6464
</ItemGroup>
65+
66+
<UsingTask TaskName="ReplaceFileText"
67+
TaskFactory="RoslynCodeTaskFactory"
68+
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
69+
<ParameterGroup>
70+
<InputFilename ParameterType="System.String" Required="true" />
71+
<OutputFilename ParameterType="System.String" Required="true" />
72+
<MatchExpression ParameterType="System.String" Required="true" />
73+
<ReplacementText ParameterType="System.String" Required="true" />
74+
</ParameterGroup>
75+
<Task>
76+
<Using Namespace="System" />
77+
<Using Namespace="System.IO" />
78+
<Using Namespace="System.Text.RegularExpressions" />
79+
<Code Type="Fragment" Language="cs">
80+
<![CDATA[
81+
File.WriteAllText(
82+
OutputFilename,
83+
Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
84+
);
85+
]]>
86+
</Code>
87+
</Task>
88+
</UsingTask>
6589
</Project>

templates/BenchmarkDotNet.Templates.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,25 @@
2424
<Compile Remove="**\*" />
2525
<None Remove="*.bat;.sh" />
2626
</ItemGroup>
27+
28+
<Target Name="Fix BenchmarkDotNetVersion"
29+
BeforeTargets="Build">
30+
<ReplaceFileText
31+
InputFilename="templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json"
32+
OutputFilename="templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json"
33+
MatchExpression='("defaultValue": )"([\d+\.?]+)"'
34+
ReplacementText='${1}"$(VersionPrefix)"' />
35+
36+
<ReplaceFileText
37+
InputFilename="templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json"
38+
OutputFilename="templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json"
39+
MatchExpression='("defaultValue": )"([\d+\.?]+)"'
40+
ReplacementText='${1}"$(VersionPrefix)"' />
41+
42+
<ReplaceFileText
43+
InputFilename="templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json"
44+
OutputFilename="templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json"
45+
MatchExpression='("defaultValue": )"([\d+\.?]+)"'
46+
ReplacementText='${1}"$(VersionPrefix)"' />
47+
</Target>
2748
</Project>

templates/install-from-source.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Run only from the folder where the shell script is located!
2+
3+
dotnet build BenchmarkDotNet.Templates.csproj -c Release
4+
dotnet pack BenchmarkDotNet.Templates.csproj -c Release
5+
6+
# If we install the templates via a folder path, then it will have a different ID (ID=folder path).
7+
# It will conflict with BDN templates from nuget.
8+
# We need to install the templates via a FILE path in order to update the template from nuget.
9+
10+
nupkg_path=$(find . -name "BenchmarkDotNet.Templates*.nupkg")
11+
12+
dotnet new uninstall "BenchmarkDotNet.Templates"
13+
dotnet new install $nupkg_path

0 commit comments

Comments
 (0)