c#的Google Protobuf 3.0.0程序集

本文关键字:程序集 Protobuf Google | 更新日期: 2023-09-27 18:08:12

在我们的项目中,我们成功地为c++使用了Google Protobuf。现在需要编译相同的*。在c#代码中使用它。我下载了最近的Protobuf 3.0.0-alpha-3版本。它为c#提供proto2格式的支持,这对我来说已经足够了。我可以建立我的*。Proto文件成功,并得到一个*.cs文件。然而,当我将结果*.cs文件添加到我的c#项目并尝试构建时,我收到编译器错误,如:"The type or namespace name 'Google' could not be found in the global namespace (are you missing an assembly reference?)"这是错误发生的地方:

// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: DiagramExport.proto
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;

现在我在项目页面上的发布ZIP中找不到任何DLL等,我可以在我的c#项目中包含作为参考。只有protoc.exe和一些*。原始文件在那里。我的简单问题是:我在哪里得到这些程序集?

(注:我试图按照README文件中的说明从源代码构建项目protobuf- sharp-3.0.0-alpha-3,但未能使用Visual Studio 2013 Update 4"开箱即用"构建它;我得到一些编译器错误)

c#的Google Protobuf 3.0.0程序集

在阅读本文和本文档页面后,我发现可以通过在包管理器控制台上执行以下命令为我的项目安装Protocol Buffers NuGet包:

Install-Package Google.ProtocolBuffers

控制台可以在Visual Studio 2013中通过TOOLS -> NuGet Package Manager -> Package Manager console访问。经理下载了这个包,我得到了两个推荐信"谷歌"。"Google.ProtocolBuffers"answers"Google.ProtocolBuffers"。序列化",这让编译器很高兴。它现在工作完美!

请看这里的发布说明

c# (Beta)部分你会发现:

Breaking: Preconditions is renamed to ProtoPreconditions
Breaking: GeneratedCodeInfo is renamed to GeneratedClrTypeInfo

因此,Grpc.Tools包附带的protoc.exe似乎生成了"旧"代码。我用这个替换了protoc.exe,并重新编译(再生)了我的类,解决了这个问题。