public DepsLessHelper(DepsLessSetting setting, string name) { ProjectFolder = setting.ProjectFolder; ExeFile = Path.Combine(ProjectFolder, setting.ExeFileName); DepsJsonPath = Path.Combine(ProjectFolder, Path.GetFileNameWithoutExtension(setting.ExeFileName) + ".deps.json"); DepsJsonBakPath = Path.Combine(ProjectFolder, Path.GetFileNameWithoutExtension(setting.ExeFileName) + ".deps.json.bak"); if (File.Exists(DepsJsonBakPath) == false) { File.Copy(DepsJsonPath, DepsJsonBakPath); } SettingName = name; CheckUrls = setting.CheckUrls ?? new List <CheckUrl>(); #region 解析 必要文件 与 删除文件 NeedDllNames = new List <string>(); if (setting.NeedDllNames != null) { NeedDllNames.AddRange(setting.NeedDllNames); } if (File.Exists(SettingName + "-needDlls.txt")) { NeedDllNames.AddRange(File.ReadAllText(SettingName + "-needDlls.txt").Split(',').ToList()); } DeleteDllNames = new List <string>(); if (setting.DeleteDllNames != null) { DeleteDllNames.AddRange(setting.DeleteDllNames); } if (File.Exists(SettingName + "-deleteDlls.txt")) { DeleteDllNames.AddRange(File.ReadAllText(SettingName + "-deleteDlls.txt").Split(',').ToList()); } DllFileNames = new List <string>(); RecoveryDlls(); //还原Dll var files = Directory.GetFiles(ProjectFolder, "*.dll", SearchOption.TopDirectoryOnly); foreach (var file in files) { var fileName = Path.GetFileNameWithoutExtension(file); if (setting.NeedDllNamePrefix != null) { foreach (var prefix in setting.NeedDllNamePrefix) { if (fileName.StartsWith(prefix)) { NeedDllNames.Add(fileName); } } } if (setting.DeleteDllNamePrefix != null) { foreach (var prefix in setting.DeleteDllNamePrefix) { if (fileName.StartsWith(prefix)) { DeleteDllNames.Add(fileName); } } } DllFileNames.Add(fileName); } var text = File.ReadAllText(DepsJsonBakPath); var json = JsonConvert.DeserializeObject <DepsJson>(text); var dllfiles = json.GetDllFiles(); dllfiles.AddRange(json.GetNativeFiles()); dllfiles.AddRange(json.GetCompileFiles()); dllfiles.AddRange(json.GetDependencies()); dllfiles = dllfiles.Distinct().OrderBy(q => q).ToList(); DllFileNames.AddRange(dllfiles); DllFileNames.RemoveAll(q => DeleteDllNames.Contains(q)); DllFileNames.RemoveAll(q => NeedDllNames.Contains(q)); DeleteDllNames.RemoveAll(q => NeedDllNames.Contains(q)); DllFileNames = DllFileNames.Distinct().ToList(); DeleteDllNames = DeleteDllNames.Distinct().ToList(); NeedDllNames = NeedDllNames.Distinct().ToList(); #endregion }
static void Main(string[] args) { var settingFileName = "setting"; if (args.Length > 0) { settingFileName = args[0]; } if (File.Exists(settingFileName + ".txt") == false) { var set = new DepsLessSetting() { _comment = "ProjectFolder:项目文件夹;ExeFileName:执行文件;NeedDllNamePrefix:必要文件前缀;NeedDllNames:必要文件;DeleteDllNamePrefix:必删文件前缀;DeleteDllNames:必删文件;CheckUrls:核对Url", ProjectFolder = "F:\\", ExeFileName = "ToolGood.Test.exe", NeedDllNamePrefix = new List <string>() { "ToolGood." }, NeedDllNames = new List <string>() { "System.Security.Principal.Windows", "System.Text.RegularExpressions" }, DeleteDllNamePrefix = new List <string>() { "api-ms-win" }, DeleteDllNames = new List <string>(), CheckUrls = new List <DepsLessSetting.CheckUrl>() { new DepsLessSetting.CheckUrl() { Url = "http://*****:*****@"F:\somain\ToolGood.Oviki\ToolGood.Oviki\bin\Release\netcoreapp3.0\publish-2"; //string s = @"""C:\Program Files\dotnet\sdk\3.0.100\Sdks\ILLink.Tasks\tools\netcoreapp2.0\illink.dll"" "; //s += $"-a \"{Path.Combine(setting.ProjectFolder, setting.ExeFileName + ".exe")}\""; //var files = Directory.GetFiles(setting.ProjectFolder, "*.dll"); //foreach (var file in files) { // s += $"-a \"{file}\" "; //} //s += $"-out \"{Path.Combine(setting.ProjectFolder, "out")}\" "; //s += "-c copyused -u copyused -l none --skip-unresolved true "; //ProcessStartInfo processStartInfo = new ProcessStartInfo(); //processStartInfo.FileName = @"C:\Program Files\dotnet\dotnet.exe"; //processStartInfo.Arguments = s; ////processStartInfo.UseShellExecute = true; //processStartInfo.CreateNoWindow = false; //processStartInfo.RedirectStandardOutput = true; //processStartInfo.RedirectStandardError = true; //var process = new Process(); //process.StartInfo = processStartInfo; //process.OutputDataReceived += Process_OutputDataReceived; //process.ErrorDataReceived += Process_ErrorDataReceived; //process.Exited += Process_Exited; //process.Start(); //Console.ReadLine(); // -out "obj\Release\netcoreapp3.0\win-x64\linked" //-c copyused -u copyused -l none--skip -unresolved true }