<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup Label="Target">
        <TargetFramework>net5.0-windows</TargetFramework>
        <PlatformTarget>x64</PlatformTarget>
        <Platforms>x64;AnyCPU</Platforms>
        <LangVersion>10.0</LangVersion>
    </PropertyGroup>

    <PropertyGroup Label="Feature">
        <DalamudVersion>6.4.0.26</DalamudVersion>
        <Description>XIV Launcher addon framework</Description>
        <AssemblyVersion>$(DalamudVersion)</AssemblyVersion>
        <Version>$(DalamudVersion)</Version>
        <FileVersion>$(DalamudVersion)</FileVersion>
    </PropertyGroup>

    <PropertyGroup Label="Output">
        <OutputType>Library</OutputType>
        <OutputPath>..\bin\$(Configuration)\</OutputPath>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
        <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
        <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
        <ProduceReferenceAssembly>false</ProduceReferenceAssembly>
    </PropertyGroup>

    <PropertyGroup Label="Documentation">
        <DocumentationFile>$(OutputPath)Dalamud.xml</DocumentationFile>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
    </PropertyGroup>

    <PropertyGroup Label="Build">
        <UseWindowsForms>true</UseWindowsForms>
        <EnableDynamicLoading>true</EnableDynamicLoading>
        <DebugSymbols>true</DebugSymbols>
        <DebugType>portable</DebugType>
        <Deterministic>true</Deterministic>
        <Nullable>annotations</Nullable>
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    </PropertyGroup>

    <PropertyGroup Label="Configuration">
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    </PropertyGroup>
    <PropertyGroup Label="Configuration" Condition="'$(Configuration)'=='Debug'">
        <DefineConstants>DEBUG;TRACE</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Label="Configuration" Condition="'$(Configuration)'=='Release'">
        <AppOutputBase>$(MSBuildProjectDirectory)\</AppOutputBase>
        <PathMap>$(AppOutputBase)=C:\goatsoft\companysecrets\dalamud\</PathMap>
    </PropertyGroup>

    <PropertyGroup Label="Warnings">
        <NoWarn>IDE0002;IDE0003;IDE1006;IDE0044;CA1822;CS1591;CS1701;CS1702</NoWarn>
        <!-- IDE1002 - Simplify member access -->
        <!-- IDE1003 - This and me preferences -->
        <!-- IDE1006 - Naming violation -->
        <!-- IDE1006 - Add readonly modifier -->
        <!-- CA1822  - Can be marked as static -->
        <!-- CS1591  - Missing XML comment for publicly visible type or member -->
        <!-- CS1701  - Runtime policy may be needed -->
        <!-- CS1702  - Runtime policy may be needed -->
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="CheapLoc" Version="1.1.6" />
        <PackageReference Include="JetBrains.Annotations" Version="2021.2.0" />
        <PackageReference Include="Lumina" Version="3.5.2" />
        <PackageReference Include="Lumina.Excel" Version="6.1.1" />
        <PackageReference Include="MinSharp" Version="1.0.4" />
        <PackageReference Include="MonoMod.RuntimeDetour" Version="21.10.10.01" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
        <PackageReference Include="Serilog" Version="2.10.0" />
        <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
        <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
        <PackageReference Include="Reloaded.Hooks" Version="3.5.3" />
        <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
        <PackageReference Include="System.Drawing.Common" Version="5.0.2" />
        <PackageReference Include="System.Reflection.MetadataLoadContext" Version="5.0.1" />
        <PackageReference Include="System.Resources.Extensions" Version="5.0.0" />
    </ItemGroup>
    <ItemGroup>
        <ProjectReference Include="..\lib\FFXIVClientStructs\FFXIVClientStructs\FFXIVClientStructs.csproj" />
        <ProjectReference Include="..\lib\ImGuiScene\deps\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj" />
        <ProjectReference Include="..\lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj" />
        <ProjectReference Include="..\lib\ImGuiScene\ImGuiScene\ImGuiScene.csproj" />
    </ItemGroup>

    <ItemGroup>
        <AdditionalFiles Include="..\stylecop.json" />
    </ItemGroup>

    <Target Name="AddRuntimeDependenciesToContent" BeforeTargets="GetCopyToOutputDirectoryItems" DependsOnTargets="GenerateBuildDependencyFile;GenerateBuildRuntimeConfigurationFiles">
        <ItemGroup>
            <ContentWithTargetPath Include="$(ProjectDepsFilePath)" CopyToOutputDirectory="PreserveNewest" TargetPath="$(ProjectDepsFileName)" />
            <ContentWithTargetPath Include="$(ProjectRuntimeConfigFilePath)" CopyToOutputDirectory="PreserveNewest" TargetPath="$(ProjectRuntimeConfigFileName)" />
        </ItemGroup>
    </Target>

    <Target Name="GetGitHash" BeforeTargets="WriteGitHash" Condition="'$(BuildHash)' == ''">
        <PropertyGroup>
            <!-- temp file for the git version (lives in "obj" folder)-->
            <VerFile>$(IntermediateOutputPath)gitver</VerFile>
            <VerFileClientStructs>$(IntermediateOutputPath)csver</VerFileClientStructs>
        </PropertyGroup>
        <!-- write the hash to the temp file.-->
        <Exec Command="git -C &quot;$(ProjectDir.Replace('\','\\'))&quot; describe --long --always --dirty &gt; $(VerFile)" />
        <Exec Command="git -C &quot;$(ProjectDir.Replace('\','\\'))\..\lib\FFXIVClientStructs&quot; describe --long --always --dirty &gt; $(VerFileClientStructs)" />
        <!-- read the version into the GitVersion itemGroup-->
        <ReadLinesFromFile File="$(VerFile)">
            <Output TaskParameter="Lines" ItemName="GitVersion" />
        </ReadLinesFromFile>
        <ReadLinesFromFile File="$(VerFileClientStructs)">
            <Output TaskParameter="Lines" ItemName="GitVersionClientStructs" />
        </ReadLinesFromFile>
        <!-- Set the BuildHash property to contain the GitVersion, if it wasn't already set.-->
        <PropertyGroup>
            <BuildHash>@(GitVersion)</BuildHash>
            <BuildHashClientStructs>@(GitVersionClientStructs)</BuildHashClientStructs>
        </PropertyGroup>
    </Target>
    <Target Name="WriteGitHash" BeforeTargets="CoreCompile">
        <!-- names the obj/.../CustomAssemblyInfo.cs file -->
        <PropertyGroup>
            <CustomAssemblyInfoFile>$(IntermediateOutputPath)CustomAssemblyInfo.cs</CustomAssemblyInfoFile>
        </PropertyGroup>
        <!-- includes the CustomAssemblyInfo for compilation into your project -->
        <ItemGroup>
            <Compile Include="$(CustomAssemblyInfoFile)" />
        </ItemGroup>
        <!-- defines the AssemblyMetadata attribute that will be written -->
        <ItemGroup>
            <AssemblyAttributes Include="AssemblyMetadata">
                <_Parameter1>GitHash</_Parameter1>
                <_Parameter2>$(BuildHash)</_Parameter2>
            </AssemblyAttributes>
            <AssemblyAttributes Include="AssemblyMetadata">
                <_Parameter1>GitHashClientStructs</_Parameter1>
                <_Parameter2>$(BuildHashClientStructs)</_Parameter2>
            </AssemblyAttributes>
        </ItemGroup>
        <!-- writes the attribute to the customAssemblyInfo file -->
        <WriteCodeFragment Language="C#" OutputFile="$(CustomAssemblyInfoFile)" AssemblyAttributes="@(AssemblyAttributes)" />
    </Target>
</Project>
