標籤:
在EF6使用Sqlite的時候。Sqlite需要安裝sqlite-netFx40-setup-bundle-x64-2010-1.0.97.0.exe。我不想在項目發布的時候,安裝的時候執行該程式,於是看到了打包過程中,Sqlite安裝程式實際是執行的註冊,於是分析了執行的命令提示介面。發現只對三個dll使用C:\Windows\Microsoft.NET\Framework\v4.0.30319\Ngen.exe 執行註冊。
於是使用C#程式執行註冊即可。
Console.WriteLine("正在添加註冊表項...");
RegistryKey key = Registry.LocalMachine;
RegistryKey software = key.CreateSubKey(@"SOFTWARE\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx");
//註冊EF string executeFile = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Ngen.exe"; string[] dllNames = new string[]{ @"System.Data.SQLite.Linq.dll" ,//1 @"System.Data.SQLite.EF6.dll",//2 @"System.Data.SQLite.dll" }; //執行註冊 for (int i = 0; i < dllNames.Length; i++) { //構建註冊語句 string installCommand = string.Format("{0} {1}{2}{3}", "install", (char)34, dllNames[i],(char)34); Process installProcess = Process.Start(executeFile, installCommand); Console.WriteLine("正在註冊{0},請等待...", dllNames[i]); installProcess.WaitForExit(); }
Sqlite EF6註冊