Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup a docker MS build server image

I need a working example of a Dockerfile for creating a .NET build server image.

No matter what I install, I get the following error, when try to build my projects with the container:

error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.5.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

My current Dockerfile looks like this:

# escape=`
FROM microsoft/dotnet-framework:4.6.2
MAINTAINER [email protected]

SHELL ["powershell"]

RUN New-Item -ItemType directory -Path "C:\tools"

WORKDIR C:\tools\

RUN Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?linkid=845298" -OutFile "winsdksetup.exe" -UseBasicParsing
RUN .\winsdksetup.exe /q /norestart

# Note: Install .Net 4.5.2
RUN Invoke-WebRequest -Uri "https://download.microsoft.com/download/E/2/1/E21644B5-2DF2-47C2-91BD-63C560427900/NDP452-KB2901907-x86-x64-AllOS-ENU.exe" -OutFile "NDP452-KB2901907-x86-x64-AllOS-ENU.exe" -UseBasicParsing
RUN .\NDP452-KB2901907-x86-x64-AllOS-ENU.exe /q /norestart

# Note: Install .Net 4.6.2
RUN Invoke-WebRequest -Uri "https://download.microsoft.com/download/F/9/4/F942F07D-F26F-4F30-B4E3-EBD54FABA377/NDP462-KB3151800-x86-x64-AllOS-ENU.exe" -OutFile "NDP462-KB3151800-x86-x64-AllOS-ENU.exe" -UseBasicParsing
RUN .\NDP462-KB3151800-x86-x64-AllOS-ENU.exe /q /norestart

# Note: Install .Net 4.6 Targeting Pack
RUN Invoke-WebRequest -Uri "https://download.microsoft.com/download/C/3/A/C3A5200B-D33C-47E9-9D70-2F7C65DAAD94/NDP46-KB3045557-x86-x64-AllOS-ENU.exe" -OutFile "NDP46-KB3045557-x86-x64-AllOS-ENU.exe" -UseBasicParsing
RUN .\NDP46-KB3045557-x86-x64-AllOS-ENU.exe /q /norestart

RUN Invoke-WebRequest "https://download.microsoft.com/download/A/6/3/A637DB94-8BA8-43BB-BA59-A7CF3420CD90/vs_BuildTools.exe" -OutFile "vs_buildtools.exe" -UseBasicParsing
RUN .\vs_buildtools.exe --add Microsoft.VisualStudio.Workload.MSBuildTools --quiet --wait

# Note: Add .NET + ASP.NET
RUN Install-WindowsFeature NET-Framework-45-ASPNET ; ` 
Install-WindowsFeature Web-Asp-Net45

# Note: Add NuGet
RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\tools\nuget.exe" -UseBasicParsing

# Note: Add NUnit
RUN Invoke-WebRequest "https://github.com/nunit/nunit-console/releases/download/3.6.1/NUnit.Console-3.6.1.zip" -OutFile "NUnit.Console-3.6.1.zip" -UseBasicParsing
RUN Expand-Archive "NUnit.Console-3.6.1.zip" -DestinationPath "C:\tools\nunit"

# Note: Add DotNet Core
RUN Invoke-WebRequest "https://download.microsoft.com/download/E/7/8/E782433E-7737-4E6C-BFBF-290A0A81C3D7/dotnet-dev-win-x64.1.0.4.zip" -OutFile "dotnet-dev-win-x64.1.0.4.zip" -UseBasicParsing
RUN Expand-Archive "dotnet-dev-win-x64.1.0.4.zip" -DestinationPath "C:\tools\dotnet"

# Note: Add to PATH
RUN setx PATH '%PATH%;C:\tools;C:\tools\dotnet;C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin'
RUN setx MSBuildSDKsPath 'C:\tools\dotnet\sdk\1.0.4\Sdks'

What is missing here?

like image 344
jonasm Avatar asked Jun 12 '17 07:06

jonasm


People also ask

How do I put an image on a Docker server?

In order to transfer a Docker image from one server to another, what you need to do is first export the image to a file, then copy that file over from your current server to the new one using scp or rsync and finally load the image to your new server.

Can I run Windows Server in Docker?

The Microsoft container ecosystem Run Windows-based or Linux-based containers on Windows 10 for development and testing using Docker Desktop, which makes use of containers functionality built-in to Windows. You can also run containers natively on Windows Server.

Does Docker run build the image?

The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.


1 Answers

Your dockerfile installs the 4.6 Targeting pack but no targeting pack for 4.5.2.

The files need to be in

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2

for MSBuild to resolve them correctly

like image 188
Martin Ullrich Avatar answered Oct 11 '22 15:10

Martin Ullrich