我可以将自定义版本字符串添加到.net DLL吗?
我可以通过手动编辑.rc文件将自定义版本字符串添加到Visual Studio中的C ++ DLL。 例如,如果我添加到.rc文件的VersionInfo部分
VALUE "BuildDate", "2008/09/19 15:42:52"
然后,该日期在文件资源管理器中,在DLL的属性中,在“版本”选项卡下可见。
我可以为C#DLL做同样的事情吗? 不仅适用于构建日期,还适用于其他版本信息(例如源控制信息)
更新:我认为可能有一种方法可以通过嵌入Windows资源来实现这一点,所以我已经问过如何做到这一点 。
扩展了Khoth的答案,在AssemblyInfo.cs中:
你可以做:
[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不是常量。
在AssemblyInfo.cs中,您可以放置:
[assembly: System.Reflection.AssemblyInformationalVersion("whatever you want")]
这是一个编译器警告,如果它不是像1.2.3.4这样的数字,但我相当确定一切都会工作。