gpt4 book ai didi

C# 创建程序集并设置版本 - 在运行时

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:20 24 4
gpt4 key购买 nike

我正在做单元测试,我想测试这个:

public static string GetVersion(Assembly assembly)
{
return assembly.GetName().Version.ToString();
}

问题在标题中。

这可能吗?

最佳答案

我认为通过反射您可以更改属性的响应,但它不会自己写入程序集。

PropertyInfo nameProperty = typeof (Version).GetProperty ("Version");
FieldInfo versionField = nameProperty.GetBackingField ();
versionField.SetValue (assemby.GetName().Version, <Version you want>);

关于C# 创建程序集并设置版本 - 在运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8312181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com