Can I add custom version strings to a .net DLL?

前端 未结 2 1559
Happy的楠姐
Happy的楠姐 2021-01-06 02:01

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

<         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 02:27

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

    You can do:

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

    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.

    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.

提交回复
热议问题