title: Error CS1705 randomly being thrown while building docker image
body: <p>The solution that I'm working on contains following projects:</p>
  <ul>
  <li>Few ASP.Net core web applications with target framework netcoreapp3.1.</li>
  <li>1 BLL class library project with target framework netstandard2.1.</li>
  <li>1 DAL project that can be build as a standalone exe or class library with target frameworks netcoreapp3.1 and netstandard2.1.</li>
  </ul>
  <p>Web applications have a project reference to BLL project which has refrence to DAL project. The problem that I'm facing is while building docker images for web apps there are always multiple warnings <code>warning MSB3277: Found conflicts between different versions of...</code> being shown and sometimes, seemingly randomly, build process throws this error.</p>
  <pre><code>error CS1705: Assembly 'Dal' with identity 'Dal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
  </code></pre>
  <p>Images are build one after another in the Azure DevOps pipeline and most of the time one of the images will fail. The same image may succeed after cleaning docker build cache.</p>
  <p>I've tried specifying target framework of project reference in Bll project like this</p>
  <pre><code>&lt;ProjectReference Include=&quot;..\Dal\Dal.csproj&quot;&gt; 
      &lt;SetTargetFramework&gt;TargetFramework=netstandard2.1&lt;/SetTargetFramework&gt;
  &lt;/ProjectReference&gt;
  </code></pre>
  <p>or this</p>
  <pre><code>&lt;ProjectReference Include=&quot;..\Dal\Dal.csproj&quot; AdditionalProperties=&quot;TargetFramework=netstandard2.1&quot; /&gt;
  </code></pre>
  <p>and adding AutoGenerateBindingRedirects, but the problem still persisted.</p>
  <p>Finally I've fixed the issue by creating copy of Dal.csproj that targets only netstandard2.1 framework and replacing the original file while copying files to docker. Here is the Dockerfile currently being used.</p>
  <pre><code>FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
  WORKDIR /app
  EXPOSE 80
  EXPOSE 443
  
  FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
  WORKDIR /src
  COPY [&quot;src/WebApp1/WebApp1.csproj&quot;, &quot;src/WebApp1/&quot;]
  COPY [&quot;src/Bll/Bll.csproj&quot;, &quot;src/Bll/&quot;]
  # --References conflict workaround--
  COPY [&quot;src/Dal/Copy.Dal.csproj&quot;, &quot;src/Dal/Dal.csproj&quot;]
  # ----
  RUN dotnet restore &quot;src/WebApp1/WebApp1.csproj&quot;
  COPY [&quot;src/WebApp1/&quot;, &quot;src/WebApp1/&quot;]
  COPY [&quot;src/Bll/&quot;, &quot;src/Bll/&quot;]
  # --References conflict workaround--
  COPY [&quot;src/Dal/&quot;, &quot;src/Dal/&quot;]
  COPY [&quot;src/Dal/Copy.Dal.csproj&quot;, &quot;src/Dal/Dal.csproj&quot;]
  CMD rm -rf src/Dal/Copy.Dal.csproj
  # ----
  WORKDIR &quot;/src/src/WebApp1&quot;
  RUN dotnet build &quot;WebApp1.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;WebApp1.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;WebApp1.dll&quot;]
  </code></pre>
  <p>I also assume that this issue can be fixed by splitting Dal project into 2 project one of which would be console app that targets only netcoreapp3.1 while the second one would be class library targeting netstandard2.1.</p>
  <p>My question is, what could be the reason of build process failing from time to time and is there a cleaner solution than those I've presented?</p>