protobuf-csharp-port
protobuf-csharp-port copied to clipboard
VS integration: custom tool to translate .proto into .cs automatically
trafficstars
It would be nice if VS could generate csharp code from proto files
automatically. A Custom Tool is the right tool for the job.
protobuf-net has a Custom Tool:
https://code.google.com/p/protobuf-net/source/browse/#svn%2Ftrunk%2FProtoBufGene
rator
Original issue reported on code.google.com by [email protected] on 21 Feb 2014 at 11:33
Issue 77 has been merged into this issue.
Original comment by jonathan.skeet on 21 Feb 2014 at 11:40
This can be done with an external tool.
Right-click the solution and Manage NuGet Packages. Search for
"CSharpTest.Net.Tools" and install. With an elevated command-prompt, browse to
the package folder .\bin and run "CmdTool.exe install".
Then in Visual Studio, browse to the folder containing the protos. Create a
new xml file called "CmdTool.config" and place the following xml in this newly
created file:
<?xml version="1.0" encoding="utf-8" ?>
<CmdTool xsi:noNamespaceSchemaLocation="CmdTool.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<match filespec="*.proto">
<generator debug="true">
<execute exe="ProtoGen.exe" />
<!-- protoc.exe arguments -->
<arg value="--proto_path=$(InputDir)\"/>
<arg value="--include_imports"/>
<arg value="$(InputPath)"/>
<!-- protogen.exe arguments -->
<arg value="-file_extension=.Designer.cs"/>
<arg value="-namespace=$(Namespace)"/>
<arg value="-umbrella_namespace=Generated"/>
<arg value="-output_directory=$(InputDir)\"/>
<arg value="-ignore_google_protobuf=true"/>
<arg value="-public_classes=false"/>
<arg value="-cls_compliance=false"/>
<arg value="-nest_classes=false"/>
<output extension=".Designer.cs"/>
</generator>
</match>
</CmdTool>
Change the line to include the relative path to ProtoGen.exe from the Google
package:
<execute exe="ProtoGen.exe" />
more information at: http://help.csharptest.net/?CmdToolConfiguration.html
Original comment by [email protected] on 15 Sep 2014 at 8:27
Given this approach, is any change suggested for the project itself? Just
documewntation?
Original comment by jonathan.skeet on 15 Feb 2015 at 5:16