发布配置输出不同的文件名

发布配置输出不同的文件名

本文介绍了VS2008 - 为调试/发布配置输出不同的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 在按 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.

推荐答案

您可以通过手动编辑项目文件来实现此目的.找到 节点并为其添加条件属性:

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.

这篇关于VS2008 - 为调试/发布配置输出不同的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 22:05