3 Star 4 Fork 2

Gitee 极速下载/MessagePack-CSharp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/aspnet/MessagePack-CSharp.git
克隆/下载
msbuildtask.md 2.23 KB
一键复制 编辑 原始数据 按行查看 历史

MessagePack Compiler via MSBuild Task

Cold startup performance and AOT environments can benefit by pre-compiling the specialized code for serializing and deserializing your custom types.

Install the MessagePack.MSBuild.Tasks NuGet package in your project: NuGet

This package automatically gets the MessagePack Compiler (mpc) to run during the build to produce a source file in the intermediate directory and adds it to the compilation, consumable in the normal way:

using System;
using MessagePack;
using MessagePack.Resolvers;

class Program
{
    static void Main(string[] args)
    {
        var o = new SomeObject { SomeMember = "hi" };

        var options = MessagePackSerializerOptions.Standard.WithResolver(
            CompositeResolver.Create(
                GeneratedResolver.Instance,
                StandardResolver.Instance
            ));
        byte[] b = MessagePackSerializer.Serialize(o, options);
        var o2 = MessagePackSerializer.Deserialize<SomeObject>(b, options);
        Console.WriteLine(o2.SomeMember);
    }
}

[MessagePackObject]
public class SomeObject
{
    [Key(0)]
    public string SomeMember { get; set; }
}

Customizations

A few MSBuild properties can be set in your project to customize mpc:

Property Purpose Default value
MessagePackGeneratedResolverNamespace The prefix for the namespace under which code will be generated. .Formatters is always appended to this value. MessagePack
MessagePackGeneratedResolverName The name of the generated type. GeneratedResolver
MessagePackGeneratedUsesMapMode A boolean value that indicates whether all formatters should use property maps instead of more compact arrays. false

For example you could add this xml to your project file to set each of the above properties (in this example, to their default values):

<PropertyGroup>
 <MessagePackGeneratedResolverNamespace>MessagePack</MessagePackGeneratedResolverNamespace>
 <MessagePackGeneratedResolverName>GeneratedResolver</MessagePackGeneratedResolverName>
 <MessagePackGeneratedUsesMapMode>false</MessagePackGeneratedUsesMapMode>
</PropertyGroup>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/mirrors/MessagePack-CSharp.git
git@gitee.com:mirrors/MessagePack-CSharp.git
mirrors
MessagePack-CSharp
MessagePack-CSharp
master

搜索帮助