【问题标题】:How to know build date for C# Class libraries如何知道 C# 类库的构建日期
【发布时间】:2013-08-17 09:45:47
【问题描述】:

我正在做 C# Winform 应用程序。我有几个类库。每个图书馆也是项目。通常,我使用下面的代码来了解我的应用程序的构建日期。但是,我想知道每个类库的构建日期。任何帮助...

 DateTime buildDate = new 
        FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;
 MessageBox.Show(string.Format("Build Date : {0}", buildDate), "Version Info");

【问题讨论】:

  • 在提出重复问题之前,请考虑自己寻找答案。 stackoverflow.com/questions/2050396/…
  • 您是否有疑问:“如何获取所有程序集的列表?”或者也许“如何在定义给定类的地方获取程序集”? - 很不清楚...
  • 或者您正在尝试重新发明“版本”程序集属性?
  • @Drasive,谢谢我已经阅读了posted文章。我没有得到我真正想要的信息。
  • @AlexeiLevenkov,谢谢。我认为““如何获取所有程序集的列表?”是正确的问题。如果我知道所有列表,那么是否有可能知道每个构建日期?对吗?

标签: c# winforms class build


【解决方案1】:

更新 这个呢?

System.IO.FileInfo fileInfo = new System.IO.FileInfo(Assembly.GetExecutingAssembly().Location);
DateTime lastModified = fileInfo.LastWriteTime;

或者您可以尝试此处答案中解释的方法: ASP.NET - show application build date/info at the bottom of the screen

【讨论】:

  • file.CreationTime 是个坏主意。只需复制文件并查看自己。
【解决方案2】:

获取进程使用中的所有程序集的列表 (AppDomain.CurrentDomain)[http://msdn.microsoft.com/en-us/library/system.appdomain.currentdomain.aspx] 然后AppDomain.GetAssemblies

使用该列表使用您的代码(new FileInfo(assembly.Location).LastWriteTime; 或更好地使用该文章中的示例通过AssemblyName.Version 获得Version

  Console.WriteLine("The version of the currently executing assembly is: {0}",
        Assembly.GetExecutingAssembly().GetName().Version);

  Console.WriteLine("The version of mscorlib.dll is: {0}",
        typeof(String).Assembly.GetName().Version);

【讨论】:

    猜你喜欢
    • 2015-10-15
    • 2013-06-27
    • 2013-02-16
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多