如何将共享原始文件导入本地文件?

发布于 2025-01-27 06:29:58 字数 1066 浏览 4 评论 0原文

我有项目 protobuf.shared ,其中包含共享的原始文件。这个项目包装到Nuget软件包中。

项目结构:

- .nuspec
- proto
 - shared.proto
 - base.proto
- Dummy.cs

我还有Project Protobuf.Server ,它使用ProtoBuf.Shared Nuget软件包,还包含自己的原始文件。

项目结构:

- proto
 - server.proto
- Dummy.cs

我成功导入共享的原始文件,它们在构建操作过程中正确编译。在虚拟C中,我可以使用生成的消息类。

问题

当我想将shared.proto(从protobuf.shared)导入server.proto build action失败时,发现了共享。 在这种情况下,如何正确导入原型以获得成功的项目构建? 通过Nuget软件包使用共享原型是一项要求。

我做了一个在github的示例 with readme with readme节省了时间。

我想实现的server.proto的结果:

syntax = "proto3";

package server;

option csharp_namespace = "Protobuf.Server";

// Import shared.proto somehow
import "shared.proto";
//import "1.0.0/shared.proto";

message SomeMessage {
  int32 Amount = 1;
  //shared.Name name = 2;
}

I have project Protobuf.Shared which contains shared proto files. This project is packed into NuGet package.

Project structure:

- .nuspec
- proto
 - shared.proto
 - base.proto
- Dummy.cs

Also I have project Protobuf.Server, which uses Protobuf.Shared NuGet package and also contains own proto file.

Project structure:

- proto
 - server.proto
- Dummy.cs

I successfully imported shared proto files, they are correctly compiled during build action. In Dummy.cs I can use generated message classes.

Problem:

When I want to import shared.proto (from Protobuf.Shared) into server.proto build action fails with error that shared.proto not found.
How to import proto in this case correctly to get successful project build?
Usage of shared protos via NuGet package is a requirement.

I made a sample at GitHub with readme to save your time.

Result of server.proto I want to achieve:

syntax = "proto3";

package server;

option csharp_namespace = "Protobuf.Server";

// Import shared.proto somehow
import "shared.proto";
//import "1.0.0/shared.proto";

message SomeMessage {
  int32 Amount = 1;
  //shared.Name name = 2;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

番薯 2025-02-03 06:29:59

在我的情况下,我修复了此错误,在.csproj文件上添加了此行:

<PropertyGroup>
<Protobuf_ProtoRoot>Protos</Protobuf_ProtoRoot>
<Protobuf_StandardImportsPath>$(Protobuf_StandardImportsPath);Protos</Protobuf_StandardImportsPath>
</PropertyGroup>

In my case I fixed this error adding this line on .csproj file:

<PropertyGroup>
<Protobuf_ProtoRoot>Protos</Protobuf_ProtoRoot>
<Protobuf_StandardImportsPath>$(Protobuf_StandardImportsPath);Protos</Protobuf_StandardImportsPath>
</PropertyGroup>
桃扇骨 2025-02-03 06:29:58

当我下载并检查代码时,未选择“ Protobuf.shared”项目中的“共享”文件的生成类型,当我将其制作为“客户端和服务器”并创建和更新Nuget软件包时,问题解决了。

我在'Protobuf.shared.csproj'中添加了此内容,

<ItemGroup>
  <Protobuf Update="proto\shared.proto" GrpcServices="Both" />
</ItemGroup>

您也可以在'shared.proto'文件的属性中执行此操作。

我还向仓库发送了一个拉请求。

When I downloaded and checked the code, the generation type of the 'shared.proto' file in the 'Protobuf.Shared' project was not selected, and when I made it 'Client and Server' and created and updated the nuget package, the problem was solved.

I added this in 'protobuf.Shared.csproj'

<ItemGroup>
  <Protobuf Update="proto\shared.proto" GrpcServices="Both" />
</ItemGroup>

You can also do this in the properties of the 'shared.proto' file.

enter image description here

I also sent a pull request to the repo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文