Skip to content
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

Ship with task that packs as resource. #59

Open
JohanLarsson opened this issue Jul 31, 2019 · 11 comments
Open

Ship with task that packs as resource. #59

JohanLarsson opened this issue Jul 31, 2019 · 11 comments

Comments

@JohanLarsson
Copy link
Member

@jnm2 if you feel like flexing some mad skills!

@jnm2
Copy link
Contributor

jnm2 commented Jul 31, 2019

This is IL-weaving a module initializer to resolve assemblies from resources? I'd want to make a standalone package for this if it was me.

@JohanLarsson
Copy link
Member Author

Stand alone to make it opt-in?

@jnm2
Copy link
Contributor

jnm2 commented Jul 31, 2019

Standalone NuGet package that does absolutely nothing else

@jnm2
Copy link
Contributor

jnm2 commented Jul 31, 2019

Maybe that's too hard. Starting small might be better.

@JohanLarsson
Copy link
Member Author

JohanLarsson commented Jul 31, 2019

We have a real use case in this lib.
Avoid sln browser looking like this:
image

Also nuget has a bug that removes the first instance of the helper lib and breaks things if many analyzers using it are installed using different versions. This is the real reason, sln browser is mostly OCD.

@jnm2
Copy link
Contributor

jnm2 commented Jul 31, 2019

I actually really do want to do this. You might have successfully nerd-sniped me

@JohanLarsson
Copy link
Member Author

We could start with the merged package Gu.Roslyn.Extensions only. A single dll, maybe it will not be insanely complicated.

  1. Add it as resource
  2. Inject module ctor.

@jnm2
Copy link
Contributor

jnm2 commented Aug 1, 2019

@JohanLarsson There's a bit of a problem. You'll need to target a framework that has AppDomain.AssemblyResolve or AssemblyLoadContext.Default.Resolving.

https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.assemblyresolve#applies-to

Min .NET Standard 2.0/.NET Core 2.0/.NET Framework 1.1.

(.NET Core 2.1 is the earliest version supported by Microsoft.)

@JohanLarsson
Copy link
Member Author

Ah, we save it for next version then. Plan is to bump to roslyn 3, netstandard 2 & C#8 soon. Not that C#8 has anything to do with this.

@JohanLarsson
Copy link
Member Author

We could potentially hack around the missing event with a try-catch:

try
{
    _ = typeof(TypeInResourceAssembly);
}
catch (SomeException e)
{
    using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Some.dll"))
    {
        var bytes = new byte[(int)stream.Length];
        stream.Read(bytes, 0, (int)stream.Length);
        Assembly.Load(bytes);
    }
}

Not elegant but may work.

@jnm2
Copy link
Contributor

jnm2 commented Aug 1, 2019

Ah, eager load. Hmm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants