使用 Visual Studio 2013 进行编译时向 C# DLL 添加日期和时间
本文关键字:DLL 添加 日期 时间 Studio Visual 2013 编译 使用 | 更新日期: 2023-09-27 18:30:29
在我的AssemblyInfo.cs对于C#类库,我有以下内容:
[assembly: AssemblyTitle("Production")]
因此,当我编译时,我得到一个dll项目.dll当我查看Windows文件属性时,它在"文件描述"字段中具有"生产"。
如何将日期和时间添加到此文件描述字段中?
按照要求,我的评论作为答案:
您可以使用 T4 模板执行此操作。
另请参阅 MSDN 文档。
你最好的解决方案是使用像TeamCity这样的东西来构建自动化,它允许你使用MSBuild并进行AssemblyInfo重写等,但如果你有兴趣,我确实有一个笨拙:
1)在AssemblyInfo中添加{Date}.cs任何您想要当前日期的位置。 在程序集标题属性的示例中
[assembly: AssemblyTitle("Production {Date}")]
2) 将其添加到预构建事件中
Powershell -Command "(Get-Content $(ProjectDir)Properties'AssemblyInfo.cs) -replace '{Date}',(Get-Date).ToString('MM/dd/yyyy')|sc $(ProjectDir)Properties'AssemblyInfo.cs -Encoding UTF8"
3) 将其添加到构建后事件中
Powershell -Command "(Get-Content $(ProjectDir)Properties'AssemblyInfo.cs) -replace (Get-Date).ToString('MM/dd/yyyy'),'{Date}'|sc $(ProjectDir)Properties'AssemblyInfo.cs -Encoding UTF8"
这仅在预构建中使用 Powershell 在 {Date} 上进行文本替换,并将其替换为当前日期。 如果需要,可以将其与自己的日期时间格式混合使用。 只需确保格式在预构建和后期构建中匹配即可。
可能有更聪明的方法可以做到这一点,比如MSBuild是如何做到的,但这是即兴的。