dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.45k stars 4.76k forks source link

`-p:NativeLib=Shared` to be implied in the absence of NativeLib #69369

Closed am11 closed 2 years ago

am11 commented 2 years ago

Using 7.0.100-preview.5.22262.14 daily build.

Create a classlib project using dotnet new classlib and publish it with the following command:

dotnet publish --use-current-runtime -p:PublishAot=true

it fails with the following error:

Microsoft (R) Build Engine version 17.3.0-preview-22256-03+72a076794 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /home/am11/projects/nativelib/nativelib.csproj (in 195 ms).
/home/am11/.dotnet7/sdk/7.0.100-preview.5.22262.14/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(216,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/home/am11/projects/nativelib/nativelib.csproj]
  nativelib -> /home/am11/projects/nativelib/bin/Debug/net7.0/linux-x64/nativelib.dll
  Generating compatible native code. To optimize for size or speed, visit https://aka.ms/OptimizeNativeAOT
EXEC : error : No entrypoint module [/home/am11/projects/nativelib/nativelib.csproj]
  System.Exception: No entrypoint module
     at ILCompiler.Program.Run(String[] args)
     at ILCompiler.Program.Main(String[] args)
/home/am11/.dotnet7/sdk/7.0.100-preview.5.22262.14/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.targets(270,5): error MSB3073: The command ""/home/am11/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.0-preview.5.22258.4/tools/ilc" @"obj/Debug/net7.0/linux-x64/native/nativelib.ilc.rsp"" exited with code 1. [/home/am11/projects/nativelib/nativelib.csproj]

Fix is to specify NativeLib property.

dotnet publish --use-current-runtime -p:PublishAot=true -p:NativeLib=Shared

It would make sense when NativeLib is unspecified for OutputType != Exe, its value is defaulted to Shared by the SDK.

cc @LakshanF, @agocke

am11 commented 2 years ago

It would also be nice to use target platform's default file naming conventions into account: https://github.com/dotnet/runtime/blob/0aa3930099720918adf2e4409fa2189fce0d0e01/eng/native/naming.props#L35 i.e. instead of nativelib1.so, I was expecting libnativelib1.so on linux.