Skip to content

Commit d8b16c7

Browse files
fix: Support libraries using TargetFrameworks property (#12)
Co-authored-by: Maxime Mangel <me@mangelmaxime.fr>
1 parent 039f8a3 commit d8b16c7

14 files changed

+145
-65
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ bin/
1010
.DS_Store
1111
node_modules/
1212
demo/dist/
13+
14+
# Don't track this file because we dynamically install packages for it during the build process
15+
tests/fixtures/valid/library-with-files-multi-tfm/packages.lock.json
16+
tests/temp/

Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55
<ItemGroup>
6+
<PackageVersion Include="BlackFox.CommandLine" Version="1.0.0" />
67
<PackageVersion Include="EasyBuild.FileSystemProvider" Version="0.3.0" />
78
<PackageVersion Include="EasyBuild.PackageReleaseNotes.Tasks" Version="1.2.0">
89
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Fable.Package.SDK.fsproj

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
Include="build\*"
1717
Pack="true"
1818
PackagePath="build\" />
19+
<!-- Support libraries using TargetFrameworks https://github.com/dotnet/msbuild/issues/1860 -->
20+
<Content
21+
Include="build\*"
22+
Pack="true"
23+
PackagePath="buildCrossTargeting\" />
1924
</ItemGroup>
2025
<!-- Disable dependency on FSharp.Core -->
2126
<ItemGroup>

tests/Fable.Package.SDK.Tests.fsproj

+2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net8.0</TargetFramework>
6+
<IsTestProject>true</IsTestProject>
67
</PropertyGroup>
78
<ItemGroup>
89
<Compile Include="Workspace.fs" />
910
<Compile Include="Main.fs" />
1011
</ItemGroup>
1112
<ItemGroup>
13+
<PackageReference Include="BlackFox.CommandLine" />
1214
<PackageReference Include="EasyBuild.FileSystemProvider" />
1315
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1416
<PackageReference Include="NUnit" />

tests/Main.fs

+78-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ open SimpleExec
55
open NUnit.Framework
66
open System.IO
77
open System.IO.Compression
8+
open BlackFox.CommandLine
9+
open System
810

911
let private expectToFailWithMessage projectName (message: string) =
1012
task {
@@ -42,6 +44,13 @@ let ``Missing FableTarget property should report an error`` () =
4244
Workspace.fixtures.invalid.``MissingFableTarget.fsproj``
4345
"You need to set at least one of Fable target via the PackageTags property. Possible values are: fable-dart, fable-dotnet, fable-javascript, fable-python, fable-rust, fable-all."
4446

47+
// Test disabled because it freeze on Github
48+
// [<Test>]
49+
// let ``Missing FableTarget property should report an error - MultiTFM`` () =
50+
// expectToFailWithMessage
51+
// Workspace.fixtures.invalid.``MissingFableTargetMultiTFM.fsproj``
52+
// "You need to set at least one of Fable target via the PackageTags property. Possible values are: fable-dart, fable-dotnet, fable-javascript, fable-python, fable-rust, fable-all."
53+
4554
[<Test>]
4655
let ``You cannot set both FablePackageType and FableTarget properties`` () =
4756
task {
@@ -237,20 +246,78 @@ let ``should include the source file and the project file under 'fable' folder``
237246
$"pack %s{Workspace.fixtures.valid.``library-with-files``.``MyLibrary.fsproj``}"
238247
)
239248

240-
let archive = ZipFile.OpenRead(VirtualWorkspace.fixtures.valid.``library-with-files``.bin.Release.``MyLibrary.1.0.0.nupkg``)
249+
let archive =
250+
ZipFile.OpenRead(
251+
VirtualWorkspace.fixtures.valid.``library-with-files``.bin.Release.``MyLibrary.1.0.0.nupkg``
252+
)
241253

242-
let entries =
243-
archive.Entries
244-
|> Seq.map (fun entry -> entry.FullName)
245-
|> Seq.toList
254+
let entries = archive.Entries |> Seq.map (fun entry -> entry.FullName) |> Seq.toList
246255

247-
Assert.That(
248-
entries,
249-
Contains.Item("fable/Entry.fs")
256+
Assert.That(entries, Contains.Item("fable/Entry.fs"))
257+
258+
Assert.That(entries, Contains.Item("fable/MyLibrary.fsproj"))
259+
}
260+
261+
[<Test>]
262+
let ``should include the source file and the project file under 'fable' folder - MultiTFM`` () =
263+
task {
264+
// Make sure we work with a fresh nupkg file
265+
let fileInfo =
266+
VirtualWorkspace.fixtures.valid.``library-with-files-multi-tfm``.bin.Release.``MyLibraryMultiTFM.1.0.0.nupkg``
267+
|> FileInfo
268+
269+
if fileInfo.Exists then
270+
fileInfo.Delete()
271+
272+
// When testing against multi Target Framework we need to use a "real package"
273+
// because using the standard "Import" trick is not enough to capture errors
274+
let tempPackageFolder = VirtualWorkspace.temp.``.`` |> FileInfo
275+
276+
if tempPackageFolder.Exists then
277+
tempPackageFolder.Delete()
278+
279+
let tempVersion = "9.999.0-local-build-" + DateTime.Now.ToString("yyyyMMdd-HHmmss")
280+
281+
Command.Run(
282+
"dotnet",
283+
CmdLine.empty
284+
|> CmdLine.append "pack"
285+
|> CmdLine.append Workspace.``..``.src.``.``
286+
|> CmdLine.appendPrefix "-o" tempPackageFolder.FullName
287+
|> CmdLine.append $"/p:PackageVersion=%s{tempVersion}"
288+
|> CmdLine.toString
250289
)
251290

252-
Assert.That(
253-
entries,
254-
Contains.Item("fable/MyLibrary.fsproj")
291+
Command.Run(
292+
"dotnet",
293+
CmdLine.empty
294+
|> CmdLine.append "add"
295+
|> CmdLine.appendPrefix "package" "Fable.Package.SDK"
296+
|> CmdLine.appendPrefix "--version" tempVersion
297+
|> CmdLine.appendPrefix "--source" tempPackageFolder.FullName
298+
|> CmdLine.toString,
299+
workingDirectory = Workspace.fixtures.valid.``library-with-files-multi-tfm``.``.``
300+
)
301+
302+
Command.Run(
303+
"dotnet",
304+
$"pack %s{Workspace.fixtures.valid.``library-with-files-multi-tfm``.``MyLibraryMultiTFM.fsproj``}"
255305
)
306+
307+
// Restore modified file to avoid polluting the Git history
308+
Command.Run(
309+
"git",
310+
$"restore %s{Workspace.fixtures.valid.``library-with-files-multi-tfm``.``MyLibraryMultiTFM.fsproj``}"
311+
)
312+
313+
let archive =
314+
ZipFile.OpenRead(
315+
VirtualWorkspace.fixtures.valid.``library-with-files-multi-tfm``.bin.Release.``MyLibraryMultiTFM.1.0.0.nupkg``
316+
)
317+
318+
let entries = archive.Entries |> Seq.map (fun entry -> entry.FullName) |> Seq.toList
319+
320+
Assert.That(entries, Contains.Item("fable/Entry.fs"))
321+
322+
Assert.That(entries, Contains.Item("fable/MyLibraryMultiTFM.fsproj"))
256323
}

tests/Workspace.fs

+5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ type Workspace = RelativeFileSystem<".">
77

88
type VirtualWorkspace = VirtualFileSystem<".",
99
"""
10+
temp/
1011
fixtures/
1112
valid/
1213
library-with-files/
1314
bin/
1415
Release/
1516
MyLibrary.1.0.0.nupkg
17+
library-with-files-multi-tfm/
18+
bin/
19+
Release/
20+
MyLibraryMultiTFM.1.0.0.nupkg
1621
""">

tests/fixtures/Directory.Build.props

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
<!-- Disable lock files for tests projects -->
3+
<PropertyGroup>
4+
<RestorePackagesWithLockFile>false</RestorePackagesWithLockFile>
5+
<RestoreLockedMode>false</RestoreLockedMode>
6+
</PropertyGroup>
7+
</Project>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<!-- Disable central package version of tests projects -->
3+
<PropertyGroup>
4+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
5+
</PropertyGroup>
6+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
5+
<FablePackageType>binding</FablePackageType>
6+
</PropertyGroup>
7+
<Import Project="./../Fable.Package.SDK.Imports.props" />
8+
</Project>

tests/fixtures/invalid/packages.lock.json

-27
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module MyLibrary
2+
3+
let answer = 42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
5+
<FablePackageType>library</FablePackageType>
6+
<PackageTags>fable-javascript</PackageTags>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="Entry.fs" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Fable.Package.SDK">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
</ItemGroup>
17+
</Project>

tests/fixtures/valid/library-with-files/packages.lock.json

-27
This file was deleted.

tests/packages.lock.json

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
"version": 2,
33
"dependencies": {
44
"net8.0": {
5+
"BlackFox.CommandLine": {
6+
"type": "Direct",
7+
"requested": "[1.0.0, )",
8+
"resolved": "1.0.0",
9+
"contentHash": "dSW7uLetl021HQXKcZd1xrXPjhsXgaJ5U4tFe64DLja1KZ2Ce6QeugHvZDvLfcPkEc1ZPRF7fWv5/T+X3ThWTA==",
10+
"dependencies": {
11+
"FSharp.Core": "4.2.3"
12+
}
13+
},
514
"EasyBuild.FileSystemProvider": {
615
"type": "Direct",
716
"requested": "[0.3.0, )",

0 commit comments

Comments
 (0)