Created
December 7, 2017 20:13
-
-
Save Rene-Sackers/19da2b79343acf55ea3356417596bd5f to your computer and use it in GitHub Desktop.
Embedded .dlls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program | |
{ | |
[STAThread] | |
public static void Main() | |
{ | |
AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; | |
App.Main(); | |
} | |
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args) | |
{ | |
var executingAssembly = Assembly.GetExecutingAssembly(); | |
var assemblyName = new AssemblyName(args.Name); | |
var path = assemblyName.Name + ".dll"; | |
if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false) | |
{ | |
path = $@"{assemblyName.CultureInfo}\{path}"; | |
} | |
using (var stream = executingAssembly.GetManifestResourceStream(path)) | |
{ | |
if (stream == null) | |
return null; | |
var assemblyRawBytes = new byte[stream.Length]; | |
stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length); | |
return Assembly.Load(assemblyRawBytes); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Target Name="AfterResolveReferences"> | |
<ItemGroup> | |
<EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll' Or '%(ReferenceCopyLocalPaths.Extension)' == '.config'"> | |
<LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName> | |
</EmbeddedResource> | |
</ItemGroup> | |
</Target> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment