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

As an extension of Shaun's code, I am pleased to announce that protobuf-net now has Visual Studio integration by way of a Custom Tool. The msi installer is available from the project page More complete information here: protobuf-net; now with added Orcas.

As an extension of Shaun's code, I am pleased to announce that protobuf-net now has Visual Studio integration by way of a Custom Tool. The msi installer is available from the project page. More complete information here: protobuf-net; now with added Orcas.

Calling a pre-build step but using project variables (e.g. $(ProjectPath)) to create absolute filenames without having them actually in your solution would seem a reasonable bet to me. One thing you might want to consider, based on my past experience of code generators: you might want to write a wrapper for protogen which generates code to a different location, then checks whether the newly generated code is the same as the old code, and doesn't overwrite it if so. That way Visual Studio will realise nothing's changed and not force that project to be rebuilt - this has cut build times dramatically for me in the past.

Alternatively, you could keep an md5 hash of the . Proto file the last time protogen was executed, and only execute protogen if the . Proto file has changed - even less to do on each build!

Thanks for raising this as a question though - it clearly suggests I should work out a way to make this an easy pre-build step for my own port.

Thanks, I must have mistyped something before on the pre-build step. It would be nice if VisualStudio could do all of the "make" style checks regarding cs being older than proto files! – Ray Hayes Jan 17 '09 at 19:43 Yes, that would indeed be nice :) There may be a way of getting it to do that, but it would probably require more MSBuild-fu than I have, I'm afraid.

The force is stronger with Marc in that respect, so he may well have a better answer. – Jon Skeet Jan 17 '09 at 19:49 @jon, I've now added a pre-build and a simple tool to check if the "written" date/time for the . Proto is newer than the .

Cs, if so, it calls the protogen command. – Ray Hayes Jan 17 '09 at 20:47 oh, by added, I mean updated the original post with an "edit" block... not sure what the correct way to do this is.... – Ray Hayes Jan 17 '09 at 20:47 lol! Caught me napping... – Marc Gravell?

Jan 17 '097 at 17:11.

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.

I have attached a quick and dirty Visual Studio Custom Tool wrapper around ProtoGen. Exe to the Google Code page for this issue (code.google.com/p/protobuf-net/issues/de...). This makes adding .

Proto files to C# projects extremely easy. See the readme in the attachment for more info.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions