Skip to content

Commit 3c9d2e2

Browse files
authored
Dotnet tool support (#213)
* Support .net 8+ for tool install
1 parent 609d2f7 commit 3c9d2e2

6 files changed

Lines changed: 35 additions & 10 deletions

File tree

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,36 @@ A simulator that provides endpoints to mimic the functionality of [Azure Event G
1313

1414
### .NET Tool (Recommended)
1515

16-
Install as a global .NET tool:
16+
Requires .NET 8.0 SDK or later. Supports .NET 8.0, 9.0, and 10.0.
1717

18-
```bash
19-
dotnet tool install -g AzureEventGridSimulator
20-
```
18+
#### Global Install
2119

22-
Then run with:
20+
Install once, use from anywhere:
2321

2422
```bash
23+
dotnet tool install -g AzureEventGridSimulator
2524
azure-eventgrid-simulator
2625
```
2726

28-
To update to the latest version:
27+
To update: `dotnet tool update -g AzureEventGridSimulator`
28+
29+
#### Local Install (Project-level)
30+
31+
Install per-project for team consistency and version control:
2932

3033
```bash
31-
dotnet tool update -g AzureEventGridSimulator
34+
# Create tool manifest if it doesn't exist
35+
dotnet new tool-manifest
36+
37+
# Install the tool
38+
dotnet tool install AzureEventGridSimulator
39+
40+
# Run it
41+
dotnet tool run azure-eventgrid-simulator
3242
```
3343

44+
The tool manifest (`.config/dotnet-tools.json`) can be committed to source control. Team members just run `dotnet tool restore` after cloning.
45+
3446
### Docker
3547

3648
See the [Docker](#docker) section below for running via Docker.

src/AzureEventGridSimulator/AzureEventGridSimulator.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3+
<!-- Multi-target for .NET Tool compatibility (clears TargetFramework from Directory.Build.props) -->
4+
<TargetFramework></TargetFramework>
5+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
36
<IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
47

58
<!-- .NET Tool packaging -->
69
<IsPackable>true</IsPackable>
710
<PackAsTool>true</PackAsTool>
11+
<RollForward>LatestMinor</RollForward>
12+
<TargetLatestRuntimePatch>false</TargetLatestRuntimePatch>
813
<ToolCommandName>azure-eventgrid-simulator</ToolCommandName>
914
<PackageId>AzureEventGridSimulator</PackageId>
1015
<PackageOutputPath>./nupkg</PackageOutputPath>

src/AzureEventGridSimulator/Infrastructure/Extensions/KestrelServerOptionsExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ this KestrelServerOptions options
2424
if (certificateFileSpecified && certificatePasswordSpecified)
2525
{
2626
// The certificate file and password was specified.
27+
#if NET9_0_OR_GREATER
2728
certificate = X509CertificateLoader.LoadPkcs12FromFile(
2829
certificateFile,
2930
certificatePassword
3031
);
32+
#else
33+
certificate = new X509Certificate2(certificateFile, certificatePassword);
34+
#endif
3135
}
3236
else if (certificateFileSpecified && !certificatePasswordSpecified)
3337
{

src/AzureEventGridSimulator/Infrastructure/Settings/Subscribers/HttpSubscriberSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public class HttpSubscriberSettings : ISubscriberSettings
5050

5151
public Guid GetValidationCode()
5252
{
53-
return new Guid(Encoding.UTF8.GetBytes(Endpoint).Reverse().Take(16).ToArray());
53+
return new Guid(
54+
Encoding.UTF8.GetBytes(Endpoint).AsEnumerable().Reverse().Take(16).ToArray()
55+
);
5456
}
5557

5658
public void Validate()

src/AzureEventGridSimulator/Infrastructure/Settings/SubscriptionSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class SubscriptionSettings
4444

4545
public Guid GetValidationCode()
4646
{
47-
return new Guid(Encoding.UTF8.GetBytes(Endpoint).Reverse().Take(16).ToArray());
47+
return new Guid(
48+
Encoding.UTF8.GetBytes(Endpoint).AsEnumerable().Reverse().Take(16).ToArray()
49+
);
4850
}
4951
}

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Target
1818
Name="CSharpier"
1919
BeforeTargets="BeforeBuild"
20-
Condition="'$(DesignTimeBuild)' != 'true' And '$(MSBuildProjectName)' == 'AzureEventGridSimulator'"
20+
Condition="'$(DesignTimeBuild)' != 'true' And '$(MSBuildProjectName)' == 'AzureEventGridSimulator' And '$(TargetFramework)' == 'net10.0'"
2121
>
2222
<Exec
2323
Command="dotnet tool restore"

0 commit comments

Comments
 (0)