2010-07-29 53 views
2

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

更具體的,假設我們有一個目錄C:\libraries\MKL,我想#define MKL,並添加mkl_dll.lib作爲一個額外的依賴,如果該目錄存在。

此前我們已經使用多種解決方案配置來實現這一點,但這很難保持。

回答

1

將以下內容粘貼到F#項目的底部時,會產生建議效果(如果存在c:\temp\foo.txt,則會添加)。我期望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> 

可能就足夠了,但幾乎沒有性感。

+0

謝謝你。最終我無法讓第一個版本工作,但第二個版本是一種享受。 – ngoozeff 2010-07-29 08:47:10

相關問題