附加附加许多Visual Studio属性表(.props)的%PATH% [英] append %PATH% of many Visual Studio property sheets (.props) additively

查看:179
本文介绍了附加附加许多Visual Studio属性表(.props)的%PATH%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在属性表的项目中本地定义PATH,我需要将其添加到LocalDebuggerEnvironment中.

To define PATH locally in a project from property sheet, I need to add it in LocalDebuggerEnvironment.

当只有1个定义PATH的属性表时,此方法效果很好.

This approach works well when there is only 1 property sheet that define PATH.

如果我有多个属性表,而我想使用每个属性表中的PATH
Visual Studio将仅考虑我包含的最后属性表中的PATH.

If I have more than one property sheet, while I want to use PATH from every property sheet,
Visual Studio will consider only PATH of the last property sheet that I have included.

如果我创建属性表B1.props:-

<PropertyGroup Label="UserMacros"><LocalDebuggerEnvironment>
PATH=SOMEPATH1;%PATH%     
</LocalDebuggerEnvironment></PropertyGroup>

,属性表B2.props:-

<PropertyGroup Label="UserMacros"><LocalDebuggerEnvironment>
PATH=SOMEPATH2;%PATH%       <!-- different only this line -->
</LocalDebuggerEnvironment></PropertyGroup> 

,属性表C.props(=包括B1.props& B2.props):-

, property sheet C.props (=include B1.props & B2.props):-

<ImportGroup Label="PropertySheets">
    <Import Project="B1.props" />
    <Import Project="B2.props" />
  </ImportGroup>

,然后将Visual Studio项目设置为使用C.props

, and set a Visual Studio project to use C.props

,我将得到结果:PATH=SOMEPATH2;%PATH%.

如何使Visual Studio使用路径的总和,例如PATH=SOMEPATH2; SOMEPATH1 ;%PATH%
...同时保持良好的属性表 modularity ?

How to make Visual Studio use the summation of path e.g. PATH=SOMEPATH2;SOMEPATH1;%PATH%
... while maintain the nice property sheet modularity?

推荐答案

您需要一种或另一种方式来继承每个导入的属性表中的属性值.您将看到是否编写了<A>someValue</A>,那么无论A是什么,现在都将其设置为someValue.您需要<A>someValue;$(A)</A>使评估值由旧"值与新值组成.

One way or another you'll need to inherit property values in each imported property sheet. You see if you write <A>someValue</A> then whatever A was it will now be set to someValue. You need <A>someValue;$(A)</A> to make the evaluated value consist of the 'old' one concatenated with the new one.

在这种情况下,由于PATH =表达式,您不能简单地连接变量.假设您将使用

In this case you cannot simply concatenate the variables though becasue of the PATH= expression. Suppose you'd use

<LocalDebuggerEnvironment>PATH=SOMEPATH;$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>
<LocalDebuggerEnvironment>PATH=SOMEPATH2;$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>

那你最终会得到

PATH=SOMEPATH2;PATH=SOMEPATH

因此,您需要一种解决方法.一种方法是为要添加的路径使用单独的值:

So you need a workaround. One way is using a separate value for paths which you want to add:

B1:

<PropertyGroup Label="UserMacros">
  <PathValue>SOMEPATH;$(PathValue)</PathValue>
  <LocalDebuggerEnvironment>PATH=$(PathValue);%PATH%</LocalDebuggerEnvironment>
</PropertyGroup>

B2:

<PropertyGroup Label="UserMacros">
  <PathValue>SOMEPATH2;$(PathValue)</PathValue>
  <LocalDebuggerEnvironment>PATH=$(PathValue);%PATH%</LocalDebuggerEnvironment>
</PropertyGroup>

C:

<PropertyGroup Label="UserMacros">
  <LocalDebuggerEnvironment>PATH=$(PathValue);%PATH%</LocalDebuggerEnvironment>
</PropertyGroup>

缺点是您需要2个变量,并且必须在每个文件中重复LocalDebuggerEnvironment部分,否则您将不能单独使用它们.但是对于其余部分,它非常有用且清晰.而且,如果您不想单独使用B1和B2,则根本不需要在其中使用LocalDebuggerEnvironment.然后,如果只需要B1中的值,则将C和B1添加到项目中.

Disadvantage is that you need 2 variables and have to repeat the LocalDebuggerEnvironment part in each file otherwise you cannot use them standalone. However for the rest it's pretty usable and clear. And if you do not want to use B1 and B2 by themselves, you don't need the LocalDebuggerEnvironment in them at all. Then if you want just the value from B1, you'd add C and B1 to your project.

我目前看到的唯一替代方法是,您必须对值进行一些解析才能使继承工作正常,而无需重复PATH =部分.但这不是很漂亮,在某些情况下可能会破坏.总而言之,我会建议这样做,太复杂了.这是一种变化;使用属性函数,当前值LocalDebuggerEnvironment,删除PATH =部分,删除%PATH%部分,然后删除一些连续的分号(我猜不是必须的).如您所见,C不需要任何东西,因为B已经负责继承值了,因此可以独立使用:

The only alternative I see currently would mean you'd have to do some parsing of the value to get the inheriting working without repating the PATH= part. But that won't be exactly pretty and can probably break in some cases. All in all I'd advice against it, just too complicated. Here's one variation; using Property Functions, take the current value of LocalDebuggerEnvironment, remove the PATH= part, remove the %PATH% part, then remove some consecutive semicolons (not strictly needed I guess). As you can see C doesn't need anything since the Bs already take care of inheriting the value and as such can be used standalone:

B1:

<PropertyGroup Label="UserMacros">
  <LocalDebuggerEnvironment>PATH=SOMEPATH;$(LocalDebuggerEnvironment.Replace('PATH=', '').Replace('%PATH%', '').Replace(';;', ';'));%PATH%</LocalDebuggerEnvironment>
</PropertyGroup>

B2:

<PropertyGroup Label="UserMacros">
  <LocalDebuggerEnvironment>PATH=SOMEPATH2;$(LocalDebuggerEnvironment.Replace('PATH=', '').Replace('%PATH%', '').Replace(';;', ';'));%PATH%</LocalDebuggerEnvironment>
</PropertyGroup>

C:

<PropertyGroup Label="UserMacros" />

这篇关于附加附加许多Visual Studio属性表(.props)的%PATH%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆