添加环境检测和单exe打包功能
1. 添加.NET Framework 4.8环境检测 - 启动时检查注册表确认运行环境 - 缺失时显示明确错误信息和下载链接 2. 配置单exe打包方案 - 使用ILRepack合并依赖项 - 更改输出文件名为ExcelMerger_merged.exe - 添加必要的项目配置 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
f65c902d40
commit
cfcc1b578b
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace WinFormsApp1
|
||||
{
|
||||
@ -11,9 +12,49 @@ namespace WinFormsApp1
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// 检查.NET Framework 4.8是否已安装
|
||||
if (!CheckDotNetFramework48())
|
||||
{
|
||||
MessageBox.Show(
|
||||
"检测到您的系统未安装 .NET Framework 4.8\n\n" +
|
||||
"Excel合并工具需要此环境才能运行。\n\n" +
|
||||
"请前往以下链接下载并安装:\n" +
|
||||
"https://dotnet.microsoft.com/download/dotnet-framework/net48\n\n" +
|
||||
"安装完成后请重新运行本程序。",
|
||||
"缺少运行环境",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
|
||||
private static bool CheckDotNetFramework48()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
object release = key.GetValue("Release");
|
||||
if (release != null && int.TryParse(release.ToString(), out int releaseValue))
|
||||
{
|
||||
// .NET Framework 4.8 的 Release 值为 528040 或更高
|
||||
return releaseValue >= 528040;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 如果无法访问注册表,假设未安装
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,10 +4,34 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<AssemblyName>ExcelMerger</AssemblyName>
|
||||
<RootNamespace>ExcelMerger</RootNamespace>
|
||||
<ApplicationIcon>app.ico</ApplicationIcon>
|
||||
<Win32Resource />
|
||||
<!-- 用于单文件发布的配置 -->
|
||||
<PublishSingleFile>false</PublishSingleFile>
|
||||
<SelfContained>false</SelfContained>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<!-- 强制将所有依赖项合并到输出目录 -->
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EPPlus" Version="4.5.3.3" />
|
||||
<!-- 用于ILMerge合并依赖项 -->
|
||||
<PackageReference Include="ILRepack" Version="2.0.18" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- ILMerge后处理脚本 -->
|
||||
<Target Name="ILRepack" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<InputAssemblies Include="$(OutputPath)$(AssemblyName).exe" />
|
||||
<InputAssemblies Include="$(OutputPath)EPPlus.dll" />
|
||||
<InputAssemblies Include="$(OutputPath)System.Threading.Tasks.dll" />
|
||||
</ItemGroup>
|
||||
<Message Text="ILRepack merging..." Importance="high" />
|
||||
<Exec Command="$(PkgILRepack)\tools\ILRepack.exe /out:$(OutputPath)$(AssemblyName)_merged.exe @(InputAssemblies->'%(FullPath)', ' ')" />
|
||||
<Message Text="ILRepack merge complete: $(OutputPath)$(AssemblyName)_merged.exe" Importance="high" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
Loading…
x
Reference in New Issue
Block a user