Clojure.MSBuild
0.0.7
See the version list below for details.
dotnet add package Clojure.MSBuild --version 0.0.7
NuGet\Install-Package Clojure.MSBuild -Version 0.0.7
<PackageReference Include="Clojure.MSBuild" Version="0.0.7"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Clojure.MSBuild" Version="0.0.7" />
<PackageReference Include="Clojure.MSBuild"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Clojure.MSBuild --version 0.0.7
#r "nuget: Clojure.MSBuild, 0.0.7"
#:package Clojure.MSBuild@0.0.7
#addin nuget:?package=Clojure.MSBuild&version=0.0.7
#tool nuget:?package=Clojure.MSBuild&version=0.0.7
Clojure.MSBuild
MSBuild integration for ClojureCLR. Build, test, and run Clojure on .NET with standard dotnet commands.
No non-dotnet tools needed.
dotnet build AOT-compiles your namespaces and produces a standalone assembly whose entry point is a
gen-class Main calling your -main. No C# in your project, no .cljr files needed at runtime.
Requirements
- .NET 11.0 SDK, 11.0.100-rc.1 or later
- Clojure CLR 1.12.6 or later
Quick Start
1. Create a project
dotnet new console -n MyApp
cd MyApp
rm Program.cs
The project must not contain C# sources: dotnet build replaces the project assembly with the
compiled Clojure entry point (see How the build works).
2. Add packages
dotnet add package Clojure.MSBuild
dotnet add package Clojure --version 1.12.6
3. Update your .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net11.0</TargetFramework>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<ClojureMainNamespace>app</ClojureMainNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Clojure.MSBuild" Version="0.0.7" />
<PackageReference Include="Clojure" Version="1.12.6" />
</ItemGroup>
<ItemGroup>
<Content Include="src/**/*.cljr" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
4. Write your app
Create src/app.cljr:
(ns app)
(defn -main [& args]
(println "Hello from ClojureCLR!"))
5. Build and run it
dotnet build
dotnet run
dotnet build compiles app (and every namespace it requires) to .dll files next to
MyApp.dll, and MyApp.dll itself is the compiled entry point: a class named after the
assembly with a static Main generated by gen-class that calls app/-main.
dotnet MyApp.dll, ./MyApp and dotnet publish all use it.
How the build works
- The SDK compiles a small generated C# host into
MyApp.dll. - After
Build, theClojureBuildtarget runs that host to AOT-compileclojure.msbuild.entry(generated, contains(:gen-class :name MyApp :main true)), your main namespace, its dependencies andClojureNamespacesToCompile. - The compiled
*.cljr.dllfiles are copied to the output directory and the compiled entry point replacesMyApp.dll.
Because the project assembly is replaced, the project cannot contain C# sources of its own.
Put C# in a class library and reference it, or set ClojureEntryPoint to csharp to keep a
generated C# Main as the entry point (Clojure is still AOT-compiled). Either way
--clj-mode tooling (REPL, nREPL, tests, scripts) is handled by the same entry point.
Clojure Git Dependencies
Add Clojure libraries from git directly in your .csproj — no deps.edn needed:
<ItemGroup>
<PackageReference Include="Clojure" Version="1.12.6" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="11.0.0-rc.1.26425.128" />
<ClojureGitDep Include="io.github.clojure/clr.data.json" Tag="v2.5.1" Sha="f84cb88" />
<ClojureGitDep Include="com.github.seancorfield/honeysql" Tag="v2.7.1368" Sha="b8332fc" />
</ItemGroup>
Repos are cloned to ~/.gitlibs (cached, compatible with cljr) when the build and tooling run;
the compiled application contains the dependency namespaces and does not need git at runtime. Supports io.github, com.github, io.gitlab, and ht.sr prefixes for auto URL resolution. You can also specify a full URL:
<ClojureGitDep Include="my/lib" Tag="v1.0" Sha="abc123" Url="https://example.com/repo.git" />
A deps.edn file is also supported if you prefer the Clojure convention. Both sources merge.
Testing
Add the test adapter package:
dotnet add package Clojure.MSBuild.TestAdapter
dotnet add package Microsoft.NET.Test.Sdk
Add test content to your .csproj:
<Content Include="test/**/*.cljr" CopyToOutputDirectory="PreserveNewest" />
Create test files with the _test.cljr suffix in a test/ directory:
(ns app-test
(:require [clojure.test :refer [deftest is testing]]))
(deftest test-addition
(testing "math works"
(is (= 4 (+ 2 2)))))
Run tests:
dotnet test
REPL
dotnet msbuild /t:clj-repl
nREPL
dotnet add package clojure.tools.nrepl --prerelease
dotnet msbuild /t:clj-nrepl
Connects on port 1667. Use Calva, CIDER, or any nREPL client.
Run a Script
dotnet msbuild /t:clj-run -p:File=path/to/script.clj
AOT Compilation
The main namespace and everything it requires are compiled on every build. To compile
additional namespaces (for example ones with their own gen-class), list them:
<PropertyGroup>
<ClojureNamespacesToCompile>my.lib;my.utils</ClojureNamespacesToCompile>
</PropertyGroup>
Note: (t/await (f ...)) on a call to a Clojure ^:async function needs the call's static
Task<T> type. Tag the call site, or attach the tag to the var:
(alter-meta! #'execute! assoc :tag (symbol "System.Threading.Tasks.Task`1[System.Object]"))
Configuration
| Property | Description | Default |
|---|---|---|
ClojureMainNamespace |
Namespace with -main function |
(required) |
ClojureEntryPoint |
gen-class (compiled entry point replaces the project assembly) or csharp (generated C# Main, allows C# sources in the project) |
gen-class |
ClojureSourceDir |
Source directory | src |
ClojureExtraSourceDirs |
Additional source dirs (pipe-separated) | |
ClojureNamespacesToCompile |
Additional namespaces to compile (semicolon-separated) |
Examples
examples/minimal-api— ASP.NET web API with HoneySQL, async ADO.NET, integration testsexamples/csharp-interop— Bidirectional C#/Clojure interop in one project (ClojureEntryPoint=csharp)
License
MIT
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.