I am trying to generate C# code using .proto file, but getting error
import google/protobuf/timestamp.proto was not found or had errors. windows
syntax = "proto3";
option csharp_namespace = "icigcppubsub1";
import "google/protobuf/timestamp.proto";
message SomeMessage {
message Itemkey {
string itemType = 1;
string itemNo = 2;
}
message Locale {
string countryCode = 1;
string languageCode = 2;
}
message Names {
Locale locale = 1;
string itemName = 2;
string presentationGroupCode = 3;
string measurementSystem = 4;
google.protobuf.Timestamp sourceInsertDateTime = 5;
google.protobuf.Timestamp sourceUpdateDateTime = 6;
}
Itemkey itemKey = 1;
repeated Names names = 2;
}
Reason
The error is produced because the protoc executable expects its libraries in particular locations (in the same folder, or in the ..\include).
Solution
Follow the following steps.
STEP 1. Install below package.
STEP 2. Copy the Path of Google.Protobuf.Tools
[
STEP 3. Copy the protoc.exe
file from below folder path
C:\Users\manishkumar\.nuget\packages\google.protobuf.tools\3.20.1\tools\windows_x64
and Paste to
C:\Users\manishkumar.ma\.nuget\packages\google.protobuf.tools\3.20.1\tools
STEP 4. Change Execution path in command prompt.
STEP 5. Execute below command using .proto file
protoc -I="C:\Users\manishkumar\source\repos\protobuf_consoleApp" --csharp_out="C:\Users\manishkumar\source\repos\protobuf_consoleApp" "C:\Users\manishkumar\source\repos\protobuf_consoleApp\proto\*.proto"