Some people on here are probably familiar with this blog entry about Merging Telerik's Assemblies into an WPF executable. We actually decided to take a completely different spin and wanted to just merge the Telerik assemblies only leaving all our others untouched (our program as a plug-gable module architecture so we can't merge ALL assemblies). I'm not sure if any one else would be interested in this but I wanted to post it anyway just to get it out there that it is possible.
MSBuild AfterResolveReferences:
Program.cs:
We also did an additional spin with a PostBuildEvent of deleting the Telerik files after the build.
PostBuildEvent:
I hope someone else finds this useful as we did.
MSBuild AfterResolveReferences:
<
Target
Name
=
"AfterResolveReferences"
>
<
ItemGroup
>
<
EmbeddedResource
Include
=
"@(ReferenceCopyLocalPaths)"
Condition
=
"$([System.Text.RegularExpressions.Regex]::IsMatch(%(ReferenceCopyLocalPaths.Filename), 'Telerik')) And '%(ReferenceCopyLocalPaths.Extension)' == '.dll'"
>
<
LogicalName
>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</
LogicalName
>
</
EmbeddedResource
>
</
ItemGroup
>
</
Target
>
Program.cs:
namespace
WpfApplication1{
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Reflection;
public
class
Program
{
[STAThreadAttribute]
public
static
void
Main()
{
var assemblies =
new
Dictionary<
string
, Assembly>();
var executingAssembly = Assembly.GetExecutingAssembly();
var resources = executingAssembly.GetManifestResourceNames().Where(n => n.StartsWith(
"Telerik"
)).Where(n => n.EndsWith(
".dll"
));
foreach
(
string
resource
in
resources)
{
using
(var stream = executingAssembly.GetManifestResourceStream(resource))
{
if
(stream ==
null
)
continue
;
var bytes =
new
byte
[stream.Length];
stream.Read(bytes, 0, bytes.Length);
try
{
assemblies.Add(resource, Assembly.Load(bytes));
}
catch
(Exception ex)
{
System.Diagnostics.Debug.Print(
string
.Format(
"Failed to load: {0}, Exception: {1}"
, resource, ex.Message));
}
}
}
AppDomain.CurrentDomain.AssemblyResolve += (s, e) =>
{
var assemblyName =
new
AssemblyName(e.Name);
var path =
string
.Format(
"{0}.dll"
, assemblyName.Name);
if
(assemblies.ContainsKey(path))
{
return
assemblies[path];
}
return
null
;
};
App.Main();
}
}
}
We also did an additional spin with a PostBuildEvent of deleting the Telerik files after the build.
PostBuildEvent:
<
PropertyGroup
>
<
PostBuildEvent
>del /F /Q "$(TargetDir)Telerik*"
rmdir /S /Q "$(TargetDir)de"
rmdir /S /Q "$(TargetDir)es"
rmdir /S /Q "$(TargetDir)fr"
rmdir /S /Q "$(TargetDir)it"
rmdir /S /Q "$(TargetDir)nl"
rmdir /S /Q "$(TargetDir)tr"</
PostBuildEvent
>
</
PropertyGroup
>
I hope someone else finds this useful as we did.