Visual Studio 2010 and protobuf-csharp-port
We are using Jon Skeet's proto-csharp port protocol and I am having some difficulty mixing with ReSharper in Visual Studio 2010.
We generate .cs files via a custom MSBuild target, connect like this:
<Target Name="BeforeBuild" DependsOnTargets="CompileProtos" />
The target CompileProtos
starts up ProtoGen
and then adds the generated .cs files to the item group @(Compile)
using CreateItem
. This looks in a specific directory and compiles every .proto file it finds, so they are not listed in the project.
Where it falls is that ReSharper does not recognize the contents of .cs files (because they are not in the project and may not exist yet), so I cannot get the solution parsing light to go green.
If I add .cs files to the project, I get build failures because the .cs file has been added to the item group Compile
twice.
I know Marc protobuf-net has Visual Studio 2008 kindness in it and I'm looking for something similar, but for Jon protobuf-csharp-port and for Visual Studio 2010.
Ideally, I would like to be able to add .proto files to the project, build them correctly, and have Visual Studio and ReSharper know about the generated .cs files so that IntelliSense and solution analysis work correctly.
I'm guessing something like how .xsd files can implicitly generate .cs files will do the trick.
a source to share
I solved it by removing CreateItem
from the target CompileProtos
and identifying it as correct ItemGroup
:
<ItemGroup>
<Protocols Include="$(ProtocolsPath)\*.proto"/>
</ItemGroup>
<ItemGroup>
<Compile Include="@(Protocols -> '%(Filename).cs')"/>
</ItemGroup>
This means that Visual Studio (and ReSharper) picks up the .cs files correctly after they are created, and a full analysis of ReSharper solutions stops complaining.
Unfortunately Visual Studio has a habit of expanding ItemGroup
into individual entries Compile
, but I can check this before I check anything.
a source to share
I tried to do the job by doing a custom tool to generate code , but I was faced with an insurmountable obstacle:
protoc
takes a directory full of files .proto
and generates a file .protobin
. It is then fed to ProtoGen
which produces a .cs file for each protocol definition. Unfortunately, it seems that the file .protobin
must contain all definitions, otherwise you will receive Error: Cannot resolve all dependencies .
Since a custom tool model in Visual Studio accepts one input file and one output file (i.e. foo.proto -> foo.cs), it looks like this cannot be made to work.
At least not getting a way to include all foo.proto
imported files .proto
in foo.protobin
, anyway.
a source to share