Skip to content

Provide a hostfxr API for resolving runtime frameworks #99027

Closed

Description

@elinor-fung

There is currently no way to run the host's runtime framework resolution algorithm in an isolated manner. This can be helpful for doing things like determining whether an application would be able to run on the current environment.

We could add a hostfxr_resolve_runtime_frameworks that acts as a parallel to hostfxr_resolve_sdk. Something like:

struct hostfxr_framework_result
{
    size_t size;
    const char_t* name;
    const char_t* requested_version;
    const char_t* resolved_version;
    const char_t* resolved_path;
};

struct hostfxr_resolve_frameworks_result
{
    size_t size;

    size_t resolved_count;
    const struct framework_result* resolved_frameworks;

    size_t unresolved_count;
    const struct framework_result* unresolved_frameworks;
};

typedef void (*hostfxr_resolve_frameworks_result_fn)(
    const hostfxr_resolve_frameworks_result* result,
    void* result_context);

// runtime_config_path : path to the runtime config file
// parameters          : additional parameters for initialization
//                       if null or dotnet_root is null, the root corresponding to the running hostfxr is used
// callback            : invoked with the result of the resolution
// result_context      : additional context passed to the callback
int32_t hostfxr_resolve_frameworks_for_runtime_config(
    const char_t* runtime_config_path,
    /*opt*/ const hostfxr_initialize_parameters* parameters,
    /*opt*/ hostfxr_resolve_frameworks_result_fn callback,
    /*opt*/ void* result_context);

Related:

cc @agocke @JL03-Yue

Activity

  1. added this to the 9.0.0 milestone on Feb 28, 2024
  2. JL03-Yue commented on Feb 28, 2024

    @JL03-Yue

    @elinor-fung Thank you so much for putting up the issue. I would love to keep this updated and keep following up with the issue.

  3. vitek-karas commented on Feb 28, 2024

    @vitek-karas
    Member

    Looks great to me.

    For future considerations - I vaguely remember scenarios where this would help if the input was not a file but some in-memory data structure describing the required dependencies. I think WiX installers wanted something like that - workaround is to write a temp config file to disk, but that's obviously not ideal.

  4. jkoritzinsky commented on Feb 28, 2024

    @jkoritzinsky
    Member

    I had a scenario where I don't have a runtimeconfig file on disk and would like to use this API. I'm currently using hostfxr_get_dotnet_environment_info to get something that works. (code is at https://github.com/AaronRobinsonMSFT/DNMD/blob/master/test/regpal/pal.cpp#L154).

    Especially having an API that operates on the installation/layout that the hostfxr is present in when unspecified instead of the global installation would be very useful.

  5. elinor-fung commented on Feb 29, 2024

    @elinor-fung
    MemberAuthor

    For future considerations - I vaguely remember scenarios where this would help if the input was not a file but some in-memory data structure describing the required dependencies.

    Maybe hostfxr_resolve_runtime_frameworks -> hostfxr_resolve_frameworks_for_runtime_config for this one then. So we don't have to figure out some horrible name for an in-memory data structure version.

    Especially having an API that operates on the installation/layout that the hostfxr is present in when unspecified instead of the global installation would be very useful.

    That is what the hostfxr_initialize_* functions do. I think it would be reasonable for this one to do the same. For the functions for getting environment information like hostfxr_get_dotnet_environment_info and hostfxr_get_available_sdks, I could see having some sentinel value that could be passed as dotnet_root to indicate that the running hostfxr should be used.

  6. locked and limited conversation to collaborators on Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions