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
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With