﻿<?xml version="1.0" encoding="utf-8"?>

<!--
***********************************************************************************************
Microsoft.WebTools.Aspire.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask
      TaskName="Microsoft.WebTools.Aspire.MSBuild.GenerateCombinedComponentSchema"
      AssemblyFile="Microsoft.WebTools.Aspire.MSBuild.dll" />
  <UsingTask
      TaskName="Microsoft.WebTools.Aspire.MSBuild.GenerateCombinedAppSettingsSchema"
      AssemblyFile="Microsoft.WebTools.Aspire.MSBuild.dll" />

  <PropertyGroup>
    <JsonSchemaCombinedFilePath>$(IntermediateOutputPath)\CombinedComponentSchema.json</JsonSchemaCombinedFilePath>
    <JsonSchemaCombinedFilePath>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(JsonSchemaCombinedFilePath)))</JsonSchemaCombinedFilePath>
    <AppSettingsJsonSchemaCombinedFilePath>$(IntermediateOutputPath)\AppSettingsSchema.json</AppSettingsJsonSchemaCombinedFilePath>
    <AppSettingsJsonSchemaCombinedFilePath>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(AppSettingsJsonSchemaCombinedFilePath)))</AppSettingsJsonSchemaCombinedFilePath>
    <SchemaGenIncrementalBuildInputs>@(JsonSchemaSegment);$(ProjectAssetsFile)</SchemaGenIncrementalBuildInputs>
  </PropertyGroup>

  <Target Name="GenerateCombinedComponentSchemaTarget"
          Condition=" '@(JsonSchemaSegment)' != '' "
          Inputs="$(SchemaGenIncrementalBuildInputs)"
          Outputs="$(JsonSchemaCombinedFilePath)">
    <GenerateCombinedComponentSchema
      JsonSchemaSegmentFiles="@(JsonSchemaSegment)"
      JsonSchemaCombinedFilePath="$(JsonSchemaCombinedFilePath)">
    </GenerateCombinedComponentSchema>
  </Target>

  <Target Name="GenerateCombinedAppSettingsSchemaTarget"
          DependsOnTargets="GenerateCombinedComponentSchemaTarget"
          Condition=" '@(JsonSchemaSegment)' != '' "
          BeforeTargets="CompileDesignTime"
          Inputs="$(SchemaGenIncrementalBuildInputs);$(JsonSchemaCombinedFilePath)"
          Outputs="$(AppSettingsJsonSchemaCombinedFilePath)">
    <GenerateCombinedAppSettingsSchema
      AppSettingJsonSchemaFilePath="$(AppSettingJsonSchemaLoadFilePath)"
      ComponentJsonSchemaCombinedFilePath="$(JsonSchemaCombinedFilePath)"
      AppSettingsJsonSchemaCombinedFilePath="$(AppSettingsJsonSchemaCombinedFilePath)">
    </GenerateCombinedAppSettingsSchema>
    <Message Text="Generating appsettingsschema" />
  </Target>
  
  <Target Name="CleanupCombinedAppSettingsSchemaTarget"
          Condition=" '@(JsonSchemaSegment)' == '' "
          BeforeTargets="CompileDesignTime">
    <Delete Files="$(AppSettingsJsonSchemaCombinedFilePath)" />
    <Message Text="Deleting appsettingsschema" />
  </Target>
</Project>
