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文件

 

具体可以研究一下:

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM