簡體   English   中英

Visual Studio 2010項目文件中的條件

[英]Conditionals in Visual Studio 2010 Project files

在Visual Studio 2010 C ++項目文件中,是否可以使用條件來確定是否存在庫,適當地更改預處理器標志等?

更具體地說,假設我們有一個目錄C:\\libraries\\MKL ,我想#define MKL並添加mkl_dll.lib作為附加依賴項(如果該目錄存在)。

以前,我們使用多種解決方案配置來實現此目的,但這很難維護。

將以下內容粘貼到F#項目的底部時,具有建議的效果(如果存在c:\\temp\\foo.txt ,則為THE_FILE_EXISTS添加#define )。 我希望C ++項目只需要進行少量修改,因為它們都使用MSBuild。 也許這有點怪癖,這是我要做的第一件事。

<UsingTask TaskName="SeeIfFileExists" TaskFactory="CodeTaskFactory" 
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
  <ParameterGroup>
    <Path ParameterType="System.String" Required="true" />
    <ItExists ParameterType="System.Boolean" Output="true" />
  </ParameterGroup>
  <Task>
    <Code Type="Fragment" Language="cs">
      <![CDATA[
ItExists = System.IO.File.Exists(Path);
]]>
    </Code>
  </Task>
</UsingTask>
<Target Name="SeeIfFileExistsTarget" BeforeTargets="PrepareForBuild">
  <SeeIfFileExists Path="c:\temp\foo.txt" >
    <Output TaskParameter="ItExists" ItemName="TheFileExists" />
  </SeeIfFileExists>
  <PropertyGroup>
    <DefineConstants Condition="'@(TheFileExists)'=='True'"
        >$(DefineConstants);THE_FILE_EXISTS</DefineConstants>
  </PropertyGroup>
</Target>

我只是想到

<PropertyGroup>
    <DefineConstants Condition="Exists('c:\temp\foo.txt')"
        >$(DefineConstants);THE_FILE_EXISTS</DefineConstants>
</PropertyGroup>

可能就足夠了,但還不如性感。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM