我可以将自定义版本字符串添加到.net DLL吗? [英] Can I add custom version strings to a .net DLL?

查看:73
本文介绍了我可以将自定义版本字符串添加到.net DLL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过手动编辑.rc文件将自定义版本字符串添加到Visual Studio中的C ++ DLL。例如,如果我在.rc文件的VersionInfo部分中添加

I can add custom version strings to a C++ DLL in Visual Studio by editing the .rc file by hand. For example, if I add to the VersionInfo section of the .rc file

VALUE "BuildDate", "2008/09/19 15:42:52"

然后该日期在文件资源管理器,DLL属性中可见,在版本选项卡下。

Then that date is visible in the file explorer, in the DLL's properties, under the Version tab.

我可以对C#DLL这样做吗?

Can I do the same for a C# DLL? Not just for build date, but for other version information (such as source control information)

UPDATE:我认为可能有一种方法可以通过嵌入Windows资源来完成,不仅用于构建日期,还用于其他版本信息(例如源代码控制信息)。 ,所以我询问如何做

UPDATE: I think there may be a way to do this by embedding a windows resource, so I've asked how to do that.

推荐答案

扩展Khoth的答案,在AssemblyInfo.cs中:

Expanding on the Khoth's answer, In AssemblyInfo.cs:

您可以这样做:

[assembly: CustomResource("Build Date", "12/12/2012")]

其中CustomResource定义为:

Where CustomResource is defined as:

[AttributeUsage(AttributeTargets.Assembly)]
public class CustomResourceAttribute : Attribute
{        
    private string the_variable;
    public string Variable  {get { return the_variable; }}

    private string the_value;
    public string Value     {get { return the_value; }}

    public CustomResourceAttribute(string variable, string value)
    {
        this.the_variable = variable;
        this.the_value = value;
    }
}

此解决方案很好,因为它为您提供了灵活性需要,它不会引起任何编译器警告。

This solution is nice because it gives you the flexibility you need and it does not cause any compiler warnings.

不幸的是,无法使用DateTime,因为在属性中输入的值必须是常量,而DateTime不是常量。

Unfortunately it is not possible to use a DateTime because the values entered in Attributes must be constants, and a DateTime is not a constant.

这篇关于我可以将自定义版本字符串添加到.net DLL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆