-
Notifications
You must be signed in to change notification settings - Fork 216
Expose function for locating hostfxr #5522
Changes from all commits
80826c1
a840455
bfff90f
986153b
7501fd8
e728a62
e371f6e
206eed4
459e372
de05524
4673b68
1dbdece
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Licensed to the .NET Foundation under one or more agreements. | ||
| # The .NET Foundation licenses this file to you under the MIT license. | ||
| # See the LICENSE file in the project root for more information. | ||
|
|
||
| cmake_minimum_required (VERSION 2.6) | ||
| project(nethost) | ||
|
|
||
| set(DOTNET_PROJECT_NAME "nethost") | ||
|
|
||
| # Include directories | ||
| include_directories(../fxr) | ||
|
|
||
| # CMake does not recommend using globbing since it messes with the freshness checks | ||
| set(SOURCES | ||
| nethost.cpp | ||
| ../fxr_resolver.cpp | ||
| ../fxr/fx_ver.cpp | ||
| ) | ||
|
|
||
| include(../lib.cmake) | ||
|
|
||
| add_definitions(-DFEATURE_LIBHOST=1) | ||
| add_definitions(-DNETHOST_EXPORT) | ||
|
|
||
| install(FILES nethost.h DESTINATION corehost) | ||
| install(TARGETS nethost DESTINATION corehost) | ||
| install_symbols(nethost corehost) | ||
|
jkoritzinsky marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| #include "nethost.h" | ||
| #include <error_codes.h> | ||
| #include <fxr_resolver.h> | ||
| #include <pal.h> | ||
| #include <trace.h> | ||
| #include <utils.h> | ||
|
|
||
| namespace | ||
| { | ||
| // Swallow the trace messages so we don't output to stderr of a process that we do not own unless tracing is enabled. | ||
| void swallow_trace(const pal::char_t* msg) | ||
| { | ||
| (void)msg; | ||
| } | ||
| } | ||
|
|
||
| NETHOST_API int NETHOST_CALLTYPE nethost_get_hostfxr_path( | ||
| char_t * result_buffer, | ||
| size_t buffer_size, | ||
| size_t * out_buffer_required_size, | ||
| const char_t * assembly_path) | ||
| { | ||
| if (out_buffer_required_size == nullptr) | ||
|
elinor-fung marked this conversation as resolved.
|
||
| return StatusCode::InvalidArgFailure; | ||
|
|
||
| trace::setup(); | ||
| error_writer_scope_t writer_scope(swallow_trace); | ||
|
|
||
| pal::string_t root_path; | ||
| if (assembly_path != nullptr) | ||
| root_path = get_directory(assembly_path); | ||
|
|
||
| pal::string_t dotnet_root; | ||
| pal::string_t fxr_path; | ||
| if(!fxr_resolver::try_get_path(root_path, &dotnet_root, &fxr_path)) | ||
| return StatusCode::CoreHostLibMissingFailure; | ||
|
|
||
| size_t len = fxr_path.length(); | ||
| size_t required_size = len + 1; // null terminator | ||
|
|
||
| *out_buffer_required_size = required_size; | ||
| if (result_buffer == nullptr || buffer_size < required_size) | ||
| return StatusCode::HostApiBufferTooSmall; | ||
|
|
||
| fxr_path.copy(result_buffer, len); | ||
| result_buffer[len] = '\0'; | ||
| return StatusCode::Success; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| #ifndef __NETHOST_H__ | ||
| #define __NETHOST_H__ | ||
|
|
||
| #include <cstddef> | ||
|
|
||
| #if defined(_WIN32) | ||
| #ifdef NETHOST_EXPORT | ||
| #define NETHOST_API __declspec(dllexport) | ||
| #else | ||
| #define NETHOST_API __declspec(dllimport) | ||
| #endif | ||
|
|
||
| #define NETHOST_CALLTYPE __stdcall | ||
|
AaronRobinsonMSFT marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is different from all the other libraries (
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vitek-karas Bah... Yes, you are right. The rest of the core-setup API is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - and I like the consistency among the "public" hosts.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elinor-fung In a previous review @vitek-karas mentioned the need for documentation of these kinds of contracts. I think the fact that we are starting to coalesce around common user scenarios using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say we need a new one. Maybe what gets created for #5481 would be a reasonable place (if it is a doc for all exposed APIs - I could also see doing a separate 'advanced' |
||
| #ifdef _WCHAR_T_DEFINED | ||
| using char_t = wchar_t; | ||
| #else | ||
| using char_t = unsigned short; | ||
| #endif | ||
| #else | ||
| #ifdef NETHOST_EXPORT | ||
| #define NETHOST_API __attribute__((__visibility__("default"))) | ||
| #else | ||
| #define NETHOST_API | ||
| #endif | ||
|
|
||
| #define NETHOST_CALLTYPE | ||
| using char_t = char; | ||
| #endif | ||
|
|
||
| // | ||
| // Get the path to the hostfxr library | ||
| // | ||
| // Parameters: | ||
| // result_buffer | ||
| // Buffer that will be populated with the hostfxr path, including a null terminator. | ||
| // | ||
| // buffer_size | ||
| // Size of result_buffer in char_t units | ||
| // | ||
| // out_buffer_required_size | ||
| // Minimum required size in char_t units for a buffer to hold the hostfxr path | ||
| // | ||
| // assembly_path | ||
| // Optional. Path to the compenent's assembly. Whether or not this is specified | ||
| // determines the behaviour for locating the hostfxr library. | ||
| // If nullptr, hostfxr is located using the enviroment variable or global registration | ||
| // If specified, hostfxr is located as if the assembly_path is the apphost | ||
| // | ||
| // Return value: | ||
| // 0 on success, otherwise failure | ||
| // 0x80008098 - result_buffer is too small (HostApiBufferTooSmall) | ||
| // | ||
| // Remarks: | ||
| // The full search for the hostfxr library is done on every call. To minimize the need | ||
| // to call this function multiple times, pass a large result_buffer (e.g. PATH_MAX). | ||
| // | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 - it's great that you wrote this as a header which we can give out to external users of the library. |
||
| extern "C" NETHOST_API int NETHOST_CALLTYPE nethost_get_hostfxr_path( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it expected that native hosters carry this dll with them rather than it being app local? Ex if I have a global module, and I wanted to find hostfxr, I would need to have nethost.dll sit side by side with my global module?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the expectation is that a native host application will ship this library as part of the application itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I need a bit of clarification. The expectation is that a published app will contain the nethost.dll, like: Also, is the nethost.dll opt-in or opt-out?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Basically the ASP.NET IIS module has the "locate hostfxr" code copied into it today, with this it would just carry it as a separate dll. We don't have a delivery vehicle yet, but we're thinking native (C/C++) NuGet package and probably just raw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our IIS module today installs via an msi, so I'd imagine we should probably include it SxS with the module. Once we get new bits from core-setup, I will start prototyping and see if all scenarios we used to support still work with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jkotalik Just to clarify for me
This means that you would package the Re the compatibility - if that's not the case (that is you find a case where it works differently then your existing code), please let us know. It's using the same code as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes I believe that is the best course of action.
I'm less concerned about that than some of the backups we did. For example, if all else fails with finding dotnet, we search in C:\PF\dotnet as a backup. So we will see! |
||
| char_t * result_buffer, | ||
| size_t buffer_size, | ||
| size_t * out_buffer_required_size, | ||
| const char_t * assembly_path); | ||
|
|
||
| #endif // __NETHOST_H__ | ||
Uh oh!
There was an error while loading. Please reload this page.