# How to Build OfficeCLI from Source Using the .NET 10 SDK

> Learn to build OfficeCLI from source with the .NET 10 SDK. Clone the repository and run dotnet publish for a self-contained executable. Get OfficeCLI running easily.

- Repository: [OfficeAI/OfficeCLI](https://github.com/iofficeai/OfficeCLI)
- Tags: how-to-guide
- Published: 2026-07-31

---

**Build OfficeCLI by cloning the repository and running `dotnet publish` with the Release configuration and your target runtime identifier to produce a single-file, self-contained executable.**

OfficeCLI is a cross-platform command-line tool for automating Microsoft Office documents. Because the project targets **.NET 10** (`net10.0`) and publishes as a trimmed, single-file binary, you can compile it from source on any platform that supports the .NET 10 SDK. This guide walks through the exact build steps derived from the project's configuration in `officecli.csproj`.

## Prerequisites

Before building, ensure you have the .NET 10 SDK installed. The SDK includes the `dotnet` CLI tool used for compilation and publishing.

- **Windows**: Download the installer from the .NET website or use `winget install Microsoft.DotNet.SDK.10`
- **macOS**: Use Homebrew (`brew install dotnet`) or download the PKG installer
- **Linux**: Follow the distribution-specific instructions from Microsoft (e.g., `apt install dotnet-sdk-10.0` on Ubuntu)

Verify your installation:

```bash
dotnet --version

```

## Understanding the Build Configuration

The build behavior is controlled by properties defined in [`src/officecli/officecli.csproj`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/officecli.csproj). Key settings include:

- **`<TargetFramework>net10.0</TargetFramework>`** – Compiles against .NET 10 APIs
- **`<PublishSingleFile>true</PublishSingleFile>`** – Bundles the application into one executable
- **`<SelfContained>true</SelfContained>`** – Includes the .NET runtime in the output
- **`<PublishTrimmed>true</PublishTrimmed>`** – Removes unused assemblies to reduce file size
- **`<CETCompat>false</CETCompat>`** – Disables Control-flow Enforcement Technology for single-file compatibility

The project references two critical NuGet packages declared in the same file:
- `DocumentFormat.OpenXml` for OOXML manipulation
- `System.CommandLine` for parsing CLI arguments (used in [[`Program.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/Program.cs)](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Program.cs))

## Step-by-Step Build Instructions

### 1. Clone the Repository

Download the source code to your local machine:

```bash
git clone https://github.com/iOfficeAI/OfficeCLI.git
cd OfficeCLI

```

### 2. Restore NuGet Packages

While `dotnet publish` handles restoration automatically, you can explicitly restore dependencies first:

```bash
dotnet restore src/officecli/officecli.csproj

```

### 3. Publish the Binary

Run the publish command with your target runtime identifier (RID). Common RIDs include `win-x64`, `linux-x64`, or `osx-arm64`.

```bash
dotnet publish src/officecli/officecli.csproj \
    -c Release \
    -r win-x64 \
    --self-contained true \
    -p:PublishSingleFile=true \
    -p:PublishTrimmed=true \
    -o ./publish

```

**Parameters explained:**
- `-c Release` – Optimizes the build for production
- `-r win-x64` – Specifies the target platform (adjust for your OS)
- `--self-contained true` – Bundles the .NET runtime
- `-p:PublishSingleFile=true` – Creates a single executable file
- `-p:PublishTrimmed=true` – Strips unused code
- `-o ./publish` – Places output in the `publish` directory

After completion, find your executable at:
- **Windows**: `./publish/officecli.exe`
- **Linux/macOS**: `./publish/officecli`

### 4. Verify the Build

Test the compiled binary by checking the help output:

```bash
./publish/officecli --help

```

You should see the command list defined in the `CommandBuilder` classes (see [[`CommandBuilder.Help.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/CommandBuilder.Help.cs)](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/CommandBuilder.Help.cs)).

## Optional System-Wide Installation

To install OfficeCLI globally, copy the built binary to a directory in your system `PATH`. The repository includes [[`install.sh`](https://github.com/iOfficeAI/OfficeCLI/blob/main/install.sh)](https://github.com/iOfficeAI/OfficeCLI/blob/main/install.sh) as a reference implementation:

```bash
sudo cp ./publish/officecli /usr/local/bin/

```

On Windows, add the `publish` directory to your system environment variables or move `officecli.exe` to a location already in your `PATH`.

## Key Source Files Reference

Understanding these files helps when modifying or debugging the build:

| File | Purpose | Link |
|------|---------|------|
| `src/officecli/officecli.csproj` | MSBuild project file with target framework and publish settings | [View source](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/officecli.csproj) |
| [`src/officecli/Program.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Program.cs) | Application entry point and command routing | [View source](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Program.cs) |
| [`src/officecli/CommandBuilder.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/CommandBuilder.cs) | Defines CLI verbs and argument parsing | [View source](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/CommandBuilder.cs) |
| [`src/officecli/BlankDocCreator.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/BlankDocCreator.cs) | Handles the `create` command implementation | [View source](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/BlankDocCreator.cs) |
| [`src/officecli/Core/SkillInstaller.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Core/SkillInstaller.cs) | Manages embedded skill installation | [View source](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Core/SkillInstaller.cs) |
| [`src/officecli/Core/Watch/WatchServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Core/Watch/WatchServer.cs) | Implements the resident file-watching server | [View source](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Core/Watch/WatchServer.cs) |
| [`install.sh`](https://github.com/iOfficeAI/OfficeCLI/blob/main/install.sh) | Bash script for system-wide binary installation | [View source](https://github.com/iOfficeAI/OfficeCLI/blob/main/install.sh) |

## Summary

- OfficeCLI targets **.NET 10** (`net10.0`) and requires the corresponding SDK
- The project is pre-configured for **single-file, self-contained, trimmed** publishing via `officecli.csproj`
- Use `dotnet publish -c Release -r <RID> --self-contained true` to build platform-specific executables
- The output is a standalone binary that requires no external .NET runtime installation
- Reference [[`install.sh`](https://github.com/iOfficeAI/OfficeCLI/blob/main/install.sh)](https://github.com/iOfficeAI/OfficeCLI/blob/main/install.sh) for deployment automation

## Frequently Asked Questions

### What version of the .NET SDK do I need to build OfficeCLI?

You need the **.NET 10 SDK** or later. The project file explicitly specifies `<TargetFramework>net10.0</TargetFramework>`, which requires a SDK that supports .NET 10. You can check your installed version by running `dotnet --version` in your terminal.

### Can I build OfficeCLI as a framework-dependent deployment instead of self-contained?

Yes. While the default configuration sets `<SelfContained>true</SelfContained>`, you can override this by passing `--self-contained false` to the `dotnet publish` command. This produces a smaller binary that requires the .NET 10 runtime to be pre-installed on the target machine.

### Why does the build produce a single file?

The [`officecli.csproj`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/officecli.csproj) file sets `<PublishSingleFile>true</PublishSingleFile>` to simplify distribution. This bundles all dependencies, including the `DocumentFormat.OpenXml` and `System.CommandLine` libraries, into one executable without external DLLs.

### Where is the application entry point located?

The entry point is in [[`src/officecli/Program.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Program.cs)](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Program.cs). This file configures global settings like UTF-8 encoding and culture, initializes the `RootCommand` via `CommandBuilder`, and dispatches execution to the appropriate handlers such as `BlankDocCreator` or `SkillInstaller`.