This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tmodloader.targets
72 lines (62 loc) · 4.2 KB
/
tmodloader.targets
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
<?xml version="1.0" encoding="utf-8"?>
<!-- ===========================================================================================================================
Targets file for compiling tTModLoader Mods. Now with incremental build support!
Updated for version 0.11
For more information visit:
https://forums.terraria.org/index.php?threads/guide-better-system-for-building-mods-with-visual-studio-msbuild.80009/
=========================================================================================================================== -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- We need to disable Visual Studio's up-to-date check, because we are including files in our build that VS doesn't know about -->
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<!-- Default tModLoader save paths, for output folder path and finding reference .targets -->
<tmodSavePath Condition="'$(tmodSavePath)'=='' AND $([MSBuild]::IsOsPlatform('Windows'))">$(registry:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders@Personal)\My Games\Terraria\ModLoader</tmodSavePath>
<tmodSavePath Condition="'$(tmodSavePath)'=='' AND $([MSBuild]::IsOsPlatform('Linux')) AND '$(XDG_DATA_HOME)'!=''">$(XDG_DATA_HOME)/.local/share/Terraria/ModLoader</tmodSavePath>
<tmodSavePath Condition="'$(tmodSavePath)'=='' AND $([MSBuild]::IsOsPlatform('Linux'))">$(HOME)/.local/share/Terraria/ModLoader</tmodSavePath>
<tmodSavePath Condition="'$(tmodSavePath)'=='' AND $([MSBuild]::IsOsPlatform('OSX'))">$(HOME)/Library/Application Support/Terraria/ModLoader</tmodSavePath>
<!-- build.txt to parse ignores from -->
<tmodBuildTxtPath Condition="'$(tmodBuildTxtPath)'==''">$(ProjectDir)build.txt</tmodBuildTxtPath>
</PropertyGroup>
<!-- .targes file generated by tModLoader 0.11 and above. Contains all of the useful references. -->
<Import Project="$(tmodSavePath)/References/tModLoader.targets" />
<!-- Task for listing all files that will be included in the mod file build -->
<UsingTask TaskName="tmodParseBuildFilesTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)/Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<ProjectPath ParameterType="System.String" Required="true" />
<BuildTxtPath ParameterType="System.String" Required="true" />
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Using Namespace="Microsoft.Build.Framework" />
<Code Type="Fragment" Language="cs"><![CDATA[
Regex ignores = null;
if (File.Exists(BuildTxtPath))
{
string line = File.ReadAllLines(BuildTxtPath).FirstOrDefault(x => x.StartsWith("buildIgnore"));
if (line != null)
ignores = new Regex("^(" + Regex.Escape(line.Replace("buildIgnore", "").Replace("=", "").Replace(" ", "")).Replace("\\?", ".").Replace("\\*", ".*").Replace(",", "|") + ")$");
}
IEnumerable<string> filePaths = Directory.GetFiles(ProjectPath, "*.*", SearchOption.AllDirectories);
if (ignores != null)
filePaths = filePaths.Where(x => !ignores.IsMatch(x.Replace(ProjectPath, "").Replace("\\", "/")));
Files = filePaths.Select(x => new TaskItem(x)).ToArray();
]]></Code>
</Task>
</UsingTask>
<!-- List all files in build -->
<Target Name="tmodParseBuildFiles">
<tmodParseBuildFilesTask ProjectPath="$(ProjectDir)" BuildTxtPath="$(tmodBuildTxtPath)">
<Output TaskParameter="Files" PropertyName="tmodBuildFiles" />
</tmodParseBuildFilesTask>
</Target>
<!-- Create .tmod file -->
<Target Name="tmodBuildModFile" AfterTargets="Build" DependsOnTargets="tmodParseBuildFiles" Inputs="$(tmodBuildFiles)" Outputs="$(tmodSavePath)/Mods/$(AssemblyName).tmod">
<!-- If the Import fails msbuild should give an error, but VS can be a weird sometimes, it's best to do a quick check -->
<Error Condition="$(tMLBuildServerPath)==''" Text="tMLBuildServerPath not set! (Try restarting your IDE)" />
<Exec Command=""$(tMLBuildServerPath)" -build $(ProjectDir) -eac $(TargetPath) -define $(DefineConstants) -unsafe $(AllowUnsafeBlocks)" />
</Target>
</Project>