summaryrefslogtreecommitdiff
path: root/src/SMAPI.ModBuildConfig/build/smapi.targets
blob: 664ba7df4efea8ba28147a72efcecf6d6dae1fd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Import Project="find-game-folder.targets" />
  <UsingTask TaskName="DeployModTask" AssemblyFile="SMAPI.ModBuildConfig.dll" />


  <!--*********************************************
  ** Set build options
  **********************************************-->
  <PropertyGroup>
    <!-- include PDB file by default to enable line numbers in stack traces -->
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>

    <!-- recognise XNA Framework DLLs in the GAC (only affects mods using new csproj format) -->
    <AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>

    <!-- suppress processor architecture mismatch warning (mods should be compiled in 'Any CPU' so they work in both 32-bit and 64-bit mode) -->
    <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>

    <!-- set default package options -->
    <ModFolderName Condition="'$(ModFolderName)' == ''">$(MSBuildProjectName)</ModFolderName>
    <ModZipPath Condition="'$(ModZipPath)' == ''">$(TargetDir)</ModZipPath>
    <GameModsPath Condition="'$(GameModsPath)' == ''">$([System.IO.Path]::Combine($(GamePath), 'Mods'))</GameModsPath>
    <EnableModDeploy Condition="'$(EnableModDeploy)' == ''">true</EnableModDeploy>
    <EnableModZip Condition="'$(EnableModZip)' == ''">true</EnableModZip>
    <EnableHarmony Condition="'$(EnableHarmony)' == ''">false</EnableHarmony>
    <EnableGameDebugging Condition="'$(EnableGameDebugging)' == ''">true</EnableGameDebugging>
    <CopyModReferencesToBuildOutput Condition="'$(CopyModReferencesToBuildOutput)' == '' OR ('$(CopyModReferencesToBuildOutput)' != 'true' AND '$(CopyModReferencesToBuildOutput)' != 'false')">false</CopyModReferencesToBuildOutput>

    <GameFramework Condition="'$(GameFramework)' == '' AND '$(OS)' == 'Windows_NT'">Xna</GameFramework>
    <GameFramework Condition="'$(GameFramework)' == ''">MonoGame</GameFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(OS)' == 'Windows_NT' AND '$(EnableGameDebugging)' == 'true'">
    <!-- enable game debugging -->
    <StartAction>Program</StartAction>
    <StartProgram>$(GamePath)\StardewModdingAPI.exe</StartProgram>
    <StartWorkingDirectory>$(GamePath)</StartWorkingDirectory>
  </PropertyGroup>


  <!--*********************************************
  ** Add assembly references
  **********************************************-->
  <ItemGroup>
    <!-- game -->
    <Reference Include="$(GameExecutableName)" HintPath="$(GamePath)\$(GameExecutableName).exe" Private="$(CopyModReferencesToBuildOutput)" />
    <Reference Include="StardewValley.GameData" HintPath="$(GamePath)\StardewValley.GameData.dll" Private="$(CopyModReferencesToBuildOutput)" />
    <Reference Include="MonoGame.Framework" HintPath="$(GamePath)\MonoGame.Framework.dll" Private="$(CopyModReferencesToBuildOutput)" />
    <Reference Include="xTile" HintPath="$(GamePath)\xTile.dll" Private="$(CopyModReferencesToBuildOutput)" />

    <!-- SMAPI -->
    <Reference Include="StardewModdingAPI" HintPath="$(GamePath)\StardewModdingAPI.exe" Private="$(CopyModReferencesToBuildOutput)" />
    <Reference Include="SMAPI.Toolkit.CoreInterfaces" HintPath="$(GamePath)\smapi-internal\SMAPI.Toolkit.CoreInterfaces.dll" Private="$(CopyModReferencesToBuildOutput)" />

    <!-- Harmony -->
    <Reference Include="0Harmony" Condition="'$(EnableHarmony)' == 'true'" HintPath="$(GamePath)\smapi-internal\0Harmony.dll" Private="$(CopyModReferencesToBuildOutput)" />

    <!-- Windows only -->
    <Reference Include="Netcode" HintPath="$(GamePath)\Netcode.dll" Private="$(CopyModReferencesToBuildOutput)" Condition="'$(OS)' == 'Windows_NT'" />
  </ItemGroup>


  <!--*********************************************
  ** Show validation messages
  **********************************************-->
  <Target Name="BeforeBuild">
    <!-- unknown OS type -->
    <Error Condition="'$(OS)' != 'OSX' AND '$(OS)' != 'Unix' AND '$(OS)' != 'Windows_NT'" Text="The mod build package doesn't recognise OS type '$(OS)'." />

    <!-- invalid game path -->
    <Error Condition="!Exists('$(GamePath)')" Text="The mod build package can't find your game folder. You can specify where to find it; see https://smapi.io/package/custom-game-path." ContinueOnError="false" />
    <Error Condition="!Exists('$(GamePath)\$(GameExecutableName).exe')" Text="The mod build package found a game folder at $(GamePath), but it doesn't contain the $(GameExecutableName) file. If this folder is invalid, delete it and the package will autodetect another game install path." ContinueOnError="false" />
    <Error Condition="!Exists('$(GamePath)\StardewModdingAPI.exe')" Text="The mod build package found a game folder at $(GamePath), but it doesn't contain SMAPI. You need to install SMAPI before building the mod." ContinueOnError="false" />

    <!-- invalid target architecture (note: internal value is 'AnyCPU', value shown in Visual Studio is 'Any CPU') -->
    <Warning Condition="'$(Platform)' != 'AnyCPU'" Text="The target platform should be set to 'Any CPU' for compatibility with both 32-bit and 64-bit versions of Stardew Valley (currently set to '$(Platform)'). See https://smapi.io/package/wrong-processor-architecture for details." HelpLink="https://smapi.io/package/wrong-processor-architecture" />
  </Target>


  <!--*********************************************
  ** Deploy mod files & create release zip
  **********************************************-->
  <Target Name="AfterBuild">
    <DeployModTask
      ModFolderName="$(ModFolderName)"
      ModZipPath="$(ModZipPath)"

      EnableModDeploy="$(EnableModDeploy)"
      EnableModZip="$(EnableModZip)"

      ProjectDir="$(ProjectDir)"
      TargetDir="$(TargetDir)"
      GameModsDir="$(GameModsPath)"
      IgnoreModFilePatterns="$(IgnoreModFilePatterns)"
    />
  </Target>
</Project>