Build WPF Application with Docker

Viewed 47

I am new to Docker and I am trying to build a WPF application using Docker.

The WPF application runs on .NET Framework 4.8.

This is the contents of my Dockerfile:

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 as base
WORKDIR /
COPY . ./
RUN nuget restore
RUN msbuild /t:Restore ./ProjectName.csproj
RUN msbuild /p:Configuration=Release ./ProjectName.csproj

And im using

docker build -f Dockerfile . --no-cache

to build.

Everything runs fine until the last row when it errors out and I get this error:

error CS0246: The type or namespace name 'MSTSCLib' could not be found (are you missing a using directive or an assembly reference?)

I'm guessing there is some problem with the reference to MSTSClib, but I cant figure out how to solve it.

I've tried the following:

  • Changing "copy local"
  • Changing "Embed Interop Types"
1 Answers

Ok, I really have no idea why this worked, but it did:

  • Firstly I did as @Selvin told me to

build normally on your PC, remove COM dependency and add dependency to generated MSTSClib interop. This dll should be "part of the source" (fx copy it from /bin/Release to /dlls and then add it as references - also check twice if they are relative in project file/it's XML/)

  • Then i Removed the fifth line RUN msbuild /t:Restore ./ProjectName.csproj from my Dockerfile, and it just worked!
Related