Skip to content

umbraco/Umbraco.JsonSchema.Extensions

Repository files navigation

Umbraco.JsonSchema.Extensions

Extensions for Umbraco to add JSON schema references and update JSON properties using MSBuild tasks.

JsonSchemaAddReferences

Adds references to a JSON schema file.

<Target Name="AddJsonSchemaReferences" BeforeTargets="Build">
  <ItemGroup>
    <_References Include="https://json.schemastore.org/appsettings.json" />
    <_References Include="appsettings-schema.Umbraco.Cms.json#" />
  </ItemGroup>
  <JsonSchemaAddReferences JsonSchemaFile="$(MSBuildProjectDirectory)\appsettings-schema.json" References="@(_References)" />
</Target>

JsonPathUpdateValue

Updates the value of a property in a JSON file using a JSON path expression.

<Target Name="UpdatePackageManifestVersion" DependsOnTargets="Build" AfterTargets="GetBuildVersion;GetUmbracoBuildVersion">
  <ItemGroup>
    <_PackageManifestFiles Include="**\package.manifest" />
  </ItemGroup>
  <JsonPathUpdateValue JsonFile="%(_PackageManifestFiles.FullPath)" Path="$.version" Value="&quot;$(PackageVersion)&quot;" />
</Target>

JsonSchemaGenerate

Generates a JSON schema from a C# type in an assembly. XML documentation comments are included as description fields in the generated schema, providing IntelliSense tooltips in editors.

Note: This task requires .NET Core MSBuild (i.e. dotnet build) or Visual Studio 2026+ (MSBuild 18.0+), which supports running .NET Core tasks via the TaskHost. It is not available when building with Visual Studio 2022 or earlier.

Note: When executing this task from a class library (Microsoft.NET.Sdk with <OutputType>Library</OutputType>, the default) and the type being generated depends on assemblies from referenced NuGet packages (e.g. Umbraco.Core), set <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> in the project file. This ensures the dependency DLLs are copied next to the target assembly so they can be resolved at build time. This is already the default for executable projects, including the Web (Microsoft.NET.Sdk.Web), Worker (Microsoft.NET.Sdk.Worker), and Blazor WebAssembly (Microsoft.NET.Sdk.BlazorWebAssembly) SDKs.

Parameter Required Description
AssemblyPath Yes Path to the assembly file containing the type
TypeName Yes Fully qualified type name to generate the schema for
OutputPath Yes Output file path for the generated JSON schema
IncludeObsoleteProperties No Whether to include properties marked with [Obsolete] (default: false)
<!-- Add JSON schema file to package output and remove on clean -->
<PropertyGroup>
  <_JsonSchemaFile>appsettings-schema.MyPackage.json</_JsonSchemaFile>
</PropertyGroup>
<ItemGroup>
  <Content Include="$(_JsonSchemaFile)" PackagePath="" Visible="false" />
  <Clean Include="$(_JsonSchemaFile)" />
</ItemGroup>

<!-- Generate JSON schema on build (regenerated when assembly is newer) -->
<Target Name="GenerateAppsettingsSchema" AfterTargets="Build" Inputs="$(TargetPath)" Outputs="$(_JsonSchemaFile)">
  <Message Text="Generating $(_JsonSchemaFile)" Importance="high" />
  <JsonSchemaGenerate AssemblyPath="$(TargetPath)" TypeName="MyPackage.MyPackageSchema" OutputPath="$(MSBuildThisFileDirectory)$(_JsonSchemaFile)" />
  <ItemGroup>
    <FileWrites Include="$(_JsonSchemaFile)" />
  </ItemGroup>
</Target>

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages