diff --git a/src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs b/src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs
index 5f6a53b6713..89c6b274e13 100644
--- a/src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs
+++ b/src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs
@@ -140,6 +140,15 @@ namespace Grpc.Tools.Tests
Does.Contain("--grpc_opt=baz,quux"));
}
+ [Test]
+ public void AdditionalProtocArguments()
+ {
+ _task.AdditionalProtocArguments = new[] { "--experimental_allow_proto3_optional" };
+ ExecuteExpectSuccess();
+ Assert.That(_task.LastResponseFile,
+ Does.Contain("--experimental_allow_proto3_optional"));
+ }
+
[Test]
public void DirectoryArgumentsSlashTrimmed()
{
diff --git a/src/csharp/Grpc.Tools/ProtoCompile.cs b/src/csharp/Grpc.Tools/ProtoCompile.cs
index 820cbfed9b2..b81656a5276 100644
--- a/src/csharp/Grpc.Tools/ProtoCompile.cs
+++ b/src/csharp/Grpc.Tools/ProtoCompile.cs
@@ -278,6 +278,12 @@ namespace Grpc.Tools
///
public string[] OutputOptions { get; set; }
+ ///
+ /// Additional arguments that will be passed unmodified to protoc (and before any file names).
+ /// For example, "--experimental_allow_proto3_optional"
+ ///
+ public string[] AdditionalProtocArguments { get; set; }
+
///
/// Full path to the gRPC plugin executable. If specified, gRPC generation
/// is enabled for the files.
@@ -428,6 +434,15 @@ namespace Grpc.Tools
}
cmd.AddSwitchMaybe("dependency_out", DependencyOut);
cmd.AddSwitchMaybe("error_format", "msvs");
+
+ if (AdditionalProtocArguments != null)
+ {
+ foreach (var additionalProtocOption in AdditionalProtocArguments)
+ {
+ cmd.AddArg(additionalProtocOption);
+ }
+ }
+
foreach (var proto in Protobuf)
{
cmd.AddArg(proto.ItemSpec);
diff --git a/src/csharp/Grpc.Tools/build/_protobuf/Google.Protobuf.Tools.targets b/src/csharp/Grpc.Tools/build/_protobuf/Google.Protobuf.Tools.targets
index fb7dc5fa03d..f06186896e1 100644
--- a/src/csharp/Grpc.Tools/build/_protobuf/Google.Protobuf.Tools.targets
+++ b/src/csharp/Grpc.Tools/build/_protobuf/Google.Protobuf.Tools.targets
@@ -288,6 +288,7 @@
GrpcPluginExe="%(_Protobuf_OutOfDateProto.GrpcPluginExe)"
GrpcOutputDir="%(_Protobuf_OutOfDateProto.GrpcOutputDir)"
GrpcOutputOptions="%(_Protobuf_OutOfDateProto._GrpcOutputOptions)"
+ AdditionalProtocArguments="%(_Protobuf_OutOfDateProto.AdditionalProtocArguments)"
>