Programmatically change the AssemblyVersion and AssemblyFileVersion attributes(以编程方式更改 AssemblyVersion 和 AssemblyFileVersion 属性)
问题描述
在设置创建过程中,我计划执行以下操作(在 C# 脚本中):
During a setup creation process, I am planning to do the following (within a C# Script):
- 读取一个DLL的
AssemblyVersion和AssemblyFileVersion属性值. - 迭代项目中的所有 DLL 和可执行文件,并将这些版本应用到它们的
AssemblyVersion和AssemblyFileVersion属性值.
- Read the
AssemblyVersionandAssemblyFileVersionattribute values of one DLL. - Iterate all DLLs and executables in the project and apply those version to their
AssemblyVersionandAssemblyFileVersionattribute values.
现在的问题是:第二步怎么做?
我可以成功完成第 1 步,但对于第 2 步,我看不到真正的起点.我可能要做的是使用一些原生的P/Invoke方法,因为属性直接修改了DLL/可执行文件的版本信息资源信息.
I successfully can do step 1, but for step 2 I don't see a real start point. What I probably have to do is to use some native P/Invoke methods since the attributes directly modify the version information resource information of a DLL/executable.
对此有任何提示吗?
推荐答案
你为什么不在构建过程中读取一个DLL的AssemblyVersion和AssemblyFileVersion,并将其保存回其他csproject的AssemblyInfo.cs,然后才编译?
Why don't you, during build process, read the AssemblyVersion and AssemblyFileVersion of one DLL, and save it back to other csproject's AssemblyInfo.cs, only then compile it?
其实我不知道是否可以直接修改DLL文件,而不用花哨的东西.
As a matter of fact, I don't know whether it is possible to modify the DLL file directly, without resorting to something fanciful.
或者,确保所有 DLL 共享一个公共 AssemblyInfo.cs.当您在 csproject 中添加新项目时,您可以通过将 AssemblyInfo.cs 添加为添加为链接"来执行此操作.这样编译时,所有的 DLL 将共享相同的 AssemblyInfo.cs,从而输出相同的 AssemblyVersion.
Or alternatively, make sure that all your DLLs share one common AssemblyInfo.cs. You can do this by adding the AssemblyInfo.cs as "Add As Link" when you add a new item in csproject. In this way when you do a compilation, all the DLLs will share the same AssemblyInfo.cs, and thus output the same AssemblyVersion.
这篇关于以编程方式更改 AssemblyVersion 和 AssemblyFileVersion 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式更改 AssemblyVersion 和 AssemblyFileVersion 属性
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 使用 rss + c# 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
