VS2008 - 用于调试/发布配置输出不同的文件名文件名、不同

2023-09-03 02:20:54 作者:佰仙

在构建一个C#应用程序使用Visual Studio 2008,是不是可以设置每个配置不同的输出文件名?

When building a C# application with Visual Studio 2008, is it possible to set a different output filename per configuration?

e.g.

MyApp_Debug.exe
MyApp_Release.exe

我试过后生成步骤通过附加当前配置文件重命名,但似乎好斗的做法。加上它意味着Visual Studio中再也找不到该文件时pressing F5开始调试。

I tried a post-build step to rename the file by appending the current configuration, but that seems a scrappy approach. Plus it meant that Visual Studio could no longer find the file when pressing F5 to start debugging.

推荐答案

您可以通过手动编辑您的项目文件实现这一目标。找到<的AssemblyName> 节点,然后添加一个条件属性吧:

You can achieve this by editing your project file by hand. Locate the <AssemblyName> node and add a conditional attribute to it:

<AssemblyName Condition="'$(Configuration)'=='Debug'">MyApp_Debug.exe</AssemblyName>
<AssemblyName Condition="'$(Configuration)'=='Release'">MyApp_Release.exe</AssemblyName>

您将不得不重复它也添加其他条件属性的发行版本。

You'll have to duplicate it also to add another conditional attribute for the release version.

虽然是可能的,它可能会导致问题。有一个AssemblyConfiguration可以应用到您的程序集的属性。在的AssemblyInfo.cs ,把:

Whilst it is possible, it may cause problems. There is an AssemblyConfiguration attribute that can be applied to your assembly. In AssemblyInfo.cs, put:

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

这将属性添加到您编译的程序集,将告诉你哪些构建配置您的应用程序使用内置。

This will add a property to your compiled assembly that will tell you which build configuration your application was built using.