Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compile protocol buffers 3 timestamp type in c# visual studio?

Visual Studio 2015 
C#
NuGet Packages : 
Google.Protobuf v3.0.0 
Google.Protobuf.Tools v3.0.0

MessageType Quake

syntax = "proto3";
import "google/protobuf/timestamp.proto";
message Quake {
  google.protobuf.Timestamp _timestamp = 1;
  double magnitude = 2;
}

timestamp.proto included in same folder

protoc 3.0.2 command-line compilation succeeds

But VS right-click proto file and select "Run Custom Tool" fails with error "The custom tool 'ProtoBufTool' failed."

to generate the C# classes from within Visual Studio ?

like image 815
BaltoStar Avatar asked Oct 19 '22 01:10

BaltoStar


1 Answers

The Protobuf documentation seems short (weak) when it explains how to execute protoc.exe. Here is how I do it in a small test project I am writing. I have installed TWO NuGet packages for my Protobuf project:

Google.Protobuf (C# runtime library for Protocol Buffers)
Google.Protobuf.Tools (protoc.exe)

In Visual Studio I have defined a Pre-build event command line. This is defined in the properties menu for the project:

..\..\..\packages\Google.Protobuf.Tools.3.6.0\tools\windows_x64\protoc -I="$(ProjectDir)."
    --csharp_out=$(ProjectDir)Model $(ProjectDir)MyOwn.proto

The resulting MyOwn.cs file lands in subdirectory "Model". It must be manually included in the project, to be automatically compiled. This is how I do it today. I hope this helps someone.

like image 197
Dag Henrik B Avatar answered Nov 13 '22 08:11

Dag Henrik B