简体   繁体   English

在将原型转换为C#的同时获得期望的顶级语句(例如“消息”)

[英]Getting Expected top-level statement (e.g. “message”).while converting proto to C#

I am having a simple proto file named Person.proto with the below content. 我有一个名为Person.proto的简单原型文件,其中包含以下内容。 I dont get it what am I missing. 我不明白我在想什么。

syntax = "proto2";

message Person{
optional string name = 1;
}

The command I am using is 我正在使用的命令是

Protoc Person.proto --csharp_out=C:\Users\Owner\.nuget\packages\google.protocolbuffers\2.4.1.555\tools Person.cs

Person.cs 人.cs

public class Person
{

}

Exactly what tooling versions are you using there? 您在那里使用的是哪个工具版本? If it isn't expecting the "syntax" keyword, that suggests a very old tooling version. 如果不希望使用“ syntax”关键字,则表明工具版本非常旧。 Maybe try updating? 也许尝试更新? However, the current Google tools only support "proto3" syntax. 但是,当前的Google工具仅支持“ proto3”语法。 In your case, that just means changing "proto2" to "proto3" and removing the "optional". 在您的情况下,这仅意味着将“ proto2”更改为“ proto3”并删除“可选”。 You could also try my online tooling which provides support for both the Google tools (protoc) and the protobuf-net tools (protogen) - see the drop-down at https://protogen.marcgravell.com 您也可以尝试使用我的在线工具,该工具同时支持Google工具(protoc)和protobuf-net工具(protogen)-请参见https://protogen.marcgravell.com上的下拉列表。

Unlike protoc, protogen supports both "proto2" and "proto3" syntax. 与protoc不同,protogen支持“ proto2”和“ proto3”语法。 There are links on the page for how to access the tools locally. 页面上有有关如何在本地访问工具的链接。

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

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