Skip to content

Instantly share code, notes, and snippets.

@nycdotnet
Created May 29, 2019 12:51
Show Gist options
  • Save nycdotnet/cb3e470ed02a7ce4886a80489d096d7c to your computer and use it in GitHub Desktop.
Save nycdotnet/cb3e470ed02a7ce4886a80489d096d7c to your computer and use it in GitHub Desktop.
Protobuf Example
syntax = "proto3";
package visualstudio.example;
option csharp_namespace = "ProtobufExample.Protos";
// contains info about a Product
message Product {
// this represents the id number.
int32 id = 1;
// description of the product.
string description = 2;
}
using ProtobufExample.Protos;
using System;
namespace ProtobufExample
{
class Program
{
static void Main(string[] args)
{
var product = new Product { Id = 2, Description = "Fun product" };
Console.WriteLine($"Product info: Id = {product.Id}, Description = {product.Description}.");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Api.CommonProtos" Version="1.6.0" />
<PackageReference Include="Grpc" Version="1.21.0" />
<PackageReference Include="Grpc.Tools" Version="1.21.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Protobuf Include="example.proto" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment