Skip to content

Commit

Permalink
Make packaging code shipshape.
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Nov 18, 2024
1 parent 7f9b53d commit 32cd8bb
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
<PackageVersion Include="Fake.DotNet.MsBuild" Version="$(FakeVersion)" />
<PackageVersion Include="Fake.Api.GitHub" Version="$(FakeVersion)" />
</ItemGroup>
</Project>
</Project>
8 changes: 8 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
14 changes: 12 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project ToolsVersion="15.0">
<Project>
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -13,5 +13,15 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageDescription>MSBuild evaluation, fsproj file loading, and project system for F# tooling</PackageDescription>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReadmeFile Condition="Exists('$(MSBuildProjectDirectory)/README.md')">README.md</PackageReadmeFile>
</PropertyGroup>
</Project>

<ItemGroup>
<PackageReference Include="Dotnet.ReproducibleBuilds" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="Ionide.KeepAChangelog.Tasks" ExcludeAssets="runtime" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<None Include="$(MSBuildProjectDirectory)/README.md" Condition="Exists('$(MSBuildProjectDirectory)/README.md')" Pack="true" PackagePath="./README.md" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions src/Ionide.ProjInfo.FCS/Ionide.ProjInfo.FCS.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
<ItemGroup>
<ProjectReference Include="..\Ionide.ProjInfo\Ionide.ProjInfo.fsproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dotnet.ReproducibleBuilds" PrivateAssets="All" />
<PackageReference Include="Ionide.KeepAChangelog.Tasks" PrivateAssets="All" />
<PackageReference Include="FSharp.Core" VersionOverride="$(FSharpCoreCompilerVersion)" />
<PackageReference Include="FSharp.Compiler.Service" />
</ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/Ionide.ProjInfo.FCS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ionide.ProjInfo.FCS

This is a helper library that provides APIs to map Ionide.ProjInfo.Types.ProjectOptions instances to FSharp.Compiler.CodeAnalysis.FSharpProjectOptions instances.

Assuming you've already done the steps in Ionide.ProjInfo to get the ProjectOptions instances, you can use the following code to get the FSharpProjectOptions for those instances efficiently

```fsharp
open Ionide.ProjInfo
let fcsProjectOptions = FCS.mapManyOptions projectOptions
```
12 changes: 12 additions & 0 deletions src/Ionide.ProjInfo.ProjectSystem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ionide.ProjInfo.ProjectSystem

This library provides helpers for operating an entire project system based on the data structures returned by the Ionide.ProjInfo library.

The main entrypoint is the `ProjectController` API in the Ionide.ProjInfo.ProjectSystem workspace:

```fsharp
type ProjectController(toolsPath: ToolsPath, workspaceLoaderFactory: ToolsPath -> IWorkspaceLoader) =
...
```

From there you can load specific projects, get their dependencies, and more.
10 changes: 1 addition & 9 deletions src/Ionide.ProjInfo.Sln/Ionide.ProjInfo.Sln.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,4 @@
<DefineConstants>FULL_SLN_PARSER;STANDALONEBUILD;$(DefineConstants)</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>

<PackageReference Include="Dotnet.ReproducibleBuilds" PrivateAssets="All" />
<PackageReference Include="Ionide.KeepAChangelog.Tasks" PrivateAssets="All" />

</ItemGroup>

</Project>
</Project>
6 changes: 2 additions & 4 deletions src/Ionide.ProjInfo.Tool/Ionide.ProjInfo.Tool.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dotnet.ReproducibleBuilds" PrivateAssets="All" />
<PackageReference Include="Ionide.KeepAChangelog.Tasks" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Framework" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build" IncludeAssets="compile" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" IncludeAssets="compile" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="Argu" />
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions src/Ionide.ProjInfo.Tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Ionide.ProjInfo.Tool

A .NET SDK tool that allows for quick parsing of projects and solutions.

Broadly, the tool has three kinds of arguments:


### Loading args

```
--project <PATH> the path to a project file to load
--solution <PATH> the path to a solution file to load
```

### How to load a project

By default you will use the standard MSBuild loader, but specifying `--graph` will use the MSBuild graph loader.

### What to parse the results into

By default you will get a structured text version of the Ionide project options for the project(s). If you want, you can get the FCS ProjectOptions versions by adding the `--fcs` flag. Finally, you can get project JSON with `--serialize` as well.
6 changes: 2 additions & 4 deletions src/Ionide.ProjInfo/Ionide.ProjInfo.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dotnet.ReproducibleBuilds" PrivateAssets="All" />
<PackageReference Include="Ionide.KeepAChangelog.Tasks" PrivateAssets="All" />
<PackageReference Include="FSharp.Core" />
<PackageReference Include="SemanticVersioning" />
<PackageReference Include="Microsoft.Build" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Framework" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build" IncludeAssets="compile" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" IncludeAssets="compile" ExcludeAssets="runtime" PrivateAssets="all" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Ionide.ProjInfo/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module SdkDiscovery =
Path: DirectoryInfo
}

/// Given the DOTNET_sROOT, that is the directory where the `dotnet` binary is present and the sdk/runtimes/etc are,
/// Given the DOTNET_ROOT, that is the directory where the `dotnet` binary is present and the sdk/runtimes/etc are,
/// enumerates the available SDKs in descending version order
let sdks (dotnetBinaryPath: FileInfo) : DotnetSdkInfo[] =
execDotnet true dotnetBinaryPath.Directory dotnetBinaryPath [ "--list-sdks" ]
Expand Down
38 changes: 38 additions & 0 deletions src/Ionide.ProjInfo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Ionide.Proj-Info

This project loads some MSBuild specific assemblies at runtime so that you can use an existing MSBuild installation instead of (incorrectly) bundling it yourself. Somewhat similar to how [MSBuildLocator](https://github.com/microsoft/MSBuildLocator) loads the correct assemblies.
Because of this you need to add a direct dependency on `Microsoft.Build.Framework` and `NuGet.Frameworks` but keep excluded them at runtime.

```
<PackageReference Include="Microsoft.Build.Framework" Version="17.2.0" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="NuGet.Frameworks" Version="6.2.1" ExcludeAssets="runtime" PrivateAssets="all" />
<PackageReference Include="Ionide.ProjInfo" Version="some_version" />
```

Next, you first need to initialize the MsBuild integration.

```fsharp
open Ionide.ProjInfo
let projectDirectory: DirectoryInfo = yourProjectOrSolutionFolder
let toolsPath = Init.init projectDirectory None
```

With the `toolsPath` you can create a `loader`

```fsharp
let defaultLoader: IWorkspaceLoader = WorkspaceLoader.Create(toolsPath, [])
// or
let graphLoader: IWorkspaceLoader = WorkspaceLoaderViaProjectGraph.Create(toolsPath, [])
```

Using the `IWorkspaceLoader` you can load projects or solutions.
Events are being emitted while projects/solutions are loaded.
You typically want to subscribe to this before you load anything.

```fsharp
let subscription: System.IDisposable = defaultLoader.Notifications.Subscribe(fun msg -> printfn "%A" msg)
let projectOptions = loader.LoadProjects([ yourFsProjPath ]) |> Seq.toArray
```

From here consider using Ionide.ProjInfo.FCS to map the `projectOptions` to F# Compiler `ProjectOptions`, or use the `projectOptions` directly to get information about the project.
8 changes: 4 additions & 4 deletions test/Ionide.ProjInfo.Tests/Ionide.ProjInfo.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<PackageReference Include="YoloDev.Expecto.TestSdk" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="GitHubActionsTestLogger" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Tasks.Core" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" IncludeAssets="compile" />
<PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="runtime" IncludeAssets="compile" />
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime" IncludeAssets="compile" />
<PackageReference Include="Microsoft.Build.Tasks.Core" ExcludeAssets="runtime" IncludeAssets="compile" />
</ItemGroup>
</Project>

0 comments on commit 32cd8bb

Please sign in to comment.