Friday, May 6, 2011

SQL Server Compact Toolbox standalone - including all managed DLLs in a single .exe

The latest release of the standalone version of my SQL Server Compact Toolbox, mainly for users that do not have Visual Studio 2010 Pro or higher, is available as a single .exe. It was actually a Tweet from @scottgal, that pointed me towards this excerpt from Jeffery Richters’ CLR via C#, Third Edition.

In order to implement in the WPF application, that is the standalone Toolbox, I added the following code to App.xaml.cs (and a Startup handler to App.xaml):

private void Application_Startup(object sender, StartupEventArgs e)
AppDomain.CurrentDomain.AssemblyResolve += (ssender, args) =>
//string[] names = this.GetType().Assembly.GetManifestResourceNames();

String resourceName = "ErikEJ.SqlCeToolbox." +
new AssemblyName(args.Name).Name + ".dll";

using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);


I also added all the Managed libraries that the Toolbox uses as Embedded Resources.
I use the following libraries, all from CodePlex:
WPF Property Grid (for the SqlCeConnectionStringBuilder)
Sample usage
KBCsv (for .csv file import)
Sample usage
SQL Server Compact Scripting Library (for database scripting)
Sample usage Sample usage
FabTab WPF Tab Control (the SQL Editor tabs)
Sample usage

And the Microsoft Data Connection Dialog (to prompt fro a SQL Server Connection) from
Sample usage
Hope you find this tip useful.

No comments: