Visual Studio 2010 - 保留不同构建配置之间的项目属性?

发布于 2025-01-04 18:34:00 字数 184 浏览 0 评论 0原文

我的解决方案中有两个项目。我目前使用默认配置模式“调试”。当我想要进行“发布”构建时,我切换到发布模式,然后我看到我以前的所有项目属性都设置为默认值,这意味着我必须再次手动将所有属性添加到此模式。

在 VS2010 中是否有一种方便的方法来解决这个问题,例如将所有属性(如包含路径、预处理器宏、构建宏等)从“调试”模式复制到“发布”模式?

I have two projects in my solution. I am currently using the default configuration mode which is 'Debug'. When I want to do a 'Release' build, I switch to Release-mode and then I see all my previous projects properties are set to default, meaning I have to add all properties again manually to this mode.

Is there a convenient way to solve this in VS2010, for example to copy all properties like include paths, preprocessor macros, build macros, etc from 'Debug' to 'Release' mode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

薄凉少年不暖心 2025-01-11 18:34:00

配置设置存储在 .vcproj / .vcxproj 文件中。您可以在某些文本编辑器中打开它并手动复制一些设置,但这并不方便。现在,您只需打开项目属性并复制这些设置,同时在该窗口左上角切换“调试”/“发布”配置。

下次当您设置所有配置都相同的属性时,请选择配置:所有配置以避免出现问题。

Configuration settings are stored in .vcproj / .vcxproj file. You could open it in some text editor and copy some settings manually, but it wouldn't be convenient. For now you could just open projects properties and copy these settings while switching Debug / Release configuration in the upper left corner of that window.

Next time when you are setting properties that are intended to be the same for all configurations, choose Configuration: All Configurations to avoid troubles.

甜柠檬 2025-01-11 18:34:00

财产表可以轻松解决这个问题以及其他一些与财产相关的问题。

简而言之,项目中的所有属性只是 XML 文档中的节点,并且属性组节点可以具有 condition 属性。它们在任何文本编辑器中都很容易更改,但一个鲜为人知的功能是导入其他 XML 文档的能力,它可以提供设置(除了少数特定于项目的文档之外的所有文档)。

这篇博文有一个很好的内容有关使用项目表的教程以及 这个问题。您可以在 Visual Studio 中创建它们,对其进行编辑(包括复制现有项目设置),然后使用属性manager(不是属性窗口)将它们附加到您的项目。

属性表中的组使用与常规设置相同的语法,可以针对所有配置进行设置,也可以进行过滤以仅应用于某些配置。它们还可以使用 VS 的变量和条件系统按项目名称和其他一些内容进行过滤。例如,我使用:

<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  <ClCompile>
    <WarningLevel>Level4</WarningLevel>
    <TreatWarningAsError>true</TreatWarningAsError>
    <Optimization>Disabled</Optimization>
    <EnablePREfast>true</EnablePREfast>
    <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
  </ClCompile>
</ItemDefinitionGroup> 

对于我的一些构建,将相同的设置应用于所有项目(完整文件在这里)。

最方便的用途之一是在文件中给出构建目录,以便所有项目统一构建到同一目录中(确保使用项目名称作为输出)。

Property sheets can solve this and a few other property-related issues with ease.

In short, all the properties in a project are just nodes in an XML document, and the property group nodes can have a condition attribute. They're easy to change in any text editor, but a lesser-known feature is the ability to import other XML documents, which can provide settings (for all but a few project-specific ones).

This blog post has a good tutorial on using project sheets, and some more info in this question. You can create them in Visual Studio, edit them (including copying your existing project settings over), then attach them to your project with the property manager (not the property window).

The groups in your property sheet use the same syntax as regular settings, and can be set for all configurations or filtered to only apply on some. They can also be filtered by project name and a few other things, using VS' variable and condition system. For example, I use:

<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  <ClCompile>
    <WarningLevel>Level4</WarningLevel>
    <TreatWarningAsError>true</TreatWarningAsError>
    <Optimization>Disabled</Optimization>
    <EnablePREfast>true</EnablePREfast>
    <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
  </ClCompile>
</ItemDefinitionGroup> 

for some of my builds, to apply the same settings to all project (full file here).

One of the most convenient uses is giving the build directory in the file, so all your projects build uniformly into the same directory (make sure to use the project name for the output).

情愿 2025-01-11 18:34:00

通过使用宏,可以通过单个设置集合来管理多个不同构建(调试、发布、win32、x64 等)中的几乎所有属性。

因此,在编辑项目设置之前,请确保已将配置设置为所有配置,并将平台:设置为所有平台。现在,几乎所有不同的配置都可以通过这种方式完成设置。比如说,您希望不同的配置和平台使用不同版本的各种库。假设您使用的命名约定在所有项目中都一致,则可以使用:

其他库目录:..\..\foo\bar\lib\$(Platform)_$(Configuration)

您可以通过点击“编辑”按钮,然后单击“宏”按钮来查看宏将扩展为哪些宏。

Managing almost all the properties across multiple different builds (debug, release, win32, x64 etc.) can be accomplished with a single collection of settings by using Macros.

Thus, before editing a project settings, make sure you've set Configurations to All Configurations and, Platform: to All Platforms. Now almost all settings can be done in this way, across all the different configurations. Say, you want different configurations and platforms to use different versions of various libraries. Assuming you are using a naming convention that's consistent across all projects, you can then use:

Additional Library Directories: ..\..\foo\bar\lib\$(Platform)_$(Configuration)

You can see what macros will expand to, by hitting the edit button, and then clicking on the Macros>> button.

玩心态 2025-01-11 18:34:00

您还可以使用配置管理器重新创建所需的新模式,然后可以选择要从哪个配置中复制所有设置。

You could also recreate the new mode you want using the configuration manager and then you can choose from which configuration you want to copy all the settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文