I am trying to build my .net core app using Docker. And I want to override my app version during build. To display it somewhere later in runtime.
I have my Docker file looks like this:
FROM microsoft/dotnet:2.2-sdk AS build-env
WORKDIR /src
RUN apt-get update && \
apt-get install -y libgit2-dev && \
ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so
COPY ..
WORKDIR /src/API
RUN dotnet restore
RUN dotnet tool install -g GitVersion.Tool --version=5.0.0-beta1-72
RUN export PATH="$PATH:/root/.dotnet/tools" && \
version="$(dotnet gitversion /output json /showvariable NuGetVersion)" && \
dotnet build --no-restore /property:Version=$version && \
dotnet publish --output "/app" --no-build
FROM microsoft/dotnet:2.2-aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app .
ENTRYPOINT ["dotnet", "API.dll"]
When I tried the same commands like in RUN instructions on my Windows machine - everything is OK. I also tried to run the same commands on WSL (Ubuntu 18) and it's also fine - I have assembly version from my build command. But I can't figure out why it is not working inside Docker.
I've also tried to remove all my GitVersion magic and use just this:
FROM microsoft/dotnet:2.2-sdk AS build-env
WORKDIR /src
RUN apt-get update && \
apt-get install -y libgit2-dev && \
ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so
COPY ..
WORKDIR /src/API
RUN dotnet restore
RUN dotnet build --no-restore /property:Version=1.1.1.0-beta1
RUN dotnet publish --output "/app" --no-build
FROM microsoft/dotnet:2.2-aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app .
ENTRYPOINT ["dotnet", "API.dll"]
Anyway, my results are the same.
I use this code to check:
public static void Main(string[] args)
{
Console.WriteLine(typeof(Program).Assembly.GetName());
}
Every time my build is a success but I have version defined in .csproj file without override.