When using c# as the development language to convert Pb files into CS files, I believe many people will encounter a very difficult problem
The first question: in the protoc3 environment, import timestamp. In the header, import “Google/protobuf/timestamp. Proto”; Exceptions will be thrown when: Google/protobuf/timestamp. Proto “was not found or had errors;
Solution [sharing of original articles by blogger “pamxy”:
(Note: it was found later that it is not necessary to add this directory, because the timestamp.pb.cc file generated by timestamp.proto has been compiled as the source code when compiling libprotobuf.lib file, and libprotobuf.lib is also used in compiling protoc.exe, so it is natural to default that there is already a source code, so there is no need to import it again!)
Just delete the import “Google/protobuf/timestamp. Proto”.
Second question: ” google.protobuf.Timestamp” is not defined.
Under normal circumstances, there is no need to import google.protobuf.timestamp directly in the protoc3 environment, because in the compilation process, the problem will be read in the Lib file, but if timestamp is called in the file, it is as follows:
It is necessary to call the timestamp file in the header, but bloggers are always prompted during the call ” google.protobuf.Timestamp” is not defined.
There is really no way, so I have to find the path of this file: timestamp.proto file in protobuf master \ SRC \ Google \ protobuf folder, directly copy the file to the same level directory of the file you want to compile, and then modify the timestamp file in the header. The call path: Import “timestamp. Proto”;
Finally, the file was finally solved…….
The third question: how to call after converting the protocol file into a CS file?
a. Found in referenced project: Tools & gt& gt; Nuget package manager & gt& gt; Nuget package for management solution & gt& gt; Search for “Google. Protocolbuffers” and install
B, directly convert the protoc file into the CS file, and call it in the project.
This small problem is recorded, which is also convenient for you to use as a reference when you encounter this problem.