什么是.fsproj文件的#I等价物?

fpe*_*soa 6 f#

我想将脚本转换为项目.在脚本中,我使用#I设置引用的.dll的路径.有没有办法直接在.fsproj文件中指定此路径?

谢谢

Tom*_*cek 7

fsproj文件实际上是一个MS Build脚本,因此您可以使用标准MS Build功能来定义变量(例如包含路径)并在项目文件中使用它们.这不像#I在F#脚本文件中使用指令那么简单,但它应该为您提供类似的功能.

例如,您可以创建一个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>
Run Code Online (Sandbox Code Playgroud)

然后,您可以修改该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>
Run Code Online (Sandbox Code Playgroud)


pad*_*pad 5

您可以在Project Properties- > Reference Paths- >中设置参考文件夹Add Folder.

如果要以编程方式执行此操作,请在下面设置"参考路径" <Project><PropertyGroup><ReferencePath>...并设置dll的相对路径<Project><ItemGroup><Reference><HintPath>....这是一个反向执行的脚本(从fsproj到fsx文件),但它可以为您提供一些提示.