首页 > 解决方案 > Add Version number to a generic file in Windows

问题描述

Last Edit: A Version number cannot be added to a generic file in Windows.

Versioning in Windows comes from a VERSIONINFO resource attached to a binary executable file such as .EXE or .DLL. This resource cannot be attached to any arbitrary file and it is not part of any Alternate Data Stream.

I had thought that the version info was stored in an Alternate Data Stream, but it is not.

Is there a way to add a program version number to the meta-data for a file in Windows that is not an executable or dll? We have a linux app. that will be stored on a Windows server and copied to Linux computers when the version changes.

Edit: I would like to Add versioning info to the file, which is kept in an Alternate File stream for the file.

I would like to write a version number to the meta data so that it could be read from a program using a method similar to this:

string fullPath = "folder_name" + "\\" + "linux_app_name";
if (File.Exists(fullPath))
{
    FileAttributes fileAttributes = File.GetAttributes(fullPath);
    FileVersionInfo verInfo = FileVersionInfo.GetVersionInfo(fullPath);
    // todo: add version info to the file.
    textBox1.AppendText("File name:\t" + Path.GetFileName(verInfo.FileName) + '\n');
    textBox1.AppendText("Version Info:\t");         
    if (verInfo.FileVersion != null)
    {
        textBox1.AppendText(verInfo.FileVersion);
    }
    else
    {
        textBox1.AppendText("No Version info.");
    }
}

Thanks in advance for any replies.

标签: c#windowsfileversion

解决方案


如果其他人正在寻找一种方法来将版本控制添加到 Windows 中不是 Windows 程序文件的任意文件中,我将发布此答案。

你不能。

Windows 中的版本控制来自附加到二进制可执行文件(如 .EXE 或 .DLL)的 VERSIONINFO 资源。此资源不能附加到任何任意文件,并且它不是任何备用数据流的一部分。


推荐阅读