Anonymous
Как настроить автоматическое генерацию классов из контракта с помощью Protobuf-Net?
Сообщение
Anonymous » 02 авг 2025, 11:19
Я настроил файл .csproj следующим образом: < /p>
Код: Выделить всё
Exe
net9.0
enable
enable
all
runtime; build; native; contentfiles; analyzers; buildtransitive
< /code>
Папка с прото -файлами расположена по адресу:
consoleapp2 \ protos < /p>
Прото -файл выглядит так: < /p>
syntax = "proto3";
package MyApp;
service MyService {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
< /code>
Проблема в том, что генерируются только сообщения, но не служба. < /p>
//
// This file was generated by a tool; you should avoid making direct changes.
// Consider using 'partial classes' to extend these types
// Input: Test.proto
//
#region Designer generated code
#pragma warning disable CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
namespace MyApp
{
[global::ProtoBuf.ProtoContract()]
public partial class HelloRequest : global::ProtoBuf.IExtensible
{
private global::ProtoBuf.IExtension __pbn__extensionData;
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
=> global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
[global::ProtoBuf.ProtoMember(1, Name = @"name")]
[global::System.ComponentModel.DefaultValue("")]
public string Name { get; set; } = "";
}
[global::ProtoBuf.ProtoContract()]
public partial class HelloReply : global::ProtoBuf.IExtensible
{
private global::ProtoBuf.IExtension __pbn__extensionData;
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
=> global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
[global::ProtoBuf.ProtoMember(1, Name = @"message")]
[global::System.ComponentModel.DefaultValue("")]
public string Message { get; set; } = "";
}
}
#pragma warning restore CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192
#endregion
Что может быть причиной?>
Подробнее здесь:
https://stackoverflow.com/questions/797 ... otobuf-net
1754122751
Anonymous
Я настроил файл .csproj следующим образом: < /p> [code] Exe net9.0 enable enable all runtime; build; native; contentfiles; analyzers; buildtransitive < /code> Папка с прото -файлами расположена по адресу: consoleapp2 \ protos < /p> Прото -файл выглядит так: < /p> syntax = "proto3"; package MyApp; service MyService { rpc SayHello (HelloRequest) returns (HelloReply); } message HelloRequest { string name = 1; } message HelloReply { string message = 1; } < /code> Проблема в том, что генерируются только сообщения, но не служба. < /p> // // This file was generated by a tool; you should avoid making direct changes. // Consider using 'partial classes' to extend these types // Input: Test.proto // #region Designer generated code #pragma warning disable CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 namespace MyApp { [global::ProtoBuf.ProtoContract()] public partial class HelloRequest : global::ProtoBuf.IExtensible { private global::ProtoBuf.IExtension __pbn__extensionData; global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); [global::ProtoBuf.ProtoMember(1, Name = @"name")] [global::System.ComponentModel.DefaultValue("")] public string Name { get; set; } = ""; } [global::ProtoBuf.ProtoContract()] public partial class HelloReply : global::ProtoBuf.IExtensible { private global::ProtoBuf.IExtension __pbn__extensionData; global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); [global::ProtoBuf.ProtoMember(1, Name = @"message")] [global::System.ComponentModel.DefaultValue("")] public string Message { get; set; } = ""; } } #pragma warning restore CS0612, CS0618, CS1591, CS3021, CS8981, IDE0079, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 #endregion [/code] Что может быть причиной?> Подробнее здесь: [url]https://stackoverflow.com/questions/79722400/how-do-i-set-up-automatic-class-generation-from-a-contract-using-protobuf-net[/url]