Có thể có một cách rất đơn giản để làm điều này, nhưng tôi không biết nó là gì. Khi tôi đầu tiên bắt đầu sử dụng NSIS, tôi đã phát triển giải pháp này cho phù hợp với nhu cầu của mình và chưa xem xét lại vấn đề kể từ khi xem có điều gì thanh lịch hơn hay không. Vì vậy, tôi đã viết một ứng dụng C# ngắn gọi là GetAssemblyInfoForNSIS để lấy thông tin tệp đó từ tệp thực thi và ghi nó vào tệp .nsh mà trình cài đặt của tôi bao gồm.
Dưới đây là C# ứng dụng:
using System;
using System.Collections.Generic;
using System.Text;
namespace GetAssemblyInfoForNSIS {
class Program {
/// <summary>
/// This program is used at compile-time by the NSIS Install Scripts.
/// It copies the file properties of an assembly and writes that info a
/// header file that the scripts use to make the installer match the program
/// </summary>
static void Main(string[] args) {
try {
String inputFile = args[0];
String outputFile = args[1];
System.Diagnostics.FileVersionInfo fileInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(inputFile);
using (System.IO.TextWriter writer = new System.IO.StreamWriter(outputFile, false, Encoding.Default)) {
writer.WriteLine("!define VERSION \"" + fileInfo.ProductVersion + "\"");
writer.WriteLine("!define DESCRIPTION \"" + fileInfo.FileDescription + "\"");
writer.WriteLine("!define COPYRIGHT \"" + fileInfo.LegalCopyright + "\"");
writer.Close();
}
} catch (Exception e) {
Console.WriteLine(e.Message + "\n\n");
Console.WriteLine("Usage: GetAssemblyInfoForNSIS.exe MyApp.exe MyAppVersionInfo.nsh\n");
}
}
}
}
Vì vậy, nếu bạn sử dụng ứng dụng như vậy:
GetAssemblyInfoForNSIS.exe MyApp.exe MyAppVersionInfo.nsh
Bạn sẽ nhận được một tệp có tên MyAppVersionInfo.nsh trông giống như thế này (giả sử thông tin này nằm trong tệp thi hành của bạn):
!define VERSION "2.0"
!define DESCRIPTION "My awesome application"
!define COPYRIGHT "Copyright © Me 2010"
Ở phía trên cùng của kịch bản NSIS của tôi, tôi làm điều gì đó như thế này:
!define GetAssemblyInfoForNSIS "C:\MyPath\GetAssemblyInfoForNSIS.exe"
!define PrimaryAssembly "C:\MyPath\MyApp.exe"
!define VersionHeader "C:\MyPath\MyAppVersionInfo.nsh"
!system '"${GetAssemblyInfoForNSIS}" "${PrimaryAssembly}" "${VersionHeader}"'
!include /NONFATAL "${VersionHeader}"
!ifdef VERSION
Name "My App ${VERSION}"
!else
Name "My App"
!endif
!ifdef DESCRIPTION
VIAddVersionKey FileDescription "${DESCRIPTION}"
!endif
!ifdef COPYRIGHT
VIAddVersionKey LegalCopyright "${COPYRIGHT}"
!endif
Đầu tiên 3 định nghĩa thiết lập tên tập tin để sử dụng trong các cuộc gọi đến !system GetAssemblyInfoForNSIS.exe. Cuộc gọi hệ thống này diễn ra trong quá trình biên dịch của trình cài đặt và tạo tệp .nsh ngay trước khi bạn đưa nó vào. Tôi sử dụng công tắc/NONFATAL để trình cài đặt của tôi không hoàn toàn thất bại nếu xảy ra lỗi khi tạo tệp bao gồm.
Nguồn
2010-06-14 19:37:23
Bây giờ đó là những gì tôi gọi một giải pháp! Cảm ơn:) – codeulike
Những người như bạn là lý do SO hoạt động :) Cảm ơn – darkpbj