forked from AlinaNova21/Railroader-Mods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Directory.Build.targets
94 lines (76 loc) · 4.5 KB
/
Directory.Build.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<Project>
<PropertyGroup>
<!-- Try to find the directory on our own -->
<GameManagedDir Condition="'$(GameManagedDir)' == ''">$([System.IO.Directory]::GetDirectories(`$(GameDir)`, `*_Data`)[0])\Managed</GameManagedDir>
<!-- Copy the mod to the game directory -->
<GameModDir Condition="'$(GameModDir)' == ''">$(GameDir)/Mods/$(AssemblyName)</GameModDir>
<OutDir Condition="'$(Configuration)' == 'Debug' And '$(IsMod)' == 'true'">$(GameModDir)/</OutDir>
</PropertyGroup>
<PropertyGroup>
<IsMod Condition="'$(IsMod)' == ''">false</IsMod>
<PackageMod Condition="'$(PackageMod)' == '' Or '$(IsMod)' == 'false'">disable</PackageMod>
<PublishMod Condition="'$(PublishMod)' == '' Or '$(PackageMod)' == 'false'">disable</PublishMod>
</PropertyGroup>
<!-- Replace the default version if something was set for it -->
<PropertyGroup Condition="'$(AssemblyVersion)' == '' OR '$(MajorVersion)' != '' OR '$(MinorVersion)' != ''">
<MajorVersion Condition="'$(MajorVersion)' == ''">1</MajorVersion>
<MinorVersion Condition="'$(MinorVersion)' == ''">0</MinorVersion>
<AssemblyVersion>$(MajorVersion).$(MinorVersion).$([System.DateTime]::UtcNow.ToString(yy))$([System.DateTime]::UtcNow.DayOfYear.ToString("000")).$([System.DateTime]::UtcNow.ToString("Hmm").TrimStart('0'))</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<ProductVersion>$(AssemblyVersion)</ProductVersion>
</PropertyGroup>
<ItemGroup>
<!-- Reference the .dll/.exes specified with GameAssembly elements-->
<Reference Include="@(GameAssembly)">
<HintPath Condition="Exists('$(GameManagedDir)\%(Identity).dll')">$(GameManagedDir)\%(Identity).dll</HintPath>
<HintPath Condition="Exists('$(GameManagedDir)\%(Identity).exe')">$(GameManagedDir)\%(Identity).exe</HintPath>
<Private>false</Private>
</Reference>
<!-- Allow referencing things like OtherMod/Mod.dll -->
<ModReference Include="@(ModAssembly)">
<AssemblyName>$([System.IO.Path]::GetFileNameWithoutExtension("%(Identity)"))</AssemblyName>
<FullModPath>$(GameDir)\Mods\%(Identity)</FullModPath>
</ModReference>
<Reference Include="@(ModReference->'%(AssemblyName)')">
<HintPath Condition="Exists('%(FullModPath)')">%(FullModPath)</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<!-- Publish the mod as a neat zip file -->
<Target Name="PackageMod" AfterTargets="AfterBuild" Condition="'$(Configuration)' == 'Release' And '$(PackageMod)' == 'enable'">
<Message Text="Packaging $(AssemblyName) v$(AssemblyVersion)" Importance="high" />
<!-- Replace $(AssemblyVersion) with the actual version -->
<Exec Command="powershell -Command "(Get-Content '$(OutputPath)Definition.json') -replace '\$\(AssemblyVersion\)', '$(AssemblyVersion)' | Set-Content '$(OutputPath)Definition.json'"" />
<PropertyGroup>
<ModsDirectory>$(OutputPath)/Mods</ModsDirectory>
<ModDirectory>$(ModsDirectory)/$(AssemblyName)</ModDirectory>
<!-- Folder we'll put the published zips into -->
<PublishPath>../bin</PublishPath>
<ZipName>$(PublishPath)/$(AssemblyName)_$(AssemblyVersion).zip</ZipName>
</PropertyGroup>
<!-- Assure the output path exists -->
<MakeDir Directories="$(PublishPath)" />
<!-- Remove the old Mods directory, and Zips file if any is lying around -->
<ItemGroup>
<OldZips Include="$(PublishPath)/$(AssemblyName)_*.zip" />
</ItemGroup>
<RemoveDir Directories="$(ModsDirectory)" ContinueOnError="true" />
<Delete Files="@(OldZips)" />
<!-- Create the Mods directory again -->
<MakeDir Directories="$(ModDirectory)" />
<!-- Move all files to the right folder -->
<ItemGroup>
<OutputFiles Include="$(OutputPath)/**/*" />
</ItemGroup>
<Copy SourceFiles="@(OutputFiles)" DestinationFolder="$(ModDirectory)" />
<!-- Zip it up -->
<Exec Command="powershell -Command "Compress-Archive -Path '$(ModsDirectory)' -Destination '$(ZipName)'"" />
<!-- Move them to the game directory -->
<Copy SourceFiles="@(OutputFiles)" DestinationFolder="$(GameModDir)" />
</Target>
<Target Name="PublishMod" AfterTargets="PackageMod" Condition="'$(Configuration)' == 'Release' AND '$(PublishMod)' == 'enable'">
<Message Text="Publishing $(AssemblyName) v$(AssemblyVersion)" Importance="high" />
<!-- Publish to GitHub -->
<Exec Command="gh release create v$(AssemblyVersion) --generate-notes $(ZipName) @(ExtraZips, ' ')" />
</Target>
</Project>