当前位置: 移动技术网 > IT编程>开发语言>c# > C# protobuf自动更新cs文件

C# protobuf自动更新cs文件

2020年05月10日  | 移动技术网IT编程  | 我要评论

网上的教程大都是手动通过protoc编译, 比较难用

给当前工程添加"google.protobuf"和"grpc.tools"的引用(通过nuget), 然后添加proto文件, 编辑.csproj文件

<project sdk="microsoft.net.sdk">
 <propertygroup>
 <targetframework>netcoreapp3.1</targetframework>
 </propertygroup>
 <itemgroup>
 <packagereference include="google.protobuf" version="3.11.2" />
 <packagereference include="grpc.tools" version="2.26.0">
  <includeassets>runtime; build; native; contentfiles; analyzers; buildtransitive</includeassets>
  <privateassets>all</privateassets>
 </packagereference>
 <!--编辑成这样-->
 <protobuf include="*.proto" outputdir="%(relativepath)" compileoutputs="false" grpcservices="none" />
 </itemgroup>
</project>

然后vs上面编译就会自动生成cs文件

具体可以研究一下:

https://github.com/grpc/grpc/blob/master/src/csharp/build-integration.md

总结

以上所述是小编给大家介绍的c# protobuf自动更新cs文件,希望对大家有所帮助!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网