在装配信息中动态显示当前年份 [英] Dynamically display current year in assembly info

查看:17
本文介绍了在装配信息中动态显示当前年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 AssemblyInfo 文件中设置当前年份?

How to set current year in AssemblyInfo file?

我用过

取而代之的是:

<Assembly: AssemblyCopyright("Copyright 2012, Company Name.")> 

试过这个:

<Assembly: AssemblyCopyright("Copyright" + DateTime.Now.Year.ToString() + ", Company Name.")> 

我收到无效的常量错误.

I get invalid constant error.

我不想使用注册表项,这样做的最佳方法是什么?(这样当用户右键单击 EXE 并查找程序集信息时可以看到当前年份).

I don't want to use registry key entries, what is the optimum way of doing this? (so that when a user right clicks on EXE & looks for assembly information can see current year).

谢谢.

推荐答案

我在另一个帖子 (https://stackoverflow.com/a/827209/857307) 在这里真的很有帮助.

I saw something on another post (https://stackoverflow.com/a/827209/857307) that could really be helpful here.

试试这个.

将一个新文件添加到您的源存储库中的某个位置,该文​​件对您的解决方案中的所有项目都通用.将文件称为 AssemblyCopyright.tt

Add a new file to your source repository somewhere common to all of the projects in your solution. Call the file something like AssemblyCopyright.tt

在文件中,为c#添加如下代码

In the file, add the following code for c#

<#@ template language="C#" #>
using System;
using System.Reflection;

[assembly: AssemblyCopyright("Copyright © CompanyName <#=DateTime.Now.Year#>")]

或vb

<#@ template language="VB" #>
<#@ output extension=".vb" #>
Imports System
Imports System.Reflection

<Assembly: AssemblyCopyright("Copyright © CompanyName <#=DateTime.Now.Year#>")> 

然后,从每个 AssemblyInfo.cs 文件中删除 AssemblyCopyright 属性.

Then, remove the AssemblyCopyright attribute from each of your AssemblyInfo.cs files.

最后,为每个项目添加一个指向 AssemblyCopyright.tt 文件的链接.

Finally, add a link to the AssemblyCopyright.tt file to each of your projects.

模板文件将在具有正确年份的每个构建中重新创建一个新的 AssemblyCopyright.cs 文件.

The template file will recreate a new AssemblyCopyright.cs file on every build with the correct year.

这篇关于在装配信息中动态显示当前年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆