Skip to content

Commit 4aee6c3

Browse files
authored
Added support for "source", "project" and "dll" reference directives (#5)
1 parent 53b795d commit 4aee6c3

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
##
44
## Get latest from `dotnet new gitignore`
55

6+
TODO.md
7+
meeting.md
8+
dotnet-tools.json
9+
610
# dotenv files
711
.env
812

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 1.0.6
4+
5+
### added
6+
7+
* support for "source", "project" and "dll" reference directives
8+
39
## 1.0.5
410

511
### changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ The following directives (source lines) are recognized by runfs:
2222
- `#r_package "pp@1.0.0"` - references package pp, version 1.0.0
2323
- `#r_sdk "mysdk@0.0.1"` - references an sdk
2424
- `#r_property "myprop=42"` - sets a build property
25-
- `#r_project "xyz.fsproj"` - references a project [not yet implemented]
26-
- `#r_dll "mylib.dll"` - references a library [not yet implemented]
27-
- `#r_source "utilities.fs"` - references a source file [not yet implemented]
25+
- `#r_project "xyz.fsproj"` - references a project
26+
- `#r_dll "mylib.dll"` - references a library
27+
- `#r_source "utilities.fs"` - references a source file
2828

2929
> The above directive syntax is preliminary and made to work with the current F# compiler (the parser accepts and ignores them). Ideally, the syntax defined for "dotnet run app.cs" should be reused, like `#:package pp@1.0.0`, but this needs a compiler fix first.
3030
@@ -63,7 +63,7 @@ Main learnings
6363
Runfs
6464
- investigate if the "compile only" shortcut can be replicated for F#
6565
- add more tests, possibly Rid-package, fix case sensitivity issue in Directives.fs
66-
- implement the #project, #source and #dll directives and `--convert`
66+
- implement `--convert`
6767

6868
Elsewhere
6969
- propose and possibly implement a compiler change so that the 'dotnet run app.cs' syntax for directives can be used

src/Runfs/ProjectFile.fs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ let private packageLine (name, version) =
2727
| None -> $""" <PackageReference Include="{escape name}" />"""
2828
| Some v -> $""" <PackageReference Include="{escape name}" Version="{escape v}"/>"""
2929

30+
let private sourceLine name =
31+
$""" <Compile Include="{escape name}" />"""
32+
33+
let private dllLine name =
34+
$""" <Reference Include="{escape name}" />"""
35+
36+
let private projectLine name =
37+
$""" <ProjectReference Include="{escape name}" />"""
38+
3039
let createProjectFileLines directives entryPointSourceFullPath artifactsPath assemblyName =
3140
let sdks =
3241
match directives |> List.choose (function Sdk(n, v) -> Some(n, v) | _ -> None) with
@@ -37,6 +46,9 @@ let createProjectFileLines directives entryPointSourceFullPath artifactsPath ass
3746
let remainingDefaultProperties =
3847
DefaultProperties |> List.filter (fun (k, _) -> not (Map.containsKey (k.ToLowerInvariant()) properties))
3948
let packages = directives |> List.choose (function Package(n, v) -> Some(n, v) | _ -> None)
49+
let dlls = directives |> List.choose (function Dll n -> Some n | _ -> None)
50+
let sources = directives |> List.choose (function Source n -> Some n | _ -> None)
51+
let projects = directives |> List.choose (function Project n -> Some n | _ -> None)
4052

4153
[
4254
"<Project>"
@@ -56,6 +68,13 @@ let createProjectFileLines directives entryPointSourceFullPath artifactsPath ass
5668
yield! packages |> List.map packageLine
5769
" </ItemGroup>"
5870
" <ItemGroup>"
71+
yield! dlls |> List.map dllLine
72+
" </ItemGroup>"
73+
" <ItemGroup>"
74+
yield! projects |> List.map projectLine
75+
" </ItemGroup>"
76+
" <ItemGroup>"
77+
yield! sources |> List.map sourceLine
5978
$""" <Compile Include="{escape entryPointSourceFullPath}" />"""
6079
" </ItemGroup>"
6180
yield! sdks |> List.map (sdkLine "Sdk.targets")

src/Runfs/Runfs.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ let run (options, sourcePath, args) =
118118
let readPreviousSourceHash() = File.ReadAllText sourceHashPath
119119
not (File.Exists sourceHashPath && readPreviousSourceHash() = sourceHash)
120120
let noDll = not (File.Exists dllPath)
121-
Ok (dependenciesChanged || noDll, sourceChanged)
121+
let hasProjectDirective = directives |> List.exists (function Project _ -> true | _ -> false)
122+
Ok (dependenciesChanged || noDll || hasProjectDirective, sourceChanged)
122123

123124
if needsRestore then
124125
do! guardAndTime "creating and writing project file" <| fun () ->

src/Runfs/Runfs.fsproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<!-- General -->
44
<AssemblyName>Runfs</AssemblyName>
5-
<Version>1.0.5</Version>
5+
<Version>1.0.6</Version>
66
<Description>"dotnet run app.cs" functionality for F#.</Description>
77
<Copyright>Copyright 2025 by Martin521</Copyright>
88
<Authors>Martin521 and contributors</Authors>
@@ -14,7 +14,13 @@
1414
<PackageTags>F#</PackageTags>
1515
<PackAsTool>True</PackAsTool>
1616
<ToolCommandName>runfs</ToolCommandName>
17-
<PackageReleaseNotes>https://github.com/Martin521/Runfs/blob/main/CHANGELOG.md</PackageReleaseNotes>
17+
<PackageReleaseNotes>
18+
## 1.0.6
19+
20+
### added
21+
22+
* support for "source", "project" and "dll" reference directives
23+
</PackageReleaseNotes>
1824
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1925
<PackageIcon>
2026
</PackageIcon>
@@ -39,7 +45,5 @@
3945

4046
<PackageReference Include="Microsoft.Build" Version="17.14.8" ExcludeAssets="runtime" />
4147
<PackageReference Include="Microsoft.Build.Locator" Version="1.9.1" />
42-
43-
<!-- <PackageReference Include="Microsoft.Build" Version="17.15.0-preview-25277-114" /> -->
4448
</ItemGroup>
4549
</Project>

tests/Runfs.Tests/TestFiles/test1.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module A =
22
open System
33

4-
#r_project "abc/xyz.fsproj"
5-
#r_dll "System.dll"
4+
// #r_project "abc/xyz.fsproj"
5+
// #r_dll "System.dll"
66
#r_property "myprop=43"
77
#r_property "TargetFramework=net9.0"
88

0 commit comments

Comments
 (0)