Distributing contracts
Distributing your Smithy model lets other projects consume the contract without copying model files. NSmithy supports two packaging paths:
- Maven JAR: any Smithy-based toolchain (Java, TypeScript, Python, .NET, and others) can consume it from a Maven registry. This is the more portable option.
- NuGet package: contains model files and their Smithy build configuration. Consumers currently need explicit MSBuild items to import them.
Within a solution
Section titled “Within a solution”Reference a contracts project with SmithyPublish=true:
<ItemGroup> <ProjectReference Include="../MyService.Contracts/MyService.Contracts.csproj" /></ItemGroup>Set SmithyService in the consumer to select its service. Without an explicit
smithy-build.json, NSmithy assembles the referenced sources automatically.
Maven JAR distribution
Section titled “Maven JAR distribution”-
Configure. Add
SmithyMavenGroupIdandSmithyMavenArtifactIdto the contracts project:MyService.Contracts/MyService.Contracts.csproj <PropertyGroup><SmithyPublish>true</SmithyPublish><SmithyMavenGroupId>io.github.acme</SmithyMavenGroupId><SmithyMavenArtifactId>my-service-contracts</SmithyMavenArtifactId></PropertyGroup>Version(orVersionPrefix/VersionSuffix) is reused as the Maven version. -
Pack.
dotnet pack MyService.Contracts --configuration ReleaseThe output directory contains the NuGet package and the Maven JAR, POM, and checksum files. The JAR contains the model in Smithy’s discovery layout.
-
Install locally (optional). To make the JAR available to local Smithy CLI builds during development:
mvn install:install-file \-Dfile=MyService.Contracts/bin/Release/my-service-contracts-1.0.0.jar \-DpomFile=MyService.Contracts/bin/Release/my-service-contracts-1.0.0.pom \-Dpackaging=jar -
Publish to a registry. Use the
dotnet-nsmithy pushtool to upload to a Maven registry that accepts HTTP PUT, such as GitHub Packages, Artifactory, or Nexus:dotnet tool install -g dotnet-nsmithydotnet nsmithy push MyService.Contracts/bin/Release \--project MyService.Contracts/MyService.Contracts.csproj \--registry https://maven.pkg.github.com/ORG/REPO \--username $GITHUB_ACTOR \--token $GITHUB_TOKENpushreads the Maven coordinates and version from the.csprojautomatically. Credentials can also be supplied viaMAVEN_USERNAME/MAVEN_TOKENenvironment variables. -
Consume. The client template defaults to Maven distribution:
dotnet new nsmithy-client -n MyService.ClientReplace the placeholder contracts coordinate in its
smithy-build.jsonwithio.github.acme:my-service-contracts:1.0.0. Configuremaven.repositoriesin that file for a private registry. Other Smithy toolchains consume the same coordinate through their Maven dependency configuration.
NuGet distribution
Section titled “NuGet distribution”-
Pack.
dotnet pack MyService.Contracts --configuration ReleaseWith
SmithyPublish=true, the package containsbuild/smithy/model sources andbuild/smithy-build.json. Publish the.nupkgto your NuGet feed. -
Consume. Request the package’s resolved path and supply both the model sources and packaged build configuration:
MyService.Client/MyService.Client.csproj <PropertyGroup><SmithyService>example.hello#HelloService</SmithyService></PropertyGroup><ItemGroup><PackageReference Include="NSmithy.MSBuild" Version="0.14.0" PrivateAssets="all" /><PackageReference Include="NSmithy.SmithyCli" Version="1.73.0" /><PackageReference Include="MyService.Contracts" Version="1.0.0" GeneratePathProperty="true" /><SmithySource Include="$(PkgMyService_Contracts)/build/smithy/**/*.smithy" /><SmithyContractsBuildFile Include="$(PkgMyService_Contracts)/build/smithy-build.json" /></ItemGroup>NuGet replaces dots with underscores in the generated package-path property. Adjust
PkgMyService_Contractswhen using a different package ID.
Keep the runtime packages required by the generated client or server. NSmithy
merges the contract’s build file into the effective smithy-build.json under
obj/, invokes smithy build, and adds the generated .g.cs files to
compilation.