[英]DotNet Core Create Proto message common library
The use case is pretty simple: I have two projects (ProtoProvider & ProtoConsumer).用例非常简单:我有两个项目(ProtoProvider 和 ProtoConsumer)。
ProtoProvider has the proto file (to_import.proto) and the message I want to use on the ProtoConsumer. ProtoProvider 有 proto 文件 (to_import.proto) 和我想在 ProtoConsumer 上使用的消息。
ProtoConsumer has a referrence on ProtoProvider and attempts to use the ProvidedMessage in the imported.proto. ProtoConsumer 对 ProtoProvider 有一个引用,并尝试在imported.proto 中使用ProvidedMessage。 I cannot use the the message because I get "File not found."我无法使用该消息,因为我收到“找不到文件”。 on the impoort and "ProvidedMessage is not defined" on the compiler for the imported.proto.在 import.proto 的编译器上导入和“ProvidedMessage 未定义”。
EDIT2>>> To clarify I want to create a message like google's google.protobuf.Timestamp and distribute it to another project or projects without the other projects while having the project/projects (consumer) getting the message from the dll. EDIT2>>> 澄清我想创建一个像谷歌的 google.protobuf.Timestamp 这样的消息并将其分发到另一个项目或没有其他项目的项目,同时让项目/项目(消费者)从 dll 获取消息。 The whole premise of the question is how to use the message defined in to_import.proto in another project through the dll (think of it as a common.grpc lib).问题的整个前提是如何通过dll(将其视为common.grpc lib)在另一个项目中使用to_import.proto中定义的消息。
EDIT1>>> The error messages I'm getting EDIT1>>> 我收到的错误消息
Is there a solution that allows the importing of the proto files from a project reference?是否有允许从项目引用中导入 proto 文件的解决方案? I'm looking for something like google's solution for the well-known-types我正在寻找类似谷歌的知名类型的解决方案
import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
source: https://developers.google.com/protocol-buffers/docs/csharptutorial#where-to-find-the-example-code .来源: https://developers.google.com/protocol-buffers/docs/csharptutorial#where-to-find-the-example-code 。
(Copying the proto files or moving the files is not an elegant solution). (复制原始文件或移动文件不是一个优雅的解决方案)。
Below I'll provide the.csproj files下面我将提供 .csproj 文件
ProtoProvider:原型提供者:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="to_import.proto" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.27.0" />
</ItemGroup>
<ItemGroup>
<Protobuf Include="to_import.proto" GrpcServices="None" />
</ItemGroup>
</Project>
ProtoConsumer:原始消费者:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Protobuf Include="Protos\imported.proto" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.27.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ProtoProvider\ProtoProvider.csproj" />
</ItemGroup>
</Project>
Edit>>3 Some context: The purpose of this question is to help me understand a clearer way to implement decimal once (as specified here ) and reuse them in each project.编辑>>3 一些上下文:这个问题的目的是帮助我理解一种更清晰的方式来实现小数一次(如此处指定)并在每个项目中重用它们。
AFAIK, compiling proto
files requires all files (including imports) to exist on disk. AFAIK,编译proto
文件需要所有文件(包括导入)都存在于磁盘上。
The way this works for the well known types is that they are included in Grpc.Tools
nuget package .这适用于众所周知的类型的方式是它们包含在Grpc.Tools
nuget package 中。
So its not possible to ship a class library that accomplishes what you want.所以不可能发布一个 class 库来完成你想要的。
Discussion on a related grpc-dotnet
issue suggests using a combination of:对相关grpc-dotnet
问题的讨论建议使用以下组合:
GeneratePathProperty
to generate a variable holding the path to the nuget package content在使用代码的 package 引用中,使用GeneratePathProperty
生成一个变量,该变量保存 nuget package 内容的路径Protobuf Include
, use AdditionalImportDirs
to include the common proto from the nuget package.在使用代码的Protobuf Include
中,使用AdditionalImportDirs
包含来自 nuget package 的通用 proto。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.