2012-05-23 23 views
6

我想將腳本轉換爲項目。在腳本中,我使用#I將路徑設置爲引用的.dll。有沒有辦法直接在.fsproj文件中指定這個路徑?.fsproj文件的#I等效物是什麼?

感謝

+0

#I是什麼意思? – User

+0

#I表示IncludePath也查找引用。 –

回答

7

fsproj文件實際上是一個MS Build腳本,所以你可以使用標準的MS建立功能來定義變量(如include路徑),並在項目文件中使用它們。這並不像在F#腳本文件中使用#I指令那麼簡單,但它應該給你類似的功能。

例如,您可以創建一個文件Includes.proj定義你包括像這樣的路徑:

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" DefaultTargets="Build" 
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <PropertyGroup> 
    <IncludePath>C:\MyIncludePath</IncludePath> 
    </PropertyGroup> 
</Project> 

然後你就可以修改fsproj文件引用上述文件,並使用您參考$(IncludePath)。可悲的是,這已經在一個文本編輯器來完成(即卸載的項目,進行修改,然後重新裝入):

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" DefaultTargets="Build" 
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <Import Project="Includes.proj" /> 
    <!-- lots of other stuff --> 
    <ItemGroup> 
    <Reference Include="mscorlib" /> 
    <Reference Include="System" /> 
    <Reference Include="FSharp.Core" /> 
    <Reference Include="MyAssembly"> 
     <HintPath>$(IncludePath)\MyAssembly.dll</HintPath> 
    </Reference> 
    </ItemGroup> 
    <!-- lots of other stuff --> 
</Project> 
5

可以在Project Properties設定的基準文件夾 - >Reference Paths - >Add Folder

如果要以編程方式執行此操作,請在<Project><PropertyGroup><ReferencePath>...下設置參考路徑,並在<Project><ItemGroup><Reference><HintPath>...中設置dll的相對路徑。這裏是a script做反向(從fsproj到fsx文件),但它可以給你一些提示繼續。

相關問題