在.NET Core项目中,可以使用反射来获取动态链接库(DLL)的版权和构建日期信息。以下是一种跨多个.NET Core项目获取相同版权和构建日期信息的方法:
using System;
[assembly: AssemblyCompany("Your Company")]
[assembly: AssemblyProduct("Your Product")]
[assembly: AssemblyCopyright("Copyright © Your Year")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyBuildDate("2022-01-01")] // 自定义属性,用于存储构建日期信息
namespace CommonInfo
{
[AttributeUsage(AttributeTargets.Assembly)]
public class AssemblyBuildDateAttribute : Attribute
{
public string BuildDate { get; }
public AssemblyBuildDateAttribute(string buildDate)
{
BuildDate = buildDate;
}
}
}
using System;
using System.Reflection;
using CommonInfo;
public class Program
{
public static void Main()
{
Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集
AssemblyBuildDateAttribute buildDateAttribute = assembly.GetCustomAttribute<AssemblyBuildDateAttribute>();
if (buildDateAttribute != null)
{
string buildDate = buildDateAttribute.BuildDate;
Console.WriteLine("Build Date: " + buildDate);
}
else
{
Console.WriteLine("Build Date information not found.");
}
}
}
这样,无论在哪个.NET Core项目中使用上述代码,都可以获取到相同的版权和构建日期信息。
推荐的腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云