我可以将自定义版本字符串添加到.net DLL吗?

Sim*_*mon 5 .net c# version-control visual-studio

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

VALUE "BuildDate", "2008/09/19 15:42:52"
Run Code Online (Sandbox Code Playgroud)

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

我可以为C#DLL执行相同的操作吗?不仅适用于构建日期,还适用于其他版本信息(例如源控制信息)

更新:我认为可能有一种方法可以通过嵌入Windows资源来实现这一点,所以我已经问过如何做到这一点.

Kyl*_*ser 5

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

你可以做:

[assembly: CustomResource("Build Date", "12/12/2012")]
Run Code Online (Sandbox Code Playgroud)

CustomResource定义为:

[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;
    }
}
Run Code Online (Sandbox Code Playgroud)

这个解决方案很不错,因为它为您提供了所需的灵活性,并且不会导致任何编译器警告.

遗憾的是,无法使用DateTime,因为在Attributes中输入的值必须是常量,而DateTime不是常量.


Kho*_*oth 4

在AssemblyInfo.cs中,您可以输入:

[assembly: System.Reflection.AssemblyInformationalVersion("whatever you want")]
Run Code Online (Sandbox Code Playgroud)

如果它不是像 1.2.3.4 这样的数字,则会出现编译器警告,但我相当确定一切都会正常。