Attribute>
  </PropertyGroup>

<!--
********************************************************************************************
Target: GenerateUserSecretsAttribute

Generates an assembly attribute that has the user secrets id that .AddUserSecrets will find
********************************************************************************************
-->
  <Target Name="GenerateUserSecretsAttribute"
          BeforeTargets="CoreCompile"
          DependsOnTargets="PrepareForBuild;CoreGenerateUserSecretsAttribute"
          Condition="'$(GenerateUserSecretsAttribute)'=='true' and '$(DesignTimeBuild)'!='true'" />

  <Target Name="CoreGenerateUserSecretsAttribute"
          Condition="'$(UserSecretsId)'!=''"
          Inputs="$(MSBuildAllProjects)"
          Outputs="$(GeneratedUserSecretsAttributeFile)" >
    <ItemGroup>
      <_UserSecretAssemblyAttribute Remove="@(_UserSecretAssemblyAttribute)" />
      <_UserSecretAssemblyAttribute Include="Microsoft.Extensions.Configuration.UserSecrets.UserSecretsIdAttribute">
        <_Parameter1>$(UserSecretsId.Trim())</_Parameter1>
      </_UserSecretAssemblyAttribute>
    </ItemGroup>

    <ItemGroup>
      <!--Ensure generated file is not already in compile sources-->
      <Compile Remove="$(GeneratedUserSecretsAttributeFile)"  />
    </ItemGroup>

    <WriteCodeFragment AssemblyAttributes="@(_UserSecretAssemblyAttribute)" Language="$(Language)" OutputFile="$(GeneratedUserSecretsAttributeFile)">
      <Output TaskParameter="OutputFile" ItemName="Compile" />
      <Output TaskParameter="OutputFile" ItemName="FileWrites" />
    </WriteCodeFragment>
  </Target>
</Project>
