根据条件编译符号更改 exe 的名称
您能否告诉 Visual Studio 根据是否设置了特定的条件编译符号来输出不同名称的 exe 文件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您能否告诉 Visual Studio 根据是否设置了特定的条件编译符号来输出不同名称的 exe 文件?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
这里的答案都不适合我。
它们要么产生错误,要么什么都不做。
这是我的解决方案,适用于 VS2005,我想它也适用于较新的 VS 版本。像这样编辑文件 *.csproj:
结果是 32 位编译生成文件
ProjectName_32.exe
,64 位编译生成ProjectName_64.exe
。请注意奇怪的语法。
if
条件周围不能有括号,并且x86
不能用引号括起来。此方法的缺点是您无法再在调试器中启动 Exe,因为 Visual Studio 找不到它生成的 Exe。这可以通过用“复制”命令替换“移动”命令来解决,但在这种情况下,您必须将 Exe 复制到另一个目录,因为您肯定不希望同一目录中出现两次相同的文件。
这一切都是一团糟。令人难以置信的是,您可以直接在项目设置中输入输出目录,但是要执行一些非常基本的操作(例如更改 Exe 名称),您必须编写这样一个笨拙的脚本,并且具有丑陋的副作用。微软真丢脸!
None of the answers here works for me.
They either produce errors or do nothing.
Here is my solution that works in VS2005 and I suppose it will also work in newer VS versions. Edit the file *.csproj like this:
The result will be that a 32 bit compilation produces a file
ProjectName_32.exe
and a 64 bit build producesProjectName_64.exe
.Please note the strange syntax. There must be no parenthesis around the
if
condition and thex86
must not be in quotes.The disadvantage of this method is that you cannot start your Exe in the debugger anymore because Visual Studio does not find the Exe that it has generated. This could be solved by replacing the 'move' command with the 'copy' command but in this case you would have to copy the Exe to another directory because surely you don't want to have the same file twice in the same directory.
All this is a mess. It is really incredible that you can enter the output directory directly in the project settings but to do something really basic as changing the Exe name you must write such a clumsy script which has ugly side effects. Shame on Microsoft!
如果将 .csproj 文件加载到文本编辑器中,则可以控制
AssemblyName
属性:请注意,这不仅会更改文件名,还会更改程序集名称,如果您有其他代码引用该程序集,这可能意味着麻烦。
我自己从来没有这样做过,所以我不能真正说这个想法有多好或多坏。
If you load the .csproj file into a text editor, you can control the
AssemblyName
property:Note though that this does not only change the file name, but the assembly name, which might mean trouble if you have other code referencing the assembly.
I never did this myself, so I can't really say how good or bad the idea is.
由于按照 Fredrik 的建议定义程序集名称标记的条件似乎会使 Visual Studio 变得暴躁,因此您可以稍后在 csproj 文件中更改程序集名称。使用 Choose element 有点像 if 语句,因此名称如果满足条件,则可以附加,如下所示。
从条件属性中的例如
DefineConstants
中获取子字符串似乎不可能(根据 MSDN)与“plain vanilla MSBuild”,但可以定义自己的构建目标并在使用/p:Tag=value
编译时设置属性( MSBuild 命令行参考)Since defining a condition to the assemblyname tag as suggested by Fredrik seems to make Visual Studio cranky, you can change the assembly name later in the csproj file. Using the Choose element is kind of like an if statement, so a name can be appended if a condition is met, demonstrated below.
Getting a substring out of for instance
DefineConstants
in a condition attribute does not seem possible (according to MSDN) with "plain vanilla MSBuild", but one can define their own build targets and set a property when compiling with a/p:Tag=value
(MSBuild command line reference)您可以编辑 csproj 文件,它只是一个包含“任务”的 MSBuild 文件。
csproj 文件中有一个名为“AfterBuild”的部分。
也许,您可以在其中添加一个命令,将您的 exe 文件重命名为您选择的文件名。
(当然,您必须取消该部分的注释)。
也许是这样的:
我还没有进一步解决,但是您应该完成 Condition 属性,以便您可以检查条件符号是否已定义。
You can edit the csproj file, which is just an MSBuild file which contains 'tasks'.
There is a section in the csproj file which is called 'AfterBuild'.
Perhaps, you can add a command there which renames your exe file to the filename of your choice.
(Offcourse, You'll have to uncomment that section).
Perhaps something like this:
I haven't worked it out further, but you should complete the Condition attribute, so that you can check whether the conditional symbol is defined or not.