软件编程
位置:首页>> 软件编程>> C#编程>> C# protobuf自动更新cs文件

C# protobuf自动更新cs文件

作者:egmkang  发布时间:2021-10-08 10:16:28 

标签:C#,protobuf,cs

网上的教程大都是手动通过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文件

C# protobuf自动更新cs文件

具体可以研究一下:

https://github.com/grpc/grpc/blob/master/src/csharp/BUILD-INTEGRATION.md

总结

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

来源:https://www.cnblogs.com/egmkang/archive/2020/02/04/12258218.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com