<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <!-- OutputType for Windows, MacOS & Linux -->
        <OutputType>WinExe</OutputType>
        <TargetFramework>net9.0</TargetFramework>
        <BuiltInComInteropSupport>false</BuiltInComInteropSupport>
        <AvaloniaNameGeneratorIsEnabled>true</AvaloniaNameGeneratorIsEnabled>
        <ApplicationManifest>app.manifest</ApplicationManifest>
        <SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
        <ApplicationIcon>Assets\Images\nitrox-icon.ico</ApplicationIcon>
        <PublishTrimmed>false</PublishTrimmed>
        <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
    </PropertyGroup>

    <PropertyGroup>
        <AppBundleName>Nitrox.app</AppBundleName>
    </PropertyGroup>

    <ItemGroup>
        <AvaloniaResource Include="Assets\**" />
    </ItemGroup>

    <ItemGroup>
        <TrimmerRootDescriptor Include="Roots.xml" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Avalonia" Version="11.1.5" />
        <PackageReference Include="Avalonia.Desktop" Version="11.1.5" />
        <PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0.1" />
        <PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.5" />
        <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.5" />
        <PackageReference Include="Avalonia.Xaml.Interactions" Version="11.1.0.7" />
        <PackageReference Include="Avalonia.Xaml.Interactivity" Version="11.1.0.7" />
        <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
        <PackageReference Include="ConsoleAppFramework" Version="5.3.1">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="dnlib" Version="4.4.0" />
        <PackageReference Include="HanumanInstitute.MvvmDialogs.Avalonia" Version="2.1.0" />
        <PackageReference Include="LitJson" Version="0.19.0" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
        <PackageReference Include="ServiceScan.SourceGenerator" Version="2.1.1">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
    </ItemGroup>

    <ItemGroup>
        <ProjectReference Include="..\NitroxModel\NitroxModel.csproj" />
        <ProjectReference Include="..\NitroxServer\NitroxServer.csproj" />
    </ItemGroup>

    <!-- Project references not to be code-linked with app, but are used by app as content files. See https://github.com/dotnet/msbuild/issues/4795#issuecomment-1443879474  -->
    <ItemGroup>
        <!-- TODO: Fix server project reference so there's no code access (launcher should never call server exe code). -->
        <ProjectReference Include="..\NitroxServer-Subnautica\NitroxServer-Subnautica.csproj" />
        <ProjectReference Include="..\NitroxPatcher\NitroxPatcher.csproj">
            <Name>NitroxPatcher472</Name>
            <SetTargetFramework>TargetFramework=net472</SetTargetFramework>
            <SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
            <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
            <ExcludeAssets>compile</ExcludeAssets>
            <AdditionalProperties Condition="'$(BuildingInsideVisualStudio)' != 'true'">TargetFramework=net472;OutDir=$(MSBuildProjectDirectory)\$(OutputPath)\lib\net472\</AdditionalProperties>
        </ProjectReference>
    </ItemGroup>

    <!-- ProjectReference with Properties/AdditionalProperties aren't given to referenced project inside Visual Studio, so we need to copy it by hand.. -->
    <!-- See: https://github.com/dotnet/msbuild/issues/5599 -->
    <Target Name="_NitroxFixBuildInsideVisualStudio" AfterTargets="$(_NitroxMoveDependenciesToLibTaskName)" Condition="'$(BuildingInsideVisualStudio)' == 'true'">

        <Message Importance="High"
                 Text="Running _FixBuildInsideVisualStudio on $(MSBuildProjectName)" />

        <ItemGroup>
            <_FilesToCopy Include="$(MSBuildProjectDirectory)\..\NitroxPatcher\bin\$(Configuration)\net472\*" />
        </ItemGroup>

        <Error Text="Unable to find NitroxPatcher files from _NitroxFixBuildInsideVisualStudio"
               Condition="@(_FilesToCopy->Count()) == 0" />

        <Copy SourceFiles="@(_FilesToCopy)"
              DestinationFolder="$(MSBuildProjectDirectory)\$(OutputPath)\lib\net472\"
              OverwriteReadOnlyFiles="True"
              Retries="3"
              RetryDelayMilliseconds="100"
              SkipUnchangedFiles="True" />

    </Target>

    <ItemGroup>
        <Content Include="..\Nitrox.Assets.Subnautica\*.dll" LinkBase="lib\net472" CopyToOutputDirectory="PreserveNewest" />
        <Content Include="..\Nitrox.Assets.Subnautica\Resources\**" LinkBase="Resources" CopyToOutputDirectory="PreserveNewest" />
        <Content Include="..\Nitrox.Assets.Subnautica\LanguageFiles\**" LinkBase="Resources\LanguageFiles" CopyToOutputDirectory="PreserveNewest" />
        <Content Include="..\Nitrox.Assets.Subnautica\AssetBundles\**" LinkBase="Resources\AssetBundles" CopyToOutputDirectory="PreserveNewest" />
    </ItemGroup>

    <Import Project="..\Nitrox.Shared.targets" />
</Project>
