Log4NET 设置被 AssemblyInfo 任务覆盖
我有一个使用 log4net 的项目,并且在开发人员机器上运行良好。 当我们构建时,构建脚本中的一个步骤会调用AssemblyInfo任务来设置版本号和日期等。但是AssemblyInfo文件也会丢失行:
[程序集:XmlConfigurator(Watch = true)]
有没有办法让AssemblyInfo任务不会覆盖该行,或者相反,让 AssemblyInfo 任务将该行重新插入到文件中(以及相应的 using 语句?
I have a project that uses log4net and works fine on the developer machines. When we build, a step in our build scripts calls the AssemblyInfo task to set version numbers and dates, etc. But the AssemblyInfo file also loses the line:
[assembly: XmlConfigurator(Watch = true)]
Is there any way to have the AssemblyInfo task not overwrite that line, or conversely, to have the AssemblyInfo task re-insert that line into the file (along with the appropriate using statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,您可以将 log4net [ assembly: ...] 行放在将编译到程序集中的任何文件中。 很多时候,我们只是将它放在具有“main”方法的.cs文件中,它就可以正常工作。
You can actually put the log4net [assembly: ...] line in any file that will be compiled into the assembly. A lot of times, we just put it in the .cs file that has the "main" method, and it works just fine.
好吧,换个角度思考,您不必只有一个程序集信息文件。
这就是我们在解决方案中的做法,每个项目都有 3 个程序集信息文件:
AssemblyInfo.cs - 包含 Guid、AssemblyTitle、AssemblyDescription 和任何程序集特定属性。
ProductAssemblyInfo.cs - 包含 AssemblyProduct、AssemblyVersion 和 AssemblyFileVersion。 这样,产品/解决方案中的所有程序集共享相同的版本。
CompanyAssemblyInfo.cs - 包含 AssemblyCompany、AssemblyCopyright 以及我们希望所有程序集共享的任何属性。
第 2 项和第 3 项是使用“添加为链接”引用的,这样它们就可以从单个源代码共享。 现在,您可能不想采用相同的方法,但您当然可以使用类似的结构,并将 XmlConfigurator 放置在与程序集版本详细信息分开的程序集信息文件中。
Well, thinking a little differently, you don't have to have only one assembly info file.
This is how we do it for a solution, each project has 3 assembly info files:
AssemblyInfo.cs - Contains Guid, AssemblyTitle, AssemblyDescription, and any assembly specific attributes.
ProductAssemblyInfo.cs - Contains AssemblyProduct, AssemblyVersion and AssemblyFileVersion. This way all assemblies in a product/solution share the same version.
CompanyAssemblyInfo.cs - Contains AssemblyCompany, AssemblyCopyright, and any attributes we want all our assemblies to share.
Items 2 and 3 are referenced using "Add as link", this way they are shared from the single source code. Now, you may not want to adopt the same approach, but you could certainly use a similar structure and place your XmlConfigurator in a separate assembly info file from your assembly version details.