网上的教程大都是手动通过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文件,希望对大家有所帮助!
如对本文有疑问, 点击进行留言回复!!
C# 对PDF文档加密、解密(基于Spire.Cloud.SDK for .NET)
Unity通用泛型单例设计模式(普通型和继承自MonoBehaviour)
网友评论