dotnet publish should not include static libraries
See original GitHub issueOn 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 aRuntimeList.xml
file, apparently from the Microsoft.NETCore.App.Runtime.osx-x64 NuGet package in thedata
directory. - The
RuntimeList.xml
file seems to be created by theGenerateRuntimeListFile
target (dotnet/runtime repository). - The
GenerateRuntimeListFile
target calls theCreateFrameworkListFile
MSBuild task (dotnet/arcade repository) to create theRuntimeList.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:
- Created 3 years ago
- Comments:9 (6 by maintainers)
I can confirm that the files no longer show up in RuntimeList.xml after the fix.
@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.