Skip to content

MSBuild Reference

NSmithy.MSBuild runs before C# compilation and drives the Smithy → C# code generation pipeline. It invokes the smithy CLI, which runs the csharp-codegen Java plugin to emit .g.cs files, then registers those files with the .NET toolchain.

PropertyDefaultDescription
SmithyServiceSmithy shape ID of the service to generate (e.g. example.hello#HelloService). Required when synthesizing a smithy-build.json from a contracts reference.
SmithyBaseNamespaceRestricts generated C# types to shapes whose Smithy namespace starts with this value. Leave empty to emit all shapes.
SmithyGenerateServertrueEmit server stub types. Set to false in client-only projects.
SmithyGenerateClienttrueEmit client types. Set to false in server-only projects.
SmithyBuildFile$(MSBuildProjectDirectory)/smithy-build.jsonPath to the Smithy build configuration file. When absent and SmithySource items are present, NSmithy synthesizes one under obj/.
SmithyProjectionsourceSmithy build projection to use.
SmithyPlugincsharp-codegenSmithy build plugin name.
SmithyBuildOutputPath$(IntermediateOutputPath)Smithy/Root directory for all Smithy build output.
SmithyStampFile$(SmithyBuildOutputPath)NSmithy.Generated.stampIncremental build stamp file. Smithy codegen is skipped when inputs have not changed since this file was last written.
SmithyEmitGeneratedFilesfalseShow generated .g.cs files in IDE project views when true.
SmithyCliPathsmithySmithy CLI executable. Resolved from PATH by default.
PropertyDefaultDescription
SmithyGrpcServicesBothPassed as GrpcServices to Grpc.Tools when .proto files are generated. Valid values: Both, Client, Server, None.
PropertyDefaultDescription
SmithyPublishfalsePack .smithy model files into the NuGet package and (when SmithyMavenGroupId is set) produce a Maven JAR on dotnet pack.
SmithySources$(MSBuildProjectDirectory)/modelDirectory containing the .smithy source files to publish.
SmithyMavenGroupIdMaven groupId for the emitted JAR (e.g. io.github.acme). When set, dotnet pack produces a JAR alongside the .nupkg.
SmithyMavenArtifactIdMaven artifactId for the emitted JAR (e.g. my-service-contracts). Required when SmithyMavenGroupId is set.
ItemDescription
SmithySource.smithy files to include in the synthesized smithy-build.json. Populated automatically from a ProjectReference to a project with SmithyPublish=true, or added manually for advanced cases.
SmithyMavenDependencyMaven coordinates of Smithy model JARs needed by the Smithy CLI (e.g. com.disneystreaming.alloy:alloy-core:0.3.38). These are written into the synthesized smithy-build.json and, in publishing projects, into the NuGet package for downstream consumers.

A single project can consume Smithy models from multiple sources simultaneously. SmithySource items and SmithyMavenDependency items are additive — NSmithy collects them all and writes a single synthesized smithy-build.json:

<!-- Model files from a contracts project in the same repo -->
<ProjectReference Include="../ServiceA.Contracts/ServiceA.Contracts.csproj" />
<!-- Model JAR from a Maven registry -->
<SmithyMavenDependency Include="io.github.acme:service-b-contracts:1.0.0" />

ProjectReference items are the recommended way to consume contracts within a solution. SmithyMavenDependency covers external dependencies — whether published by a team using NSmithy or any other Smithy toolchain.

NSmithy bundles the Smithy CLI (version 1.68.0) inside NSmithy.MSBuild and selects the correct platform binary automatically. No separate installation is required. The bundle is self-contained and includes a JRE, so Java does not need to be installed either.

Set SmithyCliPath to override the bundled binary with a specific executable, for example when testing against a different CLI version: