Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the #I equivalent for a .fsproj file?

Tags:

f#

I want to convert a script to a project. In the script, I set the path to the referenced .dlls using #I. Is there a way to specify this path directly in the .fsproj file ?

Thanks

like image 220
fpessoa Avatar asked May 23 '12 12:05

fpessoa


2 Answers

The fsproj file is actually an MS Build script, so you can use standard MS Build features to define variables (such as your include path) and use them in the project file. This is not as simple as using #I directive in F# script files, but it should give you similar features.

For example, you can create a file Includes.proj that defines your include path like this:

<?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>

Then you can modify the fsproj file to reference the above file and use $(IncludePath) in your references. Sadly, this has to be done in a text editor (i.e. unload the project, modify it and then reload it):

<?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>
like image 85
Tomas Petricek Avatar answered Nov 15 '22 09:11

Tomas Petricek


You can set reference folders in Project Properties -> Reference Paths -> Add Folder.

If you want to do this programmatically, set Reference Paths under <Project><PropertyGroup><ReferencePath>... and set relative paths of dlls in <Project><ItemGroup><Reference><HintPath>.... Here is a script doing in reverse (from fsproj to fsx file), but it could give you some hints to proceed.

like image 37
pad Avatar answered Nov 15 '22 11:11

pad