Skip to content

Commit b5983f2

Browse files
Mpdreamzpuckpuck
andauthored
Resolve proto directory dynamically for dotnet cartservice (#1579)
This allows the solutio to be opened in any .NET editor and compile right away. Removes the requirement to manually copy the proto files. This also now copies the protofiles into the docker container using the original folder name. Co-authored-by: Pierre Tessier <pierre@pierretessier.com>
1 parent e91611b commit b5983f2

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/cartservice/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ This service stores user shopping carts in Redis.
66

77
Run `dotnet restore` and `dotnet build`.
88

9-
Protobufs must be present in `./src/protos`
10-
119
## Docker Build
1210

13-
From the root directory, run:
11+
From the root directory of this repository, run:
1412

1513
```sh
1614
docker compose build cartservice

src/cartservice/src/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ARG TARGETARCH
2121
WORKDIR /usr/src/app/
2222

2323
COPY ./src/cartservice/ ./
24-
COPY ./pb/ ./src/protos/
24+
COPY ./pb/ ./pb/
2525

2626
RUN dotnet restore ./src/cartservice.csproj -v d -r linux-musl-$TARGETARCH
2727

src/cartservice/src/cartservice.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
<PublishSingleFile>true</PublishSingleFile>
88
<SelfContained>true</SelfContained>
99
<PublishTrimmed>false</PublishTrimmed>
10+
<ProtosDir>$(ProjectDir)..\pb</ProtosDir>
11+
</PropertyGroup>
12+
13+
<PropertyGroup Condition="!Exists('$(ProtosDir)')">
14+
<ProtosDir>..\..\..\pb</ProtosDir>
1015
</PropertyGroup>
1116

1217
<ItemGroup>
@@ -29,6 +34,6 @@
2934
</ItemGroup>
3035

3136
<ItemGroup>
32-
<Protobuf Include="**\*.proto" GrpcServices="Both" />
37+
<Protobuf Include="$(ProtosDir)\**\*.proto" GrpcServices="Both" />
3338
</ItemGroup>
3439
</Project>

0 commit comments

Comments
 (0)