dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

System.Drawing.Common.dll is not added to Net Core build output #5312

Closed Persimus closed 4 years ago

Persimus commented 4 years ago

Steps to reproduce

Create an application for .Net Core add System.Drawing.Common Nuget or Direct dll reference, and build. You will see that the dll is not in the output directory.

This issue causes runtime errors in Linux containers if you run Build and Publish processes on Windows machine or TFS server and then try to run them on Linux container. When processes that needs dll to run is called exception is thrown: "System.IO.FileNotFoundException: Could not load file or assembly 'System.Drawing.Common'", otherwise no build or deploy issues were observed.

Issue observed after updating From: Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core To: Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core

Project file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
  </ItemGroup>

</Project>

Expected behavior

System.Drawing.Common.dll is in output directory

Actual behavior

System.Drawing.Common.dll is not added

OS info: Windows 10, TFS server

If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc): Build Engine version 16.5.0+d4cbfca49 for .NET Core

KirillOsenkov commented 4 years ago

Hi @Persimus have you tried using https://msbuildlog.com to obtain a .binlog from your scenario and investigate it? You can search for did not copy System.Drawing.Common.dll in the log viewer.

Here's a more detailed article about how to investigate issues like these: https://github.com/microsoft/msbuild/blob/master/documentation/wiki/ResolveAssemblyReference.md

Persimus commented 4 years ago

Thank you @KirillOsenkov for sharing the tool. It seems that on 16.5 the System.Drawing.Common and some other libraries in my project are set to CopyLocal = false while I assume on older version 16.4 it was set to CopyLocal = true

KirillOsenkov commented 4 years ago

Hmm, this is interesting. I am able to reproduce, and indeed the files are not copied to output at all.

Not sure how, if ever, it used to work before.

I do see that ResolvePackageAssets adds the .dll to the RuntimeCopyLocalItems: image

Aha, but I do see that if you set the CopyLocalLockFileAssemblies to true they will get copied:

msbuild /r /bl 1.csproj /p:CopyLocalLockFileAssemblies=true

Or, in the .csproj file:

<PropertyGroup>
  <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

Can you try that and see if it works? Not sure if it's a bug or by-design, and whether it's documented anywhere.

KirillOsenkov commented 4 years ago

I've filed an issue here to clarify and document this behavior so it's not so confusing: https://github.com/microsoft/msbuild/issues/5321

Meanwhile, @Persimus have you tried invoking dotnet publish or msbuild /r /bl /t:Publish? This should produce properly laid out output and copy all the necessary things.

Persimus commented 4 years ago

I think I need to elaborate as my issue is a bit more complex. I am using EPPlus package in one of my libraries to generate Excel file, it has a System.Drawing.Common as one of their dependencies. So my dependency tree look like this:

At first (a year ago) I had some issues with System.Drawing.Common library not appearing in the publish (as I needed to be in Linux container) so I added to my ExcelLibrary, like this:

Everything worked fine, build on my machine and TFS build server generated dll and I pushed TFS published content directly into my pod as dlls in my deploy pipeline.

System worked as intended until MSbuild 16.5 update, I am sure about cause of the problem because I have two almost identical builds an hour apart of which first worked fine and the second had missing dlls in its artifacts, only difference Build Engine version.

So now what I have tried, and what doesn't work:

Any additional possible solutions are welcome.

KirillOsenkov commented 4 years ago

@cdmihai

rainersigwald commented 4 years ago

This issue was moved to dotnet/sdk#11489