如何在Unity中设置生成的EXE文件信息:构建过程配置与构建后修改产品名称、版本、版权等细节
Hey there! Let's break down how to handle setting up those EXE file details—like Product Name, Version, Copyright, and more—both automatically during your Unity build process and adjusting them after building if you need to. This will keep your builds consistent and looking professional.
1. Basic Setup in Unity Editor (Foundation for Automation)
First, let's cover the manual setup, which is what automated builds will leverage:
- Open your Unity project and navigate to
Edit > Project Settings > Player - Make sure the Windows tab is selected at the top of the Player Settings window (since we're targeting EXE)
- Fill in these fields to map directly to your EXE's file properties:
- Product Name: Sets the EXE's "Product name" field
- Version: Populates "Product version"
- Copyright: Fills in the "Copyright" section
- Company Name: Shows up as the EXE's "Company name"
- Any changes here will be reflected in your next build—perfect for one-off builds, but we can automate this for consistency.
2. Automate EXE Info During Build
To automatically set these details every time you run a build, create an Editor script (place this in an Assets/Editor folder—this folder won't be included in your final build):
using UnityEditor; using UnityEngine; public class BuildExeWithCustomMetadata { // Adds a menu option in Unity's top bar for easy access [MenuItem("Build Tools/Build Windows EXE with Custom Info")] public static void BuildWindowsStandalone() { // Step 1: Set your desired EXE metadata PlayerSettings.productName = "My Epic Game"; PlayerSettings.bundleVersion = "1.0.1"; PlayerSettings.copyright = "© 2024 My Game Studio. All Rights Reserved."; PlayerSettings.companyName = "My Game Studio"; // Step 2: Configure build settings string buildOutputPath = "Builds/MyEpicGame.exe"; BuildPlayerOptions buildConfig = new BuildPlayerOptions { scenes = EditorBuildSettings.scenes, // Uses your configured build scenes locationPathName = buildOutputPath, target = BuildTarget.StandaloneWindows64, options = BuildOptions.None }; // Step 3: Run the build BuildReport buildReport = BuildPipeline.BuildPlayer(buildConfig); BuildSummary buildSummary = buildReport.summary; if (buildSummary.result == BuildResult.Succeeded) { Debug.Log($"Build completed successfully! EXE at {buildOutputPath} has custom metadata."); } else { Debug.LogError($"Build failed with {buildSummary.totalErrors} errors."); } } }
Once this script is in place, you'll see a new Build Tools menu in Unity—clicking the option will set your metadata and run the build in one go. No more manual tweaks before each build!
3. Modify EXE Info Post-Build
If you already have a built EXE and need to adjust its metadata without rebuilding, you have a couple options:
- Third-Party Resource Editors: Tools like Resource Hacker let you open the EXE, edit its resource fields (like version info), and save changes directly.
- Command-Line/Code Approach: Use the
mt.exetool (included with Visual Studio/Windows SDK) to extract, modify, and re-inject the EXE's resources. Here's a quick example of a C# console app to do this:
using System; using System.Diagnostics; using System.IO; class ExeMetadataEditor { static void Main(string[] args) { string exePath = @"C:\Path\To\Your\BuiltGame.exe"; string tempResourceFile = "temp_version.res"; // Extract existing resources from the EXE Process extractProcess = Process.Start(new ProcessStartInfo { FileName = "mt.exe", Arguments = $"-inputresource:\"{exePath}\" -out:{tempResourceFile}", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true }); extractProcess.WaitForExit(); // Note: You'll need to edit the temp_res file's version info here (use a resource editor or library like ResourceLib) // For simplicity, you could pre-create a modified .res file and skip extraction if you know the exact values // Re-inject the modified resource back into the EXE Process injectProcess = Process.Start(new ProcessStartInfo { FileName = "mt.exe", Arguments = $"-outputresource:\"{exePath}\" -input:{tempResourceFile}", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true }); injectProcess.WaitForExit(); // Clean up temp file File.Delete(tempResourceFile); Console.WriteLine("EXE metadata updated successfully!"); } }
内容的提问来源于stack exchange,提问作者KRISHNANANDH N




