Displaying the build date

前端 未结 25 2361
感动是毒
感动是毒 2020-11-22 11:36

I currently have an app displaying the build number in its title window. That\'s well and good except it means nothing to most of the users, who want to know if they have t

25条回答
  •  一向
    一向 (楼主)
    2020-11-22 12:19

    For .NET Core projects, I adapted Postlagerkarte's answer to update the assembly Copyright field with the build date.

    Directly Edit csproj

    The following can be added directly to the first PropertyGroup in the csproj:

    Copyright © $([System.DateTime]::UtcNow.Year) Travis Troyer ($([System.DateTime]::UtcNow.ToString("s")))
    

    Alternative: Visual Studio Project Properties

    Or paste the inner expression directly into the Copyright field in the Package section of the project properties in Visual Studio:

    Copyright © $([System.DateTime]::UtcNow.Year) Travis Troyer ($([System.DateTime]::UtcNow.ToString("s")))
    

    This can be a little confusing, because Visual Studio will evaluate the expression and display the current value in the window, but it will also update the project file appropriately behind the scenes.

    Solution-wide via Directory.Build.props

    You can plop the element above into a Directory.Build.props file in your solution root, and have it automatically applied to all projects within the directory, assuming each project does not supply its own Copyright value.

    
     
       Copyright © $([System.DateTime]::UtcNow.Year) Travis Troyer ($([System.DateTime]::UtcNow.ToString("s")))
     
    
    

    Directory.Build.props: Customize your build

    Output

    The example expression will give you a copyright like this:

    Copyright © 2018 Travis Troyer (2018-05-30T14:46:23)
    

    Retrieval

    You can view the copyright information from the file properties in Windows, or grab it at runtime:

    var version = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
    
    Console.WriteLine(version.LegalCopyright);
    

提交回复
热议问题