Do 'dotnet build' and 'dotnet test' commands treat the -o/--output argument differently?

Viewed 31

I'm trying to create a Dockerfile for running unit tests inside a container.

I currently have the following Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR "/src"

COPY ["ProjectName/ProjectName.csproj", "ProjectName/"]
RUN dotnet restore "ProjectName/ProjectName.csproj"
COPY . .
WORKDIR "/src/ProjectName"
RUN dotnet build "ProjectName.csproj" -c Release -o /app/build

FROM build AS test
ENTRYPOINT ["dotnet", "test", "ProjectName.csproj", "-c:Release", "-o:\"/app/build\"", "--no-build"]

The idea here is that it will build an image with binaries stored in /app/build and then execute the dotnet test command without rebuilding the project and knowing where the binaries are (because of the -o:"/app/build" parameter).

It builds fine, I can -it bash into the container and confirm that the assemblies are stored in the /app/build directory. However, once I try to execute the tests, it produces some weird error:

Test run for /src/ProjectName/app/build/ProjectName.dll (.NETCoreApp,Version=v6.0)

Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)

Copyright (c) Microsoft Corporation. All rights reserved.

The argument /src/ProjectName/app/build/ProjectName.dll is invalid. Please use the /help option to check the list of valid arguments.

As I understand this, instead of treating the -o:/app/build as a directory in the root of the file system, it appends it to the current directory:

/src/ProjectName/app/build/ProjectName.dll

I can work around this and not specify the output directory at all, it is not critical for a unit testing container, however, I want to understand what the cause of the problem is.

Is it a .NET CLI bug or am I doing something wrong here?

Thank you.

0 Answers
Related