【问题标题】:How to set file version comment如何设置文件版本注释
【发布时间】:2026-01-31 21:15:01
【问题描述】:

在哪里可以设置文件版本 cmets..?

我们可以通过

FileVersionInfo fv = 
System.Diagnostics.FileVersionInfo.GetVersionInfo(
                   Assembly.GetExecutingAssembly().Location);
var comment = fv.Comments;

那么我该如何设置它以便我可以在某处显示相同的内容..

【问题讨论】:

  • 你想在哪里/如何展示他们?
  • @KonstantinVasilcov 在应用程序的关于窗口中
  • 是什么阻止你做MessageBox.Show(comment,"About");
  • 你是想在创建程序集时设置它的编译时间还是需要操作现有程序集?

标签: c# .net


【解决方案1】:

对于 .NET 程序集,您可以使用 AssemblyDescriptionAttribute 设置文件版本注释,您通常在使用 Visual Studio 时将其放入项目的 AssemblyInfo.cs 文件中。

[assembly: AssemblyDescription("The assembly does xxx by yyy")]

对于其他类型的可执行文件,文件版本是使用文件中的资源设置的。

不同的程序集级别文件版本属性映射如下:

  • FileVersionInfo.Comments = AssemblyDescription
  • FileVersionInfo.CompanyName = AssemblyCompany
  • FileVersionInfo.FileDescription = AssemblyTitle
  • FileVersionInfo.FileVersion = AssemblyFileVersion
  • FileVersionInfo.LegalCopyright = AssemblyCopyright
  • FileVersionInfo.LegalTrademarks = AssemblyTrademark
  • FileVersionInfo.ProductName = AssemblyProduct
  • FileVersionInfo.ProductVersion = AssemblyInformationalVersion

【讨论】:

  • 不客气。随意接受您认为最有帮助的答案,将其标记为“已接受”。
【解决方案2】:

要设置此值,您可以编辑项目的AssemblyInfo.cs 文件。

这行就是你要找的:

[assembly: AssemblyDescription("This is the comment")]

【讨论】:

    【解决方案3】:

    如今在 .Net 6 中

    你可以在*.csproj中设置cmets

    <Description>My Comment</Description>
    

    得到

    public static string GetComments()
    {
        var fileName = Assembly.GetEntryAssembly()?.Location;
        if (fileName == null) return String.Empty;
        var versionInfo = FileVersionInfo.GetVersionInfo(fileName);
        return versionInfo?.Comments ?? String.Empty; 
    }
    

    【讨论】: