question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet publish should not include static libraries

See original GitHub issue

On macOS (and maybe also on Linux, I have not tried) five static libraries end up in the publish directory when publishing an executable with dotnet publish -c Release -r osx-x64 (reproducible with a hello world console app):

  • libSystem.IO.Compression.Native.a
  • libSystem.Native.a
  • libSystem.Net.Security.Native.a
  • libSystem.Security.Cryptography.Native.Apple.a
  • libSystem.Security.Cryptography.Native.OpenSsl.a

Those are not required at runtime (only dynamic libraries are used) and should not be included in the publish directory.

As a workaround I have added this in my csproj file:

<Target Name="RemoveStaticLibraries" AfterTargets="ResolveRuntimePackAssets">
  <ItemGroup>
    <RuntimePackAsset Remove="@(RuntimePackAsset)" Condition="'%(Extension)' == '.a'" />
    <ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)' == '.a'" />
  </ItemGroup>
</Target>

Ideally this workaround should not be needed and the SDK should be responsible for not publishing the static library files.

Technical details (gathered by analyzing the binary build log with MSBuild Log Viewer, reading and grepping source code in dotnet repositories):

  • The static library files are copied into the publish directory because they are part of the output of the ResolveRuntimePackAssets MSBuild task.
  • The ResolveRuntimePackAssets MSBuild task reads a RuntimeList.xml file, apparently from the Microsoft.NETCore.App.Runtime.osx-x64 NuGet package in the data directory.
  • The RuntimeList.xml file seems to be created by the GenerateRuntimeListFile target (dotnet/runtime repository).
  • The GenerateRuntimeListFile target calls the CreateFrameworkListFile MSBuild task (dotnet/arcade repository) to create the RuntimeList.xml file.

I think that what should be fixed is the RuntimePackNativeFile item. It includes everything $(MicrosoftNetCoreAppRuntimePackNativeDir)*.* but should probably exclude .a files. I’ll let someone at Microsoft more exerienced than me confirm my intuition though.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
akoeplingercommented, Oct 28, 2020

I can confirm that the files no longer show up in RuntimeList.xml after the fix.

0reactions
vitek-karascommented, Oct 9, 2020

@0xced sorry I don’t remember the details anymore. I agree they should not be mentioned anywhere in the runtime pack, but I don’t know if my “fix” actually fixes the runtime list.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet publish command - .NET CLI
dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files ...
Read more >
Static libraries
NET 7, using Native AOT with static libraries is implemented, but is not yet considered a supported and documented feature.
Read more >
c# - .NET Core include folder in publish
First solution, if run dotnet build or dotnet publish will add the folder inside bin. <ItemGroup> <None Update="AppData\**" ...
Read more >
[NET 7] NativeAOT-compiled static library is not exporting ...
I am trying to compile my managed code into a static library (.lib file on win-x64), so I can link against it from...
Read more >
Creating a Static Web Content Project for Publishing with ...
I've been working on updating a small and old customer application that is directly deployed to an IIS Web server. The app goes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found