Skip to content

Commit

Permalink
Use the new MessagePack source generator instead of the old dotnet tool
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZidar committed May 12, 2024
1 parent 45060bf commit 70c6abb
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 41 deletions.
12 changes: 3 additions & 9 deletions .build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,25 @@ task AssertVersion {
}
}

task DotnetToolRestore {
exec {
dotnet tool restore
}
}

task DotnetRestore {
exec {
dotnet restore
}
}

task DotnetFormat DotnetToolRestore, DotnetRestore, {
task DotnetFormat DotnetRestore, {
exec {
dotnet format --no-restore
}
}

task DotnetFormatCheck DotnetToolRestore, DotnetRestore, {
task DotnetFormatCheck DotnetRestore, {
exec {
dotnet format --no-restore --verify-no-changes
}
}

task DotnetBuild DotnetToolRestore, DotnetRestore, {
task DotnetBuild DotnetRestore, {
exec {
dotnet build --no-restore
}
Expand Down
12 changes: 0 additions & 12 deletions .config/dotnet-tools.json

This file was deleted.

1 change: 1 addition & 0 deletions samples/ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<OutputType>Exe</OutputType>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions samples/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="MessagePack" Version="3.0.54-alpha" />
<PackageVersion Include="MessagePackAnalyzer" Version="3.0.54-alpha" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="TinyLogger" Version="1.9.0" />
Expand Down
11 changes: 3 additions & 8 deletions samples/GenericHost/GenericHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<OutputType>Exe</OutputType>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MessagePack" />
<PackageReference Include="MessagePackAnalyzer" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="TinyLogger" />
Expand All @@ -15,12 +18,4 @@
<ProjectReference Include="..\..\src\TinyIpc\TinyIpc.csproj" />
</ItemGroup>

<Target Name="GenerateMessagePack" BeforeTargets="CoreCompile" Inputs="@(Compile)" Outputs="$(IntermediateOutputPath)\MessagePack.Generated.cs">
<Exec Command="dotnet mpc -input $(MSBuildProjectDirectory) -output $(IntermediateOutputPath)\MessagePack.Generated.cs -resolverName GenericHostGeneratedResolver" />
<ItemGroup>
<Compile Remove="$(IntermediateOutputPath)\MessagePack.Generated.cs" />
<Compile Include="$(IntermediateOutputPath)\MessagePack.Generated.cs" />
</ItemGroup>
</Target>

</Project>
2 changes: 1 addition & 1 deletion samples/GenericHost/MessagePackOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class MessagePackOptions
MessagePackSerializerOptions.Standard
.WithResolver(
CompositeResolver.Create(
GenericHostGeneratedResolver.Instance,
MessageResolver.Instance,
StandardResolver.Instance
)
);
Expand Down
3 changes: 3 additions & 0 deletions samples/GenericHost/WorkerMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace GenericHost;

[GeneratedMessagePackResolver]
public partial class MessageResolver;

[MessagePackObject]
public class WorkerMessage
{
Expand Down
3 changes: 2 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="MessagePack" Version="2.5.140" />
<PackageVersion Include="MessagePack" Version="3.0.54-alpha" />
<PackageVersion Include="MessagePackAnalyzer" Version="3.0.54-alpha" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
Expand Down
3 changes: 2 additions & 1 deletion src/TinyIpc/MessagePackOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MessagePack;
using MessagePack.Resolvers;
using TinyIpc.Messaging;

namespace TinyIpc;

Expand All @@ -9,7 +10,7 @@ internal static class MessagePackOptions
MessagePackSerializerOptions.Standard
.WithResolver(
CompositeResolver.Create(
TinyIpcGeneratedResolver.Instance,
LogBookResolver.Instance,
StandardResolver.Instance
)
);
Expand Down
3 changes: 3 additions & 0 deletions src/TinyIpc/Messaging/TinyMessageBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ private static LogBook DeserializeLogBook(Stream stream)
private static partial void LogReceiveError(ILogger logger, Exception exception, long id);
}

[GeneratedMessagePackResolver]
public partial class LogBookResolver;

[MessagePackObject]
public sealed class LogBook
{
Expand Down
11 changes: 2 additions & 9 deletions src/TinyIpc/TinyIpc.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
Expand All @@ -16,6 +16,7 @@

<ItemGroup>
<PackageReference Include="MessagePack" />
<PackageReference Include="MessagePackAnalyzer" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options" />
Expand All @@ -26,12 +27,4 @@
<PackageReference Include="System.Threading.Channels" />
</ItemGroup>

<Target Name="GenerateMessagePack" BeforeTargets="CoreCompile" Inputs="@(Compile)" Outputs="$(IntermediateOutputPath)\MessagePack.Generated.cs">
<Exec Command="dotnet mpc -input $(MSBuildProjectDirectory) -output $(IntermediateOutputPath)\MessagePack.Generated.cs -resolverName TinyIpcGeneratedResolver" />
<ItemGroup>
<Compile Remove="$(IntermediateOutputPath)\MessagePack.Generated.cs" />
<Compile Include="$(IntermediateOutputPath)\MessagePack.Generated.cs" />
</ItemGroup>
</Target>

</Project>

0 comments on commit 70c6abb

Please sign in to comment.