public static AddCacheAssembly ( string strAssemblyPath, KeePass.Plugins.PlgxPluginInfo plgx ) : string | ||
strAssemblyPath | string | |
plgx | KeePass.Plugins.PlgxPluginInfo | |
return | string |
private static string Compile(string strTmpRoot, PlgxPluginInfo plgx, string strBuildPre, string strBuildPost) { if (strTmpRoot == null) { Debug.Assert(false); return(null); } RunBuildCommand(strBuildPre, UrlUtil.EnsureTerminatingSeparator( strTmpRoot, false), null); PlgxCsprojLoader.LoadDefault(strTmpRoot, plgx); List <string> vCustomRefs = new List <string>(); foreach (string strIncRefAsm in plgx.IncludedReferencedAssemblies) { string strSrcAsm = plgx.GetAbsPath(UrlUtil.ConvertSeparators( strIncRefAsm)); string strCached = PlgxCache.AddCacheFile(strSrcAsm, plgx); if (string.IsNullOrEmpty(strCached)) { throw new InvalidOperationException(); } vCustomRefs.Add(strCached); } CompilerParameters cp = plgx.CompilerParameters; cp.OutputAssembly = UrlUtil.EnsureTerminatingSeparator(strTmpRoot, false) + UrlUtil.GetFileName(PlgxCache.GetCacheFile(plgx, false, false)); cp.GenerateExecutable = false; cp.GenerateInMemory = false; cp.IncludeDebugInformation = false; cp.TreatWarningsAsErrors = false; cp.ReferencedAssemblies.Add(WinUtil.GetExecutable()); foreach (string strCustomRef in vCustomRefs) { cp.ReferencedAssemblies.Add(strCustomRef); } cp.CompilerOptions = "-define:" + GetDefines(); CompileEmbeddedRes(plgx); PrepareSourceFiles(plgx); string[] vCompilers; Version vClr = Environment.Version; int iClrMajor = vClr.Major, iClrMinor = vClr.Minor; if ((iClrMajor >= 5) || ((iClrMajor == 4) && (iClrMinor >= 5))) { vCompilers = new string[] { null, "v4.5", "v4", // Suggested in CodeDomProvider.CreateProvider doc "v4.0", // Suggested in community content of the above "v4.0.30319", // Deduced from file system "v3.5" }; } else if (iClrMajor == 4) // 4.0 { vCompilers = new string[] { null, "v4", // Suggested in CodeDomProvider.CreateProvider doc "v4.0", // Suggested in community content of the above "v4.0.30319", // Deduced from file system "v4.5", "v3.5" }; } else // <= 3.5 { vCompilers = new string[] { null, "v3.5", "v4", // Suggested in CodeDomProvider.CreateProvider doc "v4.0", // Suggested in community content of the above "v4.0.30319", // Deduced from file system "v4.5" }; } CompilerResults cr = null; StringBuilder sbCompilerLog = new StringBuilder(); bool bCompiled = false; for (int iCmp = 0; iCmp < vCompilers.Length; ++iCmp) { if (CompileAssembly(plgx, out cr, vCompilers[iCmp])) { bCompiled = true; break; } if (cr != null) { AppendCompilerResults(sbCompilerLog, vCompilers[iCmp], cr); } } if (!bCompiled) { if (Program.CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null) { SaveCompilerResults(plgx, sbCompilerLog); } throw new InvalidOperationException(); } Program.TempFilesPool.Add(cr.PathToAssembly); Debug.Assert(cr.PathToAssembly == cp.OutputAssembly); string strCacheAsm = PlgxCache.AddCacheAssembly(cr.PathToAssembly, plgx); RunBuildCommand(strBuildPost, UrlUtil.EnsureTerminatingSeparator( strTmpRoot, false), UrlUtil.GetFileDirectory(strCacheAsm, true, false)); return(strCacheAsm); }
private static string Compile(string strTmpRoot, PlgxPluginInfo plgx, string strBuildPre, string strBuildPost) { if (strTmpRoot == null) { Debug.Assert(false); return(null); } RunBuildCommand(strBuildPre, UrlUtil.EnsureTerminatingSeparator( strTmpRoot, false), null); PlgxCsprojLoader.LoadDefault(strTmpRoot, plgx); List <string> vCustomRefs = new List <string>(); foreach (string strIncRefAsm in plgx.IncludedReferencedAssemblies) { string strSrcAsm = plgx.GetAbsPath(UrlUtil.ConvertSeparators( strIncRefAsm)); string strCached = PlgxCache.AddCacheFile(strSrcAsm, plgx); if (string.IsNullOrEmpty(strCached)) { throw new InvalidOperationException(); } vCustomRefs.Add(strCached); } CompilerParameters cp = plgx.CompilerParameters; cp.OutputAssembly = UrlUtil.EnsureTerminatingSeparator(strTmpRoot, false) + UrlUtil.GetFileName(PlgxCache.GetCacheFile(plgx.FileUuid, false, false)); cp.GenerateExecutable = false; cp.GenerateInMemory = false; cp.IncludeDebugInformation = false; cp.TreatWarningsAsErrors = false; cp.ReferencedAssemblies.Add(WinUtil.GetExecutable()); foreach (string strCustomRef in vCustomRefs) { cp.ReferencedAssemblies.Add(strCustomRef); } CompileEmbeddedRes(plgx); PrepareSourceFiles(plgx); CompilerResults cr; if (!CompileAssembly(plgx, out cr, null)) { if (!CompileAssembly(plgx, out cr, "v3.5")) { throw new InvalidOperationException(); } } Program.TempFilesPool.Add(cr.PathToAssembly); Debug.Assert(cr.PathToAssembly == cp.OutputAssembly); string strCacheAsm = PlgxCache.AddCacheAssembly(cr.PathToAssembly, plgx); RunBuildCommand(strBuildPost, UrlUtil.EnsureTerminatingSeparator( strTmpRoot, false), UrlUtil.GetFileDirectory(strCacheAsm, true, false)); return(strCacheAsm); }