title: Docker: Installing .NET Framework in a .NET Core Image
body: <p>I have a .NET 5 project. I want to use Docker to deploy my .NET 5 project.</p>
  <p>In this project, I have to reference a .NET Standard 2.0 project, which references many other projects that, down the line are .NET Framework 4.6.2 projects. It is an overly complicated mess.</p>
  <p>Since I wanted to keep this simple, I didn't bring in all of the projects into one solution. Instead I just have my .NET 5 project and then I've made references to the .dll's that are built for the other projects.</p>
  <p>One of those projects references System.Data.SqlClient.dll, which I've brought into my project and reference directly.</p>
  <p>With my current Dockerfile, I only bring in the .NET 5 sdk and runtime. When my code gets to the point where it needs to load that DLL, I get the error:</p>
  <blockquote>
  <p>system.data.sqlclient not supported on this platform</p>
  </blockquote>
  <p>Of course it isn't, because I don't have the 4.6.2 Framework installed.</p>
  <p>So in my Dockerfile I've added this hoping that it would include it:</p>
  <pre><code>FROM mcr.microsoft.com/dotnet/framework/runtime:4.8
  </code></pre>
  <p>But it didn't.</p>
  <p>Q. How can I install that framework version in my docker image?</p>
  <p>BTW: What I'm doing feels very ugly to me... I'm just bloating my image with old stuff... I know that. I can't help it. It is what I'm working with for now.</p>
  <p>Thanks.</p>
  <p><strong>UPDATE</strong></p>
  <p>Based on a private comment that pointed me to another post (<a href="https://stackoverflow.com/questions/61716440/how-to-install-net-framework-in-docker">How to install .net Framework in docker?</a>), I have tried to start with a window server core image that supposedly has the .NET Framework installed. Then I try to install the .NET 5 runtime and sdk. My dockerfile is below, but:</p>
  <ol>
  <li><p>While this builds and runs in vs.net, when my code runs it cannot find System.Data.SqlClient.</p>
  </li>
  <li><p>When I inspect the container or connect to it interactively with a command prompt, &quot;ver&quot; reports it is Windows 10.0.17763.1879. Shouldn't it give me a windows server 2019 verion number? My &quot;base&quot; in my dockerfile is Window Server 2019, isn't it???</p>
  </li>
  <li><p>When I do dotnet --list-runtimes I see NETCore and AspNetCor 5.0.5</p>
  </li>
  <li><p>When I run powershell in the command prompt I see this:</p>
  <p>Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version</p>
  </li>
  </ol>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>PSChildName</th>
  <th>Version</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Client</td>
  <td>4.7.03190</td>
  </tr>
  <tr>
  <td>Full</td>
  <td>4.7.03190</td>
  </tr>
  <tr>
  <td>Client</td>
  <td>4.0.0.0</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Dockerfile:</p>
  <pre><code>FROM mcr.microsoft.com/windows/servercore:ltsc2019-amd64 AS base
  ENV COMPLUS_NGenProtectedProcess_FeatureEnabled=0
  RUN curl -fSLo patch.msu http://download.windowsupdate.com/c/msdownload/update/software/secu/2021/01/windows10.0-kb4601060-x64_b645458f512391ae20e17e21f01d24183b5076c9.msu &amp;&amp; mkdir patch &amp;&amp; expand patch.msu patch -F:* &amp;&amp; del /F /Q patch.msu &amp;&amp; dism /Online /Quiet /Add-Package /PackagePath:C:\patch\windows10.0-kb4601060-x64.cab &amp;&amp; rmdir /S /Q patch &amp;&amp; %windir%\Microsoft.NET\Framework64\v4.0.30319\ngen uninstall &quot;Microsoft.Tpm.Commands, Version=10.0.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=amd64&quot; &amp;&amp; %windir%\Microsoft.NET\Framework64\v4.0.30319\ngen update &amp;&amp; %windir%\Microsoft.NET\Framework\v4.0.30319\ngen update
  
  ENV ASPNETCORE_ENVIRONMENT Development
  
  #FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
  RUN powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -UseBasicParsing -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; ./dotnet-install.ps1 -InstallDir '/Program Files/dotnet' -Channel 5.0 -Runtime aspnetcore; Remove-Item -Force dotnet-install.ps1 &amp;&amp; setx /M PATH &quot;%PATH%;C:\Program Files\dotnet&quot;
  WORKDIR /app
  EXPOSE 80
  EXPOSE 8001
  
  #FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
  FROM mcr.microsoft.com/windows/servercore:ltsc2019-amd64 AS build
  RUN powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;Invoke-WebRequest -UseBasicParsing -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; ./dotnet-install.ps1 -InstallDir '/Program Files/dotnet' -Channel 5.0; Remove-Item -Force dotnet-install.ps1 &amp;&amp; setx /M PATH &quot;%PATH%;C:\Program Files\dotnet&quot;
  WORKDIR /src
  COPY [&quot;Ess.Api.Auth.csproj&quot;, &quot;.&quot;]
  #COPY [&quot;../../../../VS19Code/Dev/ESS Lib Auth/AuthBO/AuthBO.csproj&quot;, &quot;../../../../VS19Code/Dev/ESS Lib Auth/AuthBO/&quot;]
  RUN dotnet restore &quot;Ess.Api.Auth.csproj&quot;
  COPY . .
  WORKDIR &quot;/src/&quot;
  RUN dotnet build &quot;Ess.Api.Auth.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;Ess.Api.Auth.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;Ess.Api.Auth.dll&quot;]
  </code></pre>