dotnet / runtime

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

[API Proposal]: Expose dotnet info by introducing a new hostfxr API #98735

Open Markliniubility opened 7 months ago

Markliniubility commented 7 months ago

Background and motivation

dotnet SDK intends to implement a new command dotnet info to replace the original dotnet --info. The detail is specified in https://github.com/dotnet/sdk/issues/33697.

However, to implement this new command, we need to have some information exposed in the corehost, which are:

We may make modification to this file to introduce the new API https://github.com/dotnet/runtime/blob/c28bec4d3d63849c9e60dee1e7174b9a180a7e55/src/native/corehost/hostfxr.h#L311-L323

API Proposal

SHARED_API int32_t HOSTFXR_CALLTYPE hostfxr_get_dotnet_host_info(
    const pal::char_t* dotnet_root,
    void* reserved,
    hostfxr_get_dotnet_host_info_result_fn result,
    void* result_context)
{}

API Usage

        [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
        internal delegate void hostfxr_get_dotnet_environment_info_result_fn(
            IntPtr info,
            IntPtr result_context);

        [DllImport(Constants.HostFxr, CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int hostfxr_get_dotnet_host_info(
            .....);

Alternative Designs

No response

Risks

it would require some versioning magic but that doable (the host has to work against any SDK, so it would have to know to do the old thing for the old SDK and the new thing for the new SDK and unfortunately this can't be done through an API since the host literally runs the SDK as an app). ---- mentioned by @vitek-karas

ghost commented 7 months ago

Tagging subscribers to this area: @vitek-karas, @agocke, @vsadov See info in area-owners.md if you want to be subscribed.

Issue Details
### Background and motivation dotnet SDK intends to implement a new command `dotnet info` to replace the original `dotnet --info`. The detail is specified in https://github.com/dotnet/sdk/issues/33697. However, to implement this new command, we need to have some information exposed in the corehost, which are: - Host, - .NET SDKs installed, - .NET runtimes installed, - Other architectures found, - Environment Variables, and - global.json file We may make modification to this file to introduce the new API https://github.com/dotnet/runtime/blob/c28bec4d3d63849c9e60dee1e7174b9a180a7e55/src/native/corehost/hostfxr.h#L311-L323 ### API Proposal ```csharp SHARED_API int32_t HOSTFXR_CALLTYPE hostfxr_get_dotnet_host_info( const pal::char_t* dotnet_root, void* reserved, hostfxr_get_dotnet_host_info_result_fn result, void* result_context) {} ``` ### API Usage ```csharp [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)] internal delegate void hostfxr_get_dotnet_environment_info_result_fn( IntPtr info, IntPtr result_context); [DllImport(Constants.HostFxr, CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] internal static extern int hostfxr_get_dotnet_host_info( .....); ``` ### Alternative Designs _No response_ ### Risks it would require some versioning magic but that doable (the host has to work against any SDK, so it would have to know to do the old thing for the old SDK and the new thing for the new SDK and unfortunately this can't be done through an API since the host literally runs the SDK as an app). ---- mentioned by @vitek-karas
Author: Markliniubility
Assignees: -
Labels: `api-suggestion`, `area-Host`
Milestone: -
jkotas commented 7 months ago

However, to implement this new command, we need to have some information exposed in the corehost,

Can SDK gather most or all of this information in managed code on its own?

For example, it does not make sense for the host to return environment variables. The managed dotnet info command can read the environment just fine.

Markliniubility commented 7 months ago

However, to implement this new command, we need to have some information exposed in the corehost,

Can SDK gather most or all of this information in managed code on its own?

For example, it does not make sense for the host to return environment variables. The managed dotnet info command can read the environment just fine.

Unfortunately, it may be a bit difficult to gather the information within the sdk repo. The current dotnet --info obtain the information from corehost as well. Ref. https://github.com/dotnet/runtime/blob/9da53590c9d624b51fddcfb85f76641c78a415d4/src/native/corehost/fxr/command_line.cpp#L283

The corehost will print out the info when there is a command dotnet --info.

Markliniubility commented 7 months ago

Some earlier discussions for this API proposal: https://github.com/dotnet/sdk/pull/36943