|
|
|
@@ -39,6 +39,16 @@ public class WriteProtoFileTask : Task
|
|
|
|
|
[Required]
|
|
|
|
|
public string ProtoFileName { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The root namespace of the project (optional, falls back to AssemblyName)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string RootNamespace { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The assembly name of the project (used for proto namespace if RootNamespace not set)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string AssemblyName { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public override bool Execute()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@@ -57,6 +67,16 @@ public class WriteProtoFileTask : Task
|
|
|
|
|
"GeneratedProtoFile.g.cs"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Check if proto file already exists (committed to repo or from previous build)
|
|
|
|
|
var existingProtoPath = Path.Combine(ProjectDirectory, OutputDirectory, ProtoFileName);
|
|
|
|
|
if (File.Exists(existingProtoPath) && !File.Exists(generatedFilePath))
|
|
|
|
|
{
|
|
|
|
|
Log.LogMessage(MessageImportance.High,
|
|
|
|
|
$"Svrnty.CQRS.Grpc: Using existing proto file at {existingProtoPath}. " +
|
|
|
|
|
"To regenerate, delete the file and build twice.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(generatedFilePath))
|
|
|
|
|
{
|
|
|
|
|
Log.LogWarning(
|
|
|
|
@@ -65,13 +85,30 @@ public class WriteProtoFileTask : Task
|
|
|
|
|
|
|
|
|
|
// Write a minimal placeholder proto file so Grpc.Tools doesn't fail
|
|
|
|
|
// The real content will be generated on the next build
|
|
|
|
|
var placeholderProto = @"syntax = ""proto3"";
|
|
|
|
|
// Use project's namespace so GrpcGenerator can find the service base types
|
|
|
|
|
var projectNamespace = !string.IsNullOrEmpty(RootNamespace) ? RootNamespace
|
|
|
|
|
: !string.IsNullOrEmpty(AssemblyName) ? AssemblyName
|
|
|
|
|
: "Generated";
|
|
|
|
|
var grpcNamespace = $"{projectNamespace}.Grpc";
|
|
|
|
|
|
|
|
|
|
option csharp_namespace = ""Generated.Grpc"";
|
|
|
|
|
var placeholderProto = $@"syntax = ""proto3"";
|
|
|
|
|
|
|
|
|
|
option csharp_namespace = ""{grpcNamespace}"";
|
|
|
|
|
|
|
|
|
|
package cqrs;
|
|
|
|
|
|
|
|
|
|
// Placeholder proto file - will be regenerated on next build
|
|
|
|
|
// Placeholder proto file - will be regenerated on next build with actual services
|
|
|
|
|
// Using namespace: {grpcNamespace}
|
|
|
|
|
|
|
|
|
|
// Empty service definitions so Grpc.Tools generates base classes
|
|
|
|
|
service CommandService {{
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
service QueryService {{
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
service DynamicQueryService {{
|
|
|
|
|
}}
|
|
|
|
|
";
|
|
|
|
|
var placeholderOutputPath = Path.Combine(ProjectDirectory, OutputDirectory);
|
|
|
|
|
Directory.CreateDirectory(placeholderOutputPath);
|
|
|
|
|