How to Build the OfficeCLI C# Project: A Complete Guide for .NET 6

Build the OfficeCLI C# project by restoring NuGet packages with dotnet restore, compiling with dotnet build -c Release, and optionally publishing a self-contained executable via dotnet publish -c Release -r win-x64 --self-contained true.

The OfficeCLI is a .NET 6 console application that provides command-line automation for Microsoft Office documents through COM interop. When you build the OfficeCLI C# project from the iOfficeAI/OfficeCLI repository, you compile a modular architecture—including command builders, document handlers, and a resident server—into a standalone Windows executable.

Prerequisites for Building OfficeCLI

Before compiling the OfficeCLI source code, ensure your environment meets these requirements:

  • .NET 6 SDK or newer is installed on your development machine.
  • Windows operating system with Microsoft Office (Word, Excel, or PowerPoint) installed, as the CLI relies on COM interop bindings that require Office automation services.
  • Git for cloning the repository.

OfficeCLI Architecture and Key Source Files

Understanding the project structure helps diagnose build issues and extension points. The relevant source files in src/officecli/ include:

Step-by-Step Build Instructions

Follow these commands to compile the OfficeCLI C# project from source:

  1. Clone the repository:

    git clone https://github.com/iOfficeAI/OfficeCLI.git
    cd OfficeCLI/src/officecli
  2. Restore dependencies:

    dotnet restore

    This command downloads the NuGet packages specified in officecli.csproj, including Office interop assemblies and logging frameworks.

  3. Compile the project:

    dotnet build -c Release

    The build output appears in bin/Release/net6.0/. For development builds with debug symbols, use -c Debug instead.

  4. Publish a distributable executable (optional):

    dotnet publish -c Release -r win-x64 --self-contained true -o ./publish

    This generates a self-contained binary in the ./publish directory that includes the .NET 6 runtime, eliminating the need for end-users to install the SDK.

Publishing Configuration Options

Choose the appropriate publish configuration based on your distribution requirements:

Scenario Command
Debug build (fast compile with symbols) dotnet build -c Debug
Release build (optimized for performance) dotnet build -c Release
Self-contained Windows x64 dotnet publish -c Release -r win-x64 --self-contained true -o ./dist
Single-file executable dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -o ./dist
Cross-platform binary (limited functionality without Office) dotnet publish -c Release -r linux-x64 --self-contained true -o ./dist

Troubleshooting Common Build Issues

When you build the OfficeCLI C# project, you may encounter these specific errors:

  • COM interop compilation errors: Ensure Microsoft Office is installed and accessible. The project references Office COM types defined in officecli.csproj that require the Office Primary Interop Assemblies (PIAs) available on Windows.

  • Missing runtime identifier errors: If publishing for a specific platform, verify the -r parameter matches a valid RID (Runtime Identifier) such as win-x64, win-x86, or win-arm64 as defined in the project file.

  • Resident server binding failures: During execution (not build), if the resident server fails to start, check that no other OfficeCLI instances are locking the COM objects. The ResidentServer.cs implementation requires exclusive access to Office automation sessions.

Summary

  • OfficeCLI is a .NET 6 CLI tool located in the src/officecli/ directory of the iOfficeAI/OfficeCLI repository.
  • Key source files include officecli.csproj for build configuration, Program.cs for entry-point logic, and CommandBuilder.cs for command routing.
  • Build process: Run dotnet restore followed by dotnet build -c Release to compile.
  • Distribution: Use dotnet publish with --self-contained true and -r win-x64 to create portable executables that include the runtime.
  • Platform limitation: Full functionality requires Windows with Microsoft Office installed due to COM interop dependencies in handlers like WordHandler.cs.

Frequently Asked Questions

What .NET version is required to build OfficeCLI?

OfficeCLI targets .NET 6 according to the officecli.csproj file. You must install the .NET 6 SDK or newer to successfully compile the project. The build will fail with framework compatibility errors if you attempt to use .NET 5 or earlier versions.

Can I build OfficeCLI on Linux or macOS?

You can compile the project on Linux or macOS using dotnet build, but the resulting binary will have limited functionality. The OfficeCLI relies heavily on Windows-specific COM interop bindings—particularly in WordHandler.cs and ResidentServer.cs—that require Microsoft Office to be installed on Windows. Cross-platform builds are suitable only for examining the command structure or running non-Office related utilities like the HTML rendering components.

How do I create a single-file executable for distribution?

Append the -p:PublishSingleFile=true flag to your publish command:

dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -o ./dist

This produces a single officecli.exe file that bundles all dependencies, the .NET runtime, and the application code, simplifying deployment to end-user machines.

Why does my build fail with Office interop errors?

Build failures related to Office interop typically indicate missing Primary Interop Assemblies (PIAs). Ensure Microsoft Office is installed on the build machine, as the project references Office type libraries during compilation. If building on a machine without Office (such as a CI/CD server), you must install the Office PIAs or build with conditional compilation symbols to exclude COM-dependent handlers.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →