1

我有一个构建,其中一些包含和库路径必须根据构建是 32 位还是 64 位而有所不同,并且必须进行参数化以便用户轻松编辑。我正在使用属性表来处理该要求。

在学习了条件属性之后,我想我会尝试摆脱使用每个平台属性表来根据主属性表中的值设置宏(例如PGBASEDIR$(PGBASEDIR_x64)x64 和$(PGBASEDIR_x86)x86 上设置;有关详细信息,请参阅回答上面链接的问题)。

我改为在我的msbuild 目标文件中使用条件属性,但发现虽然构建它自己工作,但VS 的编辑器找不到路径由条件属性指定的包含文件。如果我在属性表.props文件的条件属性组中设置属性,或者将单个条件属性添加到主属性组,情况也是如此。

所以我在 msbuild 目标文件中都试过这个:

<PropertyGroup Condition="'$(Platform)' == 'x64'">
  <PGBASEDIR>$(PGBASEDIR_x64)</PGBASEDIR>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'Win32'">
  <PGBASEDIR>$(PGBASEDIR_x86)</PGBASEDIR>
</PropertyGroup>

并且还尝试将其添加到所有构建配置/平台中包含的属性表文件中。结果相同。我还尝试在属性表的主<PropertyGroup Label="UserMacros">块中使用单个条件属性;再次,同样的效果。

当我通过转到项目属性、对其进行编辑并MACROS>在 UI 中按选项卡打开列表来检查 Visual Studio 中的宏列表时,我看到了在属性表中静态定义的宏,但没有看到条件宏。

我尝试<BuildMacro>在主属性表<ItemGroup>中添加条目以防出现问题,例如:

<BuildMacro Include="PGBASEDIR">
  <Value>$(PGBASEDIR)</Value>
</BuildMacro>

...但没有看到任何变化。

在所有情况下,其自身的构建都运行良好,但 Visual Studio 的编辑器抱怨它找不到标头(因此找不到其中定义的任何内容)。

如果我坚持使用堆叠的属性表,它会起作用,例如:

  • pg_sysdatetime 项目

    • 发布 | win32
    • pg_sysdatetime.props

        <PropertyGroup Label="UserMacros">
          <PGMAJORVERSION>9.2</PGMAJORVERSION>
          <PGBASEDIR_x64>$(PROGRAMW6432)\PostgreSQL\$(PGMAJORVERSION)</PGBASEDIR_x64>
          <PGBASEDIR_x86>$(MSBUILDPROGRAMFILES32)\PostgreSQL\$(PGMAJORVERSION)</PGBASEDIR_x86>
        </PropertyGroup>
        <PropertyGroup />
        <ItemDefinitionGroup />
        <ItemGroup>
          <BuildMacro Include="PGMAJORVERSION">
            <Value>$(PGMAJORVERSION)</Value>
          </BuildMacro>
          <BuildMacro Include="PGBASEDIR_x64">
            <Value>$(PGBASEDIR_x64)</Value>
          </BuildMacro>
          <BuildMacro Include="PGBASEDIR_x86">
            <Value>$(PGBASEDIR_x86)</Value>
          </BuildMacro>
        </ItemGroup>
      
    • pg_sysdatetime_x86.props

      • 定义<PGBASEDIR>$(PGBASEDIR_x86)</PGBASEDIR>
    • 发布 | x64
    • pg_sysdatetime.props
      • ...同上...
    • pg_sysdatetime_x64.props
      • 定义<PGBASEDIR>$(PGBASEDIR_x64)</PGBASEDIR>

我正在使用 Visual Studio 2012 Express。

4

2 回答 2

4

在这些情况下,通常最好使用<CHOOSE><WHEN>构造

所以你最终可能会得到:

 <Choose>
    <When Condition="'$(Platform)' == 'x64'">
       <PropertyGroup>
         <PGBASEDIR>$(PGBASEDIR_x64)</PGBASEDIR>
       </PropertyGroup>
    </When>

    <When Condition="'$(Platform)' == 'win32'">
       <PropertyGroup>
         <PGBASEDIR>$(PGBASEDIR_x86)</PGBASEDIR>
       </PropertyGroup>
    </When>

    <Otherwise> <!-- Default -->
       <PropertyGroup>
         <PGBASEDIR>$(PGBASEDIR)</PGBASEDIR>
       </PropertyGroup>
    </Otherwise>
 </Choose>
于 2014-09-17T12:21:31.670 回答
0

Hmm, I recall a property that is used to indicate a normal build vs a partial build for things like intellisence and design-time editors to use. Maybe there is some short circuit that skips over your path settings in this case. Using MSBuild Explorer 3, I see some properties with names like ProjectDesignTime* so maybe a different include path is used by Intellisense.

I think what you really want is to find out how MSBuild is being called for Intellisense processing. I wonder if it could log to a file so you could see what was happening and when it was processed?

Try using the unsupported feature of debugging MSBuild evaluation. “Do a Bing search on "Debugging MSBuild" and be sure to locate all three parts of the blog posting.” by Dan Moseley of the MSBuild team at Microsoft.

于 2014-09-18T04:15:31.113 回答