-
Notifications
You must be signed in to change notification settings - Fork 131
Improve auto-discovery of configuration assemblies in bundled mode #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e2a7573
to
d874b52
Compare
Neither the dependency context nor scanning DLL files on disk works with bundled (single-file) applications. Given that the configuration assemblies have actually been loaded, using `AppDomain.CurrentDomain.GetAssemblies()` works for both bundled and non bundled applications.
d874b52
to
cad35a0
Compare
Thanks for tackling this, @0xced! 👏 Just a thought, since it's necessary in this mode to list assemblies specifically, could we get away from needing any scanning code at all (in 'bundled' mode), and just list all dependencies in the E.g. for your example: loggerConfiguration.ReadFrom.Configuration(
context.Configuration,
usingAssemblies: new[]
{
typeof(ConsoleLoggerConfigurationExtensions).Assembly,
typeof(SeqLoggerConfigurationExtensions).Assembly
}) |
By reading the deps json directly from the application host the with the help of the`Microsoft.NET.HostModel` package.
* Test with both IncludeAllContentForSelfExtract as true and false * Don't show a window when building the single file app * Make sure the test pass on all tested platforms by adding a global.json file
This is a proof-of-concept implementation (using an internal method of the Microsoft.NET.HostModel package) to ensure that all tests pass also on Windows.
You're absolutely right about explicitly passing the assemblies to the But I think we can do even better and having the configuration assemblies automatically discovered even in bundled mode. I tried something in d8d162c which works fine on macOS but fails on Windows. I implemented a proof-of-concept workaround in 3d2e5df which relies on an internal method of the Ideally, this logic should be implemented in the Microsoft.Extensions.DependencyModel project directly. I'll probably try to submit a pull request there so that eventually using |
a228109
to
0f21889
Compare
Also fix possible concurrency issue by using different bin and obj directories.
As [stated by Vitek Karas][1]: > Also note that the `Microsoft.NET.HostModel` package is not intended as a public API, it's only intended use is from the SDK. [1]: dotnet/runtime#67386 (comment)
0f21889
to
11bc6de
Compare
I have rewritten the code (in 11bc6de) to read the bundled deps.json without taking a dependency on The hardest part was to write the This pull request is now ready for review. |
Hi @0xced - thanks for the follow-up! I'd be a little anxious to take this kind of dependency on the (undocumented?) bundle manifest and (loosely documented but possibly changeable?) .deps file formats; my guess is that the Still does make a nice job of addressing a tricky scenario, though - I might need to give it a bit more thought. @serilog/reviewers-configuration any sense of what would be best, here? |
Toying around with single file apps and the deps.json file was a fun and very educative experiment. I learned a ton of things about single file apps by reading the design documents and the CoreCLR source code. But eventually it should really be implemented at the Microsoft.Extensions.DependencyModel level. I have even created a repository and written technical notes and thoughts in the README: https://github.com/0xced/SingleFileAppDependencyContext I took some code written for In the end the best solution to avoid listing assemblies in the configuration file is probably what you proposed in your initial reply, i.e. explicitly passing a list of assemblies to the Would you be interested in a pull request to implement this new |
Okay, great to know! 😎 I'm not well-placed to review this currently, but gets a 👍 from me in case @skomis-mm or another maintainer is able to dig in deeply enough. |
Closing this pull request in favor of #310. Leaving https://github.com/0xced/SingleFileAppDependencyContext as a record of the work I did that should eventually be part of Microsoft.Extensions.DependencyModel. |
Neither the dependency context nor scanning DLL files on disk works with bundled (single-file) applications.
Given that the configuration assemblies have actually been loaded, using
AppDomain.CurrentDomain.GetAssemblies()
works for both bundled and non bundled applications.