AssemblyTitle设置后永远不会更改,我希望根据配置进行更改 [英] The AssemblyTitle never changes once set, I want it to be changed per configuration
问题描述
我想根据产品名称更改以下屏幕快照中显示的文本。我知道,文本取自Assembly.Title属性,这是一个只读属性,因此无法在运行时更改。那么如何在编译时更改它呢?
我们将应用程序出售给多个客户,每个客户的应用程序名称应更改。我们为每个客户提供配置。因此,在构建时,应根据配置选择程序集标题。
I would like to change the text shown in the screenshot below based on the Product name. I know, the text is taken from Assembly.Title property which is a read only property and so can not be changed at runtime. So how do I change it at compile time? We sell the application to multiple customers and the name of the application should change per customer. We have a configurations for each customer. So at build time, Assembly title should be selected as per the configuration.
任何建议如何解决这个问题?
Any suggestion how to solve this?
更新:
我尝试了评论中给出的一些建议,发现以下内容:
I tried some of the suggestions given in the comments and I found following:
使用项目属性中的程序集信息弹出窗口设置文本或直接在AssemblyInfo.cs文件中对其进行更改后,该文本将正确显示在任务栏中。
After I set the text using the assembly info popup from project properties or by changing it directly in the AssemblyInfo.cs file, it is shown correctly in the taskbar.
如果我再次更改它,更改后的文本不会显示在任务栏中。
If I change it again, changed text is not shown in the taskbar ie. it shows all the time the text which was set at FIRST time.
我一直尝试删除文件,甚至重新启动系统,但始终没有显示设置为首次时间的文本。
I tried deleting files, even restarting the system, but it didn't help.
然后我重命名了文件(即exe文件),然后它正确显示了更改的文本。
Then I renamed the file (i.e. exe file) and then it showed correctly the changed text.
如果我将其重命名为原始名称,它将显示第一个设置的文本。
If I rename it back to original name, it shows the first set text.
可能是什么原因?
推荐答案
在AssemblyInfo.cs中(在VisualStudio项目的属性下),您将在以下属性中找到指定的程序集标题:
In AssemblyInfo.cs (under Properties in a VisualStudio project), you'll find the assembly title specified in an attribute like this:
[assembly: AssemblyTitle("MyAssembly")]
您应该能够使用编译器常量将其包装:
You should be able to wrap this with compiler constants:
#if SOME_MODE
[assembly: AssemblyTitle("SomeName")]
#else
[assembly: AssemblyTitle("ADifferentName")]
#endif
这篇关于AssemblyTitle设置后永远不会更改,我希望根据配置进行更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!