我有一个简单的控制台应用程序,它具有自动增量构建版本。当我构建项目时,我想使用构建后事件将构建版本附加到输出 exe 文件名的末尾。构建版本没有宏。
问问题
111 次
1 回答
0
您将需要一个小实用程序来重命名目标:
using System;
using System.Diagnostics;
using System.IO;
namespace RenameWithVersion
{
public class Program
{
public static void Main(String[] args)
{
if (args.Length != 1)
throw new Exception("There should only be one command line parameter - the file to be renamed.");
var oldFilename = Path.GetFullPath(args[0]);
if (!File.Exists(oldFilename))
throw new Exception($"File '{oldFilename}' does not exist.");
var oldFilenameWithoutExt = Path.ChangeExtension(oldFilename, null);
var fileVersion = FileVersionInfo.GetVersionInfo(oldFilename).FileVersion;
var ext = Path.GetExtension(oldFilename);
var newFilename = $"{oldFilenameWithoutExt}{fileVersion}{ext}";
File.Delete(newFilename);
File.Move(oldFilename, newFilename);
}
}
}
编译它并将可执行文件放在路径上的某个位置。
在构建后事件中,像这样调用该实用程序:
RenameWithVersion "$(TargetPath)"
(请记住将 $(TargetPath) 放在双引号中,以防路径包含空格。)
于 2019-05-24T22:58:06.557 回答