feat: 增强便携版支持与配置管理
- 更新 .gitignore 文件,添加便携版分发目录和 Fody 生成的配置文件。 - 修改 README.md,详细说明便携版的构建与分发流程,强调单文件分发的优势。 - 在 Config.cs 中实现便携配置管理,优先使用 exe 同目录的 config.json,提升用户体验。 - 更新 ExcelService.cs,优化默认模板的导出逻辑,支持现场替换模板文件。 - 在 MainForm.cs 中加载应用图标,提升界面一致性。 - 调整 Program.cs,确保在单文件分发时正确加载 native DLL。
This commit is contained in:
@@ -22,7 +22,8 @@ namespace TfsExcelImporter
|
||||
|
||||
/// <summary>
|
||||
/// Excel 读取与默认模板。模板内容(列宽、示例行、样式)只在
|
||||
/// templates\TFS导入模板.xlsx 里维护,随构建复制到 exe 目录后原样导出。
|
||||
/// templates\TFS导入模板.xlsx 里维护,构建时作为嵌入资源打进 exe;
|
||||
/// 若 exe 同目录存在同名文件则优先用它(现场可替换模板而不用重编译)。
|
||||
/// 列: Title | State | Assigned To | FinancialProject | Completed | LogDate | PBI Id | Description
|
||||
/// </summary>
|
||||
public static class ExcelService
|
||||
@@ -44,13 +45,33 @@ namespace TfsExcelImporter
|
||||
|
||||
// --------------------------------------------------------- 默认模板
|
||||
|
||||
/// <summary>把随程序发布的默认模板原样复制到目标路径。</summary>
|
||||
/// <summary>
|
||||
/// 把默认模板原样复制到目标路径。优先用 exe 同目录的同名文件(可由现场替换),
|
||||
/// 没有则从 exe 内嵌资源释放——单文件便携分发时无需附带模板。
|
||||
/// </summary>
|
||||
public static void CopyTemplate(string path)
|
||||
{
|
||||
var src = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TemplateFileName);
|
||||
if (!File.Exists(src))
|
||||
throw new FileNotFoundException("未找到默认模板文件: " + src, src);
|
||||
File.Copy(src, path, true);
|
||||
if (File.Exists(src))
|
||||
{
|
||||
File.Copy(src, path, true);
|
||||
return;
|
||||
}
|
||||
|
||||
var asm = typeof(ExcelService).Assembly;
|
||||
// 嵌入名取决于 Link 名:默认 <RootNamespace>.<文件名>
|
||||
var name = asm.GetManifestResourceNames()
|
||||
.FirstOrDefault(n => n.EndsWith(TemplateFileName, StringComparison.OrdinalIgnoreCase));
|
||||
if (name == null)
|
||||
throw new FileNotFoundException(
|
||||
"未找到默认模板:exe 内嵌资源与同目录 " + TemplateFileName + " 均缺失", src);
|
||||
|
||||
using (var input = asm.GetManifestResourceStream(name))
|
||||
{
|
||||
if (input == null) throw new FileNotFoundException("无法读取内嵌模板资源: " + name, src);
|
||||
using (var output = File.Create(path))
|
||||
input.CopyTo(output);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------- 读取数据
|
||||
|
||||
Reference in New Issue
Block a user