Skip to content

Commit c3f2ca7

Browse files
committed
⬆️ Support F# 8 and PowerShell 7.4
1 parent fd05982 commit c3f2ca7

File tree

12 files changed

+331
-60
lines changed

12 files changed

+331
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
**/out
44
.fake
55
.ionide
6+
Release

FSharp.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{836CC08C-E538-4343-96A8-4B3B87DB71A9}"
77
EndProject
8-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PoshFSharp", "src\FSharp\PoshFSharp.fsproj", "{6E93875C-A681-48BD-BB68-9A14C2480BFD}"
8+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp", "src\FSharp\FSharp.fsproj", "{6E93875C-A681-48BD-BB68-9A14C2480BFD}"
99
EndProject
1010
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpCore", "src\FSharpCore\FSharpCore.fsproj", "{D09B6A15-5628-4D74-AC7E-3F968259B0D1}"
1111
EndProject

README.MD

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
This is a PowerShell module to enable use of the F# language in PowerShell. It is currently only supported with Powershell 7.2+ at the moment.
44

5-
## Quickstart
5+
There are two separate modules that are published from this repo:
6+
7+
1. `FSharp`: Provides the `Add-FSharpType` command which enables dynamic compilation of F# code to be loaded into PowerShell.
8+
1. `FSharp.Core`: Provides the core fsharp libraries for FSharp-based modules. It is binary compatible so you should always set your modules to require the latest version of this module, even if you wrote for an older version, so that the latest version is always used.
9+
10+
## FSharp Quickstart
11+
612
```ps
713
Install-Module FSharp
814
Add-FSharpType -TypeDefinition @'
@@ -16,8 +22,13 @@ type Car = {
1622
[Test.Car]::new('Mazda','Miata',65)
1723
```
1824

19-
```
25+
```text
2026
model name speed
2127
----- ---- -----
2228
Mazda Miata 65
23-
```
29+
```
30+
31+
## Creating PowerShell Modules with F#
32+
33+
1. Create a new F# powershell module project as normal and set both `FSharp.Core` and `System.Management.Automation` as privateassets so they are not published.
34+
1. Your .psd1 file *must* have a dependency on the `FSharp.Core` module. Set your dependency to the minimumversion of F# code you are using or higher **always**, do not pin this dependency directly or it will cause problems.

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "7.0.102"
3+
"version": "8.0.100"
44
}
5-
}
5+
}

src/FSharp/FSharp.fsproj

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<OutputType>Library</OutputType>
6-
<!-- We want to selectively exclude FSharp.Core below, so we need to disable the implicit reference -->
6+
</PropertyGroup>
7+
8+
<PropertyGroup Label="BuildOptions">
79
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
10+
<DebugType>portable</DebugType>
811
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
9-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
12+
<GenerateDependencyFile>false</GenerateDependencyFile>
13+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
14+
<PublishDir>$(SolutionDir)/Release/FSharp</PublishDir>
15+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
1016
</PropertyGroup>
17+
1118
<ItemGroup>
12-
<!-- We ship FSharp.Core as part of common module fsharpcore, reference in the .psd1-->
13-
<PackageReference Include="fsharp.core" Version="7.0.0" ExcludeAssets="All" />
14-
<PackageReference Include="fsharp.compiler.service" Version="42.7.101"/>
15-
<PackageReference Include="System.Runtime.Remoting" Version="7.0.0"/>
19+
<PackageReference Include="fsharp.compiler.service" Version="43.8.100" />
20+
<!-- We ship FSharp.Core as part of common module FSharp.Core, which will be imported as a module dependency -->
21+
<PackageReference Include="fsharp.core" Version="8.0.100" />
22+
1623
</ItemGroup>
1724
<ItemGroup>
1825
<Compile Include="Library.fs" />
1926
<Content Include="FSharp.psd1" CopyToPublishDirectory="Always" />
2027
</ItemGroup>
2128
<ItemGroup>
2229
<!-- These are provided by Powershell 7 and dont need to be included in the package -->
23-
<PackageReference Include="System.Management.Automation" Version="7.3.0" PrivateAssets="All" />
24-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" ExcludeAssets="all" />
25-
<PackageReference Include="System.Drawing.Common" Version="7.0.0" ExcludeAssets="all" />
26-
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" ExcludeAssets="all" />
27-
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="7.0.0" ExcludeAssets="all" />
28-
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="7.0.0" ExcludeAssets="all" />
29-
<PackageReference Include="System.Security.Cryptography.Xml" Version="7.0.0" ExcludeAssets="all" />
30-
<PackageReference Include="System.Security.Permissions" Version="7.0.0" ExcludeAssets="all" />
31-
<PackageReference Include="System.Windows.Extensions" Version="7.0.0" ExcludeAssets="all" />
32-
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="7.0.0" ExcludeAssets="all" />
33-
<PackageReference Include="System.Diagnostics.EventLog" Version="7.0.0" ExcludeAssets="all" />
34-
<PackageReference Include="System.CodeDom" Version="7.0.0" ExcludeAssets="all" />
30+
<PackageReference Include="System.Management.Automation" Version="7.2.0" PrivateAssets="All" />
31+
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" PrivateAssets="All" />
32+
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" PrivateAssets="All" />
33+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" PrivateAssets="All" />
3534
</ItemGroup>
3635
</Project>

src/FSharp/FSharp.psd1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
RootModule = 'FSharp.dll'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.0.1'
15+
ModuleVersion = '8.0.0'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core'
1919

2020
# ID used to uniquely identify this module
21-
GUID = '46f9db37-c23c-45b5-a4b0-2f4a40cd53c5'
21+
GUID = '0d394a13-1e05-4db9-88ac-2bee72446d0b'
2222

2323
# Author of this module
2424
Author = 'Justin Grote @justinwgrote'
@@ -33,7 +33,7 @@
3333
Description = 'A F# Dynamic Compiler in the style of the Add-Type PowerShell command'
3434

3535
# Minimum version of the PowerShell engine required by this module
36-
PowerShellVersion = '7.2'
36+
PowerShellVersion = '7.4'
3737

3838
# Name of the PowerShell host required by this module
3939
# PowerShellHostName = ''
@@ -51,7 +51,7 @@
5151
# ProcessorArchitecture = ''
5252

5353
# Modules that must be imported into the global environment prior to importing this module
54-
RequiredModules = @('FSharp.Core')
54+
# RequiredModules = @('FSharp.Core')
5555

5656
# Assemblies that must be loaded prior to importing this module
5757
# RequiredAssemblies = @()

src/FSharp/Library.fs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
module AddFSharpType =
44
open FSharp.Compiler.CodeAnalysis
55
open System
6-
open type System.IO.Path
7-
open type System.IO.File
8-
open type System.Reflection.Assembly
6+
open System.IO
7+
open type Path
8+
open type File
9+
open System.Reflection
910

1011
/// This is basically the compiler so we name it that way
1112
let compiler = FSharpChecker.Create()
@@ -17,7 +18,12 @@ module AddFSharpType =
1718
tempFilePath.ToString()
1819

1920
let AddFromFile (sourceFile : string) =
21+
let currentDirectory = Directory.GetCurrentDirectory()
2022
let destination = GetTempFilePathWithExtension ".dll"
23+
let thisAssembly = Assembly.GetExecutingAssembly()
24+
let thisDirectory = GetDirectoryName(thisAssembly.Location)
25+
Directory.SetCurrentDirectory(thisDirectory)
26+
2127
let errors, exitCode =
2228
compiler.Compile([|
2329
"fsc.dll"
@@ -26,9 +32,12 @@ module AddFSharpType =
2632
"-o"; destination
2733
|])
2834
|> Async.RunSynchronously
35+
36+
Directory.SetCurrentDirectory(currentDirectory)
37+
2938
// TODO: Better error handling
3039
if exitCode > 0 then raise (InvalidOperationException(errors.[0].ToString()))
31-
let assembly = LoadFrom(destination)
40+
let assembly = Assembly.LoadFrom(destination)
3241
assembly
3342

3443
let AddType (typeDefinition : string) =

0 commit comments

Comments
 (0)