Protocol buffers in C# projects using protobuf-net - best practices for code generation

前端 未结 6 1585
盖世英雄少女心
盖世英雄少女心 2021-01-31 05:35

I\'m trying to use protobuf in a C# project, using protobuf-net, and am wondering what is the best way to organise this into a Visual Studio project structure.

When manu

6条回答
  •  误落风尘
    2021-01-31 06:28

    well, that gave me an idea (something about reinventing the wheel)...

    • create simple Makefile.mak, something like
    .SUFFIXES : .cs .proto
    
    .proto.cs:
        protogen\protogen.exe -i:$? -o:$@ -t:protogen\csharp.xlst
    

    (obviously, don't forget to replace paths to protogen and csharp.xlst). IMPORTANT - protogen\protogen.exe command starting from TAB character, not 8 spaces

    • If you don't want to specify files needed to be build all the time, you might use something like
    .SUFFIXES : .cs .proto
    
    all: mycs1.cs myotherfile.cs
    
    .proto.cs:
        protogen\protogen.exe -i:$? -o:$@ -t:protogen\csharp.xlst
    
    • in pre-build step to add
    cd $(ProjectDir) && "$(DevEnvDir)..\..\vc\bin\nmake" /NOLOGO -c -f Makefile.mak mycs1.cs myotherfile.cs

    or, if you have nmake in your path, one can use

    cd $(ProjectDir) && nmake /NOLOGO -c -f Makefile.mak mycs1.cs myotherfile.cs

提交回复
热议问题