使用 C# 更改可执行属性(产品名称)
我有一个 C# 项目,需要在编译时更改其产品名称。我使用预构建事件在 AssemblyInfo.cs 中更改它,但有几次 Visual Studio 没有获得此更改并使用以前的产品名称进行编译。所以我更喜欢在从另一个可执行文件(全部用 C# 编写)编译后更改它。
I have a C# project that I need to change its product name upon compiling. I used the prebuild event to change it in the AssemblyInfo.cs but a few times Visual Studio doesn't get this change and compiles it with the previous product name. So i prefer to change it after compiling from another executable (all in C#).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦程序集被编译,您就不能(或至少不应该)更改该信息。它被编译到程序集中的资源文件中,该资源文件的设计目的是不可更改的。
Visual Studio 应始终提取该信息,因为它是代码的一部分。如果不是,这可能是一个更大问题的征兆,因为 Visual Studio 没有编译您期望编译的代码,并且可能还包含其他代码文件的恶意版本。尝试执行完整的重建解决方案,并确保产品名称正确;如果没有,请将代码移至另一台计算机并在那里进行编译,以确保它不会出于某种原因从计算机上的其他位置提取文件。
Once the assembly is compiled, you can't (or at least shouldn't) change that information. It's compiled into a resource file inside the assembly that's not designed to be changed.
Visual Studio should always pull that information in, because it's part of the code. If it's not, that may be a sign of a bigger problem, because Visual Studio is not compiling the code you expect to be compiled, and there may be rogue versions of other code files being included as well. Try doing a complete Rebuild Solution, and make sure that the product name is then correct; if not, move the code to a different machine and compile it there, just to make sure it's not pulling in files from somewhere else on your machine for some reason.