I'm trying to get Sonar Scanner to analyze a project as part of a dockerfile using the mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809
image, but it's throwing the following exception when attempting to run dotnet-sonarscanner begin
Unhandled exception. System.IO.IOException: Cannot find local application data directory.
I've verified that the folder it's looking for exists on the container with the following powershell command:
RUN pwsh -Command Get-ChildItem $env:LOCALAPPDATA -Directory
Not sure what I'm missing here. Here's a more complete picture of the dockerfile with example data:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /app
ARG SONAR_PROJECT_KEY=example-project-key
ARG SONAR_OGRANIZAION_KEY=exapmle-org-key
ARG SONAR_HOST_URL=https://sonarcloud.io
ARG SONAR_TOKEN
# install java
COPY ./install-java.ps1 .
RUN pwsh install-java.ps1
RUN cmd ver
# Install Sonar Scanner
RUN dotnet tool install --tool-path msbuildscanner dotnet-sonarscanner
#ENV PATH="$PATH:/root/.dotnet/tools"
RUN pwsh -Command Get-ChildItem $env:LOCALAPPDATA -Directory
# Start Sonar Scanner
RUN msbuildscanner\dotnet-sonarscanner begin /k:"$SONAR_PROJECT_KEY" /o:"$SONAR_OGRANIZAION_KEY" /d:sonar.host.url="$SONAR_HOST_URL" /d:sonar.login="$SONAR_TOKEN"
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
RUN msbuildscanner\dotnet-sonarscanner end /d:sonar.login="$SONAR_TOKEN"
#Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.9-nanoserver-1809 AS runtime
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "app.dll"]