简体   繁体   English

Visual Studio 2012中外部项目的配置

[英]Configurations from External Projects in Visual Studio 2012

I am having a problem with Visual Studio 2012, and I am hoping there is a solution to this. 我遇到了Visual Studio 2012的问题,我希望有一个解决方案。 I have in my solution 2 projects: 1 project is an ".exe" project, and the other is a ".lib" project. 我在我的解决方案中有2个项目:1个项目是“.exe”项目,另一个是“.lib”项目。 I have added the lib project as a reference in the exe project, and I have ensured that it is scheduled to be compiled first. 我已经在lib项目中添加了lib项目作为参考,并且我确保它被安排首先编译。 The lib project has a bunch of additional include directories and a bunch of additional dependencies and linked libraries. lib项目有一堆额外的include目录和一堆额外的依赖项和链接库。 The lib project compiles fine. lib项目编译得很好。 However, none of the additional include directories or additional library directories or dependencies are being inherited by the exe application. 但是,exe应用程序不会继承任何其他包含目录或其他库目录或依赖项。 I was able to resolve this by copying the configurations to the exe project, but that means that if I ever update the lib dependencies, then I need to update it in every project that uses this library (I play to use this library for multiple projects). 我能够通过将配置复制到exe项目来解决这个问题,但这意味着如果我更新了lib依赖项,那么我需要在每个使用该库的项目中更新它(我玩这个库用于多个项目)。 This seems like something that there should be a solution for, but I just can't seem to find it. 这似乎应该有一个解决方案,但我似乎无法找到它。 Has anyone figured out a way to have projects inherit the configurations of referenced projects, or is there no way around this? 有没有人想出让项目继承引用项目的配置的方法,或者没有办法解决这个问题? Thanks. 谢谢。

You're right, projects don't inherit the properties of other projects they reference. 你没错,项目不会继承他们引用的其他项目的属性。 To solve your problem what you need is a property sheet . 要解决您的问题,您需要的是一个属性表 A property sheet is a collection of Properties (like you set in your Project Properties) separate from a project. 属性表是与项目分开的属性集(就像您在“项目属性”中设置的那样)。 You can apply a single property sheet to many projects. 您可以将单个属性表应用于许多项目。

In your case, the "additional library dependencies" and "additional include directories" will be placed into a property sheet. 在您的情况下,“附加库依赖项”和“其他包含目录”将放入属性表中。 That property sheet will be applied to both your .exe project and your .lib project. 该属性表将应用于.exe项目和.lib项目。 When you make changes, you will make them to the property sheet and both projects will see the changes. 进行更改时,您将把它们添加到属性表中,两个项目都将看到更改。

Let's go step-by-step through setting up a property sheet to do what you want. 让我们一步一步地设置属性表来做你想做的事情。

  1. Load your solution file with your .exe and .lib projects. 使用.exe.lib项目加载解决方案文件。 Let's suppose the name of your library is PowerMath.lib and your main executable is SuperCalc.exe . 假设您的库的名称是PowerMath.lib而您的主要可执行文件是SuperCalc.exe
  2. Find the Solution Explorer window in Visual Studio. 在Visual Studio中找到解决方案资源管理器窗口。 This is the sub-window that lists all your projects, and the files inside those projects. 这是列出所有项目的子窗口,以及这些项目中的文件。 (If you don't have one, click on the View menu and choose the Solution Explorer option to create one.) (如果没有,请单击“查看”菜单,然后选择“解决方案资源管理器”选项以创建一个。)
  3. First, let's take the settings out of the Project Properties where you have them set now. 首先,让我们从现在设置它们的项目属性中取出设置。 Go to the project properties for the PowerMath.lib project (right-click on that project in the Solution Explorer and choose Properties from the context menu). 转到PowerMath.lib项目的项目属性(在解决方案资源管理器中右键单击该项目,然后从上下文菜单中选择“属性”)。 Find your "additional library dependencies" and "additional include directories" settings that you made, and delete them. 找到您所做的“其他库依赖项”和“其他包含目录”设置,然后将其删除。 (Only delete your changes, not whatever was there before.) (Also, write your stuff down or copy it somewhere -- it's going to come back in step 10.) When you are done with the PowerMath.lib project, repeat the process with the SuperCalc.exe project. (只删除你的更改,而不是以前的更改。)(另外,写下你的东西或将其复制到某个地方 - 它将在步骤10中返回。)完成PowerMath.lib项目后,重复该过程使用SuperCalc.exe项目。 Rip it all out so it doesn't interfere with the new approach we're going to take. 把它全部撕掉,这样就不会干扰我们要采取的新方法。 Be sure you've done this for all configurations of your projects (Debug and Release, Win32 and x64). 确保您已为项目的所有配置(Debug和Release,Win32和x64)执行此操作。
  4. Down at the bottom of the Solution Explorer window you will see several tabs, including: Solution Explorer, Class View, and Property Manager. 在Solution Explorer窗口的底部,您将看到几个选项卡,包括:Solution Explorer,Class View和Property Manager。 These may be abbreviated if the window is small. 如果窗口很小,这些可以缩写。 Click on Property Manager . 单击Property Manager
  5. In the Property Manager you'll see two entries: the PowerMath and SuperCalc project names. 在Property Manager中,您将看到两个条目: PowerMathSuperCalc项目名称。 Right-click on the PowerMath.lib project, and choose the menu option Add New Property Sheet . 右键单击PowerMath.lib项目,然后选择菜单选项“ 添加新属性表”
  6. Choose a good Name that refers to your library. 选择一个引用您图书馆的好名称。 I would suggest PowerMath-settings.props . 我建议使用PowerMath-settings.props Then click Add to create the property sheet, and automatically attach it to the PowerMath .lib project. 然后单击“ 添加”以创建属性表,并自动将其附加到PowerMath .lib项目。
  7. Back in the Property Manager pane, you see that PowerMath has two elements underneath it: Debug and Release . 回到Property Manager窗格,您会看到PowerMath下面有两个元素: DebugRelease These are the two configurations of your library. 这些是您的库的两种配置。 If you "open them up" by clicking on them with the mouse, you'll see that the PowerMath-settings property sheet has been attached to both configurations. 如果您通过鼠标单击它们“打开它们”,您将看到PowerMath-settings属性表已附加到这两个配置。
  8. The PowerMath-settings property sheet is listed above a bunch of other property sheets that were already present, which have names like Core Windows Libraries and Unicode Support . PowerMath-settings属性表列在一堆已存在的其他属性表上方,这些属性表的名称类似于Core Windows LibrariesUnicode Support All of the settings in any configuration of your projects come from combining these property sheets! 您项目的任何配置中的所有设置都来自组合这些属性表! That's how properties work inside Visual Studio -- putting together all the project's property sheets, in order with the first one at the bottom. 这就是Visual Studio中属性的工作方式 - 将所有项目的属性表放在一起,按顺序放在第一个属性表的底部。
  9. Double-click on the PowerMath-settings property sheet in the list. 双击列表中的PowerMath-settings属性表。 This will take you to the familiar Project Properties interface. 这将带您进入熟悉的Project Properties界面。 Changes made here don't apply to a project or a particular configuration inside that project. 此处所做的更改不适用于项目或该项目内的特定配置。 Instead, you're writing the settings only for the property sheet PowerMath-settings.props . 相反,您只是为属性表PowerMath-settings.props编写PowerMath-settings.props
  10. Now you get to write your additional library dependencies and additional include directories . 现在,您可以编写其他库依赖项其他包含目录 Go to the dialog boxes where you expect to set those things. 转到您希望设置这些内容的对话框。 In the appropriate fields, click the little down arrow at the right side of the field and pick Edit... . 在相应的字段中,单击字段右侧的小向下箭头,然后选择Edit...
  11. In the edit box you will see a blank space where you can write your new settings. 在编辑框中,您将看到一个空白区域,您可以在其中编写新设置。 (You'll also see the "inherited values", which are the settings that came from other property sheets.) Add your stuff and then click OK. (您还会看到“继承的值”,这是来自其他属性表的设置。)添加您的东西,然后单击“确定”。
  12. When you're done, you'll have a property sheet called PowerMath-settings.props that stores the settings needed for all users of the PowerMath.lib library. 完成后,您将拥有一个名为PowerMath-settings.props的属性表,其中存储了PowerMath.lib库的所有用户所需的设置。
  13. Now go back to the Property Manager window. 现在返回Property Manager窗口。 Right-click on the SuperCalc project instead (this is your .exe). 右键单击SuperCalc项目(这是您的.exe)。 Choose the menu option Add Existing Property Sheet . 选择菜单选项添加现有属性表 Find PowerMath-settings.props and select it. 找到PowerMath-settings.props并选择它。
  14. Boom, now SuperCalc.exe gets all the settings you just created for PowerMath.lib . Boom,现在SuperCalc.exe获取您刚刚为PowerMath.lib创建的所有设置。
  15. To verify this, switch back from Property Manager to Solution Explorer (by clicking the Solution Explorer tab along the bottom of the sub-window). 要验证这一点,请从Property Manager切换回Solution Explorer(通过单击子窗口底部的Solution Explorer选项卡)。 Go to Project Properties for your SuperCalc.exe project. 转到SuperCalc.exe项目的项目属性。 Go to "additional include directories". 转到“其他包含目录”。 Click on the down-arrow at the left side of that field and pick Edit... . 单击该字段左侧的向下箭头,然后选择Edit... You will see that your property sheet settings are listed as "inherited values". 您将看到属性表设置被列为“继承值”。
  16. Sometimes the settings for a brand-new property sheet are not applied until you quit Visual Studio, re-start, and re-load the solution. 有时,在退出Visual Studio,重新启动和重新加载解决方案之前,不会应用全新属性表的设置。 Remember to click YES when it asks whether you want to save your project changes and new property sheets! 当它询问您是否要保存项目更改和新属性表时,请记住单击“是” Once it's all set up you shouldn't need to do this again. 一旦完成设置,您就不需要再次这样做了。

Now any time you have a new project that uses PowerMath.lib , just go to the Property Manager and Add Existing Property Sheet: PowerMath-settings.props . 现在,只要有一个使用PowerMath.lib的新项目,只需转到Property Manager并添加现有属性表: PowerMath-settings.props

Remember that all changes made to the properties in the property sheet have to be made via the Property Manager dialog boxes, not using the PowerMath.lib Project Properties! 请记住,必须通过“属性管理器”对话框对属性表中的属性进行所有更改, 而不是使用PowerMath.lib项目属性! Project Properties is a kind of "override" property sheet that only applies to one specific project. “项目属性”是一种“覆盖”属性表,仅适用于一个特定项目。 It stands above all the property sheets listed by the Property Manager. 它位于物业经理列出的所有物业单之上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM