如何获得参赛申请的版权属性

How do I get the copyright property of the entry application

我的问题是这样的:我正在用C#写一个dll,但是它是Com可见的,所以它可以被.NET应用程序引用或者被非.NET应用程序用作COM组件(Forms, VB6等等等等)。
我想获得调用可执行文件的属性 - 即。产品名称、版权等(如果您右键单击 .EXE,select 属性并转到“详细信息”选项卡,您可以看到所有内容)。
通过简单地使用 System.Windows.Forms.Application 的属性,我可以获得其中的很多信息 - ProductName 和 Product Version 都在那里。但是,没有文件版本或版权 属性。奇怪的是,其中一些已实施而另一些未实施。当然必须有一种方法(无论多么曲折)获得调用应用程序的版权 属性。我到处用谷歌搜索并在 PInvoke 网站上搜索,但都无济于事。欢迎提出任何建议。

如果我理解正确你的问题,你可以这样暴露AssemblyCopyright

public string AssemblyCopyright
{
    get
    {
        object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
        if (attributes.Length == 0)
        {
            return "";
        }
        return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
    }
}

对于其他属性,您也可以这样做。

您可以使用 Add New ItemAboutBox 添加到项目中,然后查看如何提取其他属性。

找到了!结果很容易:

FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.GetFileName(System.Windows.Forms.Application.ExecutablePath));

FileVersionInfo 然后具有文件版本资源中所有内容的属性,包括版权的 LegalCopyright。适用于任何类型的应用程序。