我可以将自定义版本字符串添加到.net DLL吗?
时间:2020-03-06 14:35:53 来源:igfitidea点击:
我可以通过手动编辑.rc文件将自定义版本字符串添加到Visual Studio中的C ++ DLL。例如,如果我将添加到.rc文件的VersionInfo部分
VALUE "BuildDate", "2008/09/19 15:42:52"
然后,该日期在DLL属性的"版本"选项卡下的文件浏览器中可见。
我可以对CDLL做同样的事情吗?不仅用于构建日期,还用于其他版本信息(例如源代码控制信息)
更新:我认为可以通过嵌入Windows资源来实现此目的,所以我问过如何做到这一点。
解决方案
在AssemblyInfo.cs中,我们可以输入:
[assembly: System.Reflection.AssemblyInformationalVersion("whatever you want")]
如果不是1.2.3.4之类的数字,这是一个编译器警告,但是我很确定一切都会正常。
在AssemblyInfo.cs中扩展Khoth的答案:
你可以做:
[assembly: CustomResource("Build Date", "12/12/2012")]
其中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; } }
这个解决方案很好,因为它为我们提供了所需的灵活性,并且不会引起任何编译器警告。
不幸的是,无法使用DateTime,因为在Attributes中输入的值必须是常量,而DateTime不是常量。