简体   繁体   English

适用于C#的Protobuf工具链/插件

[英]Protobuf toolchain/plugin for C#

In my company we already have a Java project (build by Maven) that is compiling proto files into Java via maven-protoc-plugin . 在我的公司中,我们已经有一个Java项目(由Maven构建),该项目通过maven-protoc-plugin将原型文件编译为Java。 Right now we are trying to do the same for C# (MSbuild + NuGet). 现在,我们正在尝试对C#(MSbuild + NuGet)执行相同的操作。

My problem is that I cannot find any toolchain for MSbuild that will compile proto into C# classes. 我的问题是我找不到用于将Proto编译成C#类的MSbuild工具链。 I already have installed Google Protobuf for .NET 4.0 via NuGet. 我已经通过NuGet安装了Google Protobuf for .NET 4.0

I want to use protobuf 2 with VisualStudio 2013 我想在Visual Studio 2013中使用protobuf 2

PS My main programming language is Java and I really suck at C# so please speak to me really slow ;). PS我的主要编程语言是Java,我真的很喜欢C#,所以请慢点跟我说;)。

I agree with the recommendation of protobuf-net 我同意protobuf-net的建议
The tool for creating classes out of .proto file is called protogen. 用于从.proto文件中创建类的工具称为protogen。

protogen -i:test2.proto -o:test2.cs protogen -i:test2.proto -o:test2.cs

Typically one would define Pre-Build Build Event in VS which will trigger the recreation of the classes before the actual compilation. 通常,将在VS中定义预构建构建事件,该事件将在实际编译之前触发类的重新创建。

You want protobuf-net ! 您想要protobuf-net It'll do everything you need! 它会做您需要的一切!

Seriously though, it'll allow you to avoid using .proto files if you want by marking a class/property with attributes. 严重的是,如果需要,可以通过使用属性标记类/属性来避免使用.proto文件。 However, it also comes with a pre-compiler to process your existing .proto files into C# classes. 但是,它还带有一个预编译器,用于将您现有的.proto文件处理为C#类。 We use it on a large-scale project and it works really well. 我们将其用于大型项目,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM