-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathKSPCommon.targets
More file actions
301 lines (275 loc) · 17.2 KB
/
KSPCommon.targets
File metadata and controls
301 lines (275 loc) · 17.2 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Condition=" '$(KSPCommonPropsImported)' == '' And Exists('$(MSBuildThisFileDirectory)KSPCommon.props') " Project="$(MSBuildThisFileDirectory)KSPCommon.props"/>
<!-- Relative path that must exist for a path to be a valid KSP Install-->
<PropertyGroup>
<KSPBT_GameIdentifier>$(_KSPBT_ManagedRelativePath)/Assembly-CSharp.dll</KSPBT_GameIdentifier>
<KSPBT_GameRootSource Condition="'$(KSPBT_GameRoot)' != ''">property</KSPBT_GameRootSource>
</PropertyGroup>
<!-- Default KSPBT_GameRoot to the "KSP_ROOT" environment variable if it exists -->
<!-- Doing this skips any checks for a valid KSP install so be careful! -->
<PropertyGroup Condition=" '$(KSPBT_GameRoot)' == '' And '$(KSP_ROOT)' != '' ">
<KSPBT_GameRoot>$(KSP_ROOT)</KSPBT_GameRoot>
<KSPBT_GameRootSource>environment variable</KSPBT_GameRootSource>
</PropertyGroup>
<ItemGroup>
<KSPBT_GameRootCandidate Include="$(SolutionDir)KSP" source="solution directory" Condition=" '$(SolutionDir)' != '' "/>
<KSPBT_GameRootCandidate Include="$(ReferencePath)" source="reference path"/>
<KSPBT_GameRootCandidate Include="$(_KSPBT_SteamGameRoot)" source="steam"/>
</ItemGroup>
<!-- Look for KSP install in Solution dir -->
<PropertyGroup Condition=" '$(KSPBT_GameRoot)' == '' And '$(SolutionDir)' != '' And Exists('$(SolutionDir)KSP/$(KSPBT_GameIdentifier)') ">
<KSPBT_GameRoot>$(SolutionDir)KSP</KSPBT_GameRoot>
<KSPBT_GameRootSource>solution directory</KSPBT_GameRootSource>
</PropertyGroup>
<!-- Look for KSP install in ReferencePath -->
<PropertyGroup Condition=" '$(KSPBT_GameRoot)' == '' And Exists('$(ReferencePath)/$(KSPBT_GameIdentifier)') ">
<KSPBT_GameRoot>$(ReferencePath)</KSPBT_GameRoot>
<KSPBT_GameRootSource>reference path</KSPBT_GameRootSource>
</PropertyGroup>
<!-- Look for KSP steam install-->
<PropertyGroup Condition=" '$(KSPBT_GameRoot)' == '' And Exists('$(_KSPBT_SteamGameRoot)/$(KSPBT_GameIdentifier)') ">
<KSPBT_GameRoot>$(_KSPBT_SteamGameRoot)</KSPBT_GameRoot>
<KSPBT_GameRootSource>steam</KSPBT_GameRootSource>
</PropertyGroup>
<!-- set the start action so that you can launch directly from VS -->
<PropertyGroup>
<StartAction>Program</StartAction>
<StartProgram>$(KSPBT_GameRoot)/$(_KSPBT_GameExecutable)</StartProgram>
<StartWorkingDirectory>$(KSPBT_GameRoot)</StartWorkingDirectory>
<DebugType>portable</DebugType>
</PropertyGroup>
<!-- Calculate KSPBT_ManagedPath -->
<PropertyGroup Condition=" '$(KSPBT_ManagedPath)' == ''">
<KSPBT_ManagedPath>$(KSPBT_GameRoot)/$(_KSPBT_ManagedRelativePath)</KSPBT_ManagedPath>
</PropertyGroup>
<!-- Prevent the compiler from acquiring or referencing any external reference assemblies -->
<PropertyGroup Condition=" '$(KSPBT_ReferenceSystemAssemblies)' == 'true' ">
<!-- Do not download the .NET Framework Target Pack NuGet package automatically -->
<DisableTransitiveFrameworkReferenceDownloads>true</DisableTransitiveFrameworkReferenceDownloads>
<!-- Instruct the compiler to not automatically reference mscorlib -->
<NoStandardLib>true</NoStandardLib>
<!-- Prevent the GetReferenceAssemblyPaths task in Microsoft.Common.CurrentVersion.targets
from attempting to locate an external copy of the reference assemblies. -->
<AutomaticallyUseReferenceAssemblyPackages>false</AutomaticallyUseReferenceAssemblyPackages>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<FrameworkPathOverride>$(KSPBT_ManagedPath)</FrameworkPathOverride>
<_FullFrameworkReferenceAssemblyPaths>$(KSPBT_ManagedPath)</_FullFrameworkReferenceAssemblyPaths>
<_TargetFrameworkDirectories>$(KSPBT_ManagedPath)</_TargetFrameworkDirectories>
</PropertyGroup>
<!-- Import references -->
<ItemGroup Condition=" '$(KSPBT_ReferenceSystemAssemblies)' == 'true' ">
<Reference Include="$(KSPBT_ManagedPath)/System.dll">
<Name>System (KSP/Mono)</Name>
<Private>False</Private>
</Reference>
<Reference Include="$(KSPBT_ManagedPath)/System.Core.dll">
<Name>System (KSP/Mono)</Name>
<Private>False</Private>
</Reference>
<Reference Include="$(KSPBT_ManagedPath)/mscorlib.dll">
<Name>System.Core (KSP/Mono)</Name>
<Private>False</Private>
</Reference>
<Reference Include="$(KSPBT_ManagedPath)/System.Xml.dll">
<Name>System.Xml (KSP/Mono)</Name>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(KSPBT_ReferenceUnityAssemblies)' == 'true' ">
<Reference Include="$(KSPBT_ManagedPath)/UnityEngine*.dll">
<Name>UnityEngine</Name>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(KSPBT_ReferenceGameAssemblies)' == 'true'">
<Reference Include="$(KSPBT_ManagedPath)/Assembly-CSharp.dll">
<Name>Assembly-CSharp</Name>
<Private>False</Private>
</Reference>
<Reference Include="$(KSPBT_ManagedPath)/Assembly-CSharp-firstpass.dll">
<Name>Assembly-CSharp-firstpass</Name>
<Private>False</Private>
</Reference>
</ItemGroup>
<!--Custom Targets-->
<Target Name="KSPBT_CheckForGameRoot" BeforeTargets="ResolveReferences">
<Error Text="KSPBuildTools was unable to find a KSP installation. Please set the ReferencePath or KSPBT_GameRoot property
in your csproj.user file to a valid KSP installation directory (the one with GameData in it)
See https://kspbuildtools.readthedocs.io/en/latest/msbuild/ksp-install.html for more information"
Condition="'$(KSPBT_GameRoot)' == ''"/>
<ItemGroup>
<_GameRootMessage Include="KSPBT_GameRoot Candidates:"/>
<_GameRootMessage Include="Candidate: %(KSPBT_GameRootCandidate.source) from %(KSPBT_GameRootCandidate.identity)"/>
<_GameRootMessage Include="Chosen KSPBT_GameRoot: $(KSPBT_GameRoot) in $(KSPBT_GameRootSource)" Condition="'$(KSPBT_GameRoot)' != ''"/>
</ItemGroup>
<Message Text="@(_GameRootMessage, '%0a')" Importance="normal"/>
</Target>
<!--
Convert ModReference items to Reference items. This allows KSPBT_InstallRoot to be evaluated
after the csproj body or in a target, giving greater flexibility.
The value of the item should be name of the assembly as defined in its KSPAssembly attribute.
The DLLPath attribute is the path to the DLL relative to the installation root, e.g. "GameData/CoolMod/mod.dll"
-->
<PropertyGroup Condition=" '$(KSPBT_ReferenceModAssemblies)' == 'true' ">
<ResolveAssemblyReferencesDependsOn>KSPBT_ReferenceModAssemblies;$(ResolveAssemblyReferencesDependsOn)</ResolveAssemblyReferencesDependsOn>
<KSPBT_GenerateCKANScriptDependsOn>KSPBT_ReferenceModAssemblies;$(KSPBT_GenerateCKANScriptDependsOn)</KSPBT_GenerateCKANScriptDependsOn>
</PropertyGroup>
<Target Name="KSPBT_ReferenceModAssemblies" BeforeTargets="ResolveAssemblyReferences"
Condition=" '$(KSPBT_ReferenceModAssemblies)' == 'true' ">
<ItemGroup>
<Reference Include="@(ModReference->'$(KSPBT_GameRoot)/%(DLLPath)')">
<KSPAssemblyName Condition=" '%(ModReference.KSPAssemblyName)' == '' ">%(ModReference.identity)</KSPAssemblyName>
</Reference>
</ItemGroup>
</Target>
<!-- Generate script to run to install CKAN dependencies -->
<PropertyGroup>
<_CKANScript>$(BaseIntermediateOutputPath)ckancommands.cache</_CKANScript>
</PropertyGroup>
<Target Name="KSPBT_GenerateCKANScript" DependsOnTargets="$(KSPBT_GenerateCKANScriptDependsOn)">
<ItemGroup>
<_CKANCompatibleVersionItems Include="$(KSPBT_CKANCompatibleVersions.Split(' '))"/>
<_CKANDependency Include="%(Reference.CKANIdentifier)" Condition="'%(Reference.CKANVersion)' == ''"/>
<_CKANDependency Include="%(Reference.CKANIdentifier)=%(Reference.CKANVersion)" Condition="'%(Reference.CKANVersion)' != ''"/>
<_CKANDependency Include="@(CKANDependency)"/>
</ItemGroup>
<PropertyGroup>
<_CKANDependencyList>@(_CKANDependency, ' ')</_CKANDependencyList>
</PropertyGroup>
<ItemGroup>
<!-- Not using `ckan compat set` because as of 2024-08-16 it is still only available in the dev branch -->
<_CKANCommands Include="update" />
<_CKANCommands Include="compat add --gamedir "$(KSPBT_GameRoot)" %(_CKANCompatibleVersionItems.Identity)"
Condition=" '$(KSPBT_CKANCompatibleVersions)' != '' "/>
<_CKANCommands Include="install --no-recommends --gamedir "$(KSPBT_GameRoot)" $(_CKANDependencyList)" Condition="'$(_CKANDependencyList)' != ''"/>
</ItemGroup>
<Message Text="Writing CKAN commands to $(_CKANScript)"/>
<Message Text="@(_CKANCommands, '%0a')" Importance="Low"/>
<WriteLinesToFile File="$(_CKANScript)" Lines="@(_CKANCommands)" Overwrite="true" WriteOnlyWhenDifferent="true"/>
</Target>
<!-- Execute generated CKAN command list -->
<PropertyGroup Condition=" '$(KSPBT_InstallCKANDependencies)' == 'true' ">
<ResolveAssemblyReferencesDependsOn>KSPBT_InstallCKANDependencies;$(ResolveAssemblyReferencesDependsOn)</ResolveAssemblyReferencesDependsOn>
</PropertyGroup>
<Target Name="KSPBT_InstallCKANDependencies" DependsOnTargets="KSPBT_GenerateCKANScript" BeforeTargets="_GenerateRestoreProjectSpec;Restore;ResolveAssemblyReferences"
Inputs="$(_CKANScript)" Outputs="$(KSPBT_GameRoot)/CKAN/registry.json"
Condition=" '$(KSPBT_InstallCKANDependencies)' == 'true' ">
<Exec Command="ckan prompt --headless --asroot < '$(_CKANScript)'" Condition=" '$(_CKANDependencyList)' != '' "/>
</Target>
<Target Name="KSPBT_CleanCKANScript" AfterTargets="Clean">
<Delete Files="$(_CKANScript)"/>
</Target>
<!-- Generate the KSPAssembly attribute based on the FileVersion property -->
<Target Name="KSPBT_GenerateAssemblyAttribute" BeforeTargets="CoreGenerateAssemblyInfo"
Condition="'$(KSPBT_GenerateAssemblyAttribute)' == 'true'">
<ItemGroup>
<AssemblyAttribute Include="KSPAssembly">
<_Parameter1>$(AssemblyName)</_Parameter1>
<_Parameter1_TypeName>System.String</_Parameter1_TypeName>
<_Parameter2>$(FileVersion.Split('.')[0])</_Parameter2>
<_Parameter2_TypeName>System.Int32</_Parameter2_TypeName>
<_Parameter3>$(FileVersion.Split('.')[1])</_Parameter3>
<_Parameter3_TypeName>System.Int32</_Parameter3_TypeName>
<_Parameter4 Condition="$(FileVersion.Split('.').Length) > 2">$(FileVersion.Split('.')[2])</_Parameter4>
<_Parameter4_TypeName Condition="$(FileVersion.Split('.').Length) > 2">System.Int32</_Parameter4_TypeName>
</AssemblyAttribute>
</ItemGroup>
</Target>
<!--
Generate the KSPAssemblyDependency attributes based on input references
Reference items must have a CKANIdentifier or a KSPAssemblyName.
KSPAssemblyVersion can be optionally specified.
Otherwise CKANVersion is used.
Otherwise 0.0 is used (no minimum version)
-->
<Target Name="KSPBT_GenerateDependencyAttributes" BeforeTargets="CoreGenerateAssemblyInfo"
Condition=" '$(KSPBT_GenerateDependencyAttributes)' == 'true' ">
<ItemGroup>
<Reference Update="%(Reference.identity)" Condition=" '%(Reference.CKANIdentifier)%(Reference.KSPAssemblyName)' != '' and '%(Reference.GenerateDependencyAttribute)' == 'true' ">
<KSPAssemblyName Condition="'%(Reference.KSPAssemblyName)' == ''">$([System.String]::Copy('%(Reference.identity)').Split(',')[0])</KSPAssemblyName>
<KSPAssemblyVersion Condition="'%(Reference.KSPAssemblyVersion)' == ''">%(Reference.CKANVersion)</KSPAssemblyVersion>
<KSPAssemblyVersion Condition="'%(Reference.KSPAssemblyVersion)' == ''">0.0</KSPAssemblyVersion>
<KSPAssemblyVersionElementCount>$([System.String]::Copy('%(Reference.KSPAssemblyVersion)').Split('.').Length)</KSPAssemblyVersionElementCount>
</Reference>
<ProjectReference Update="%(ProjectReference.identity)" Condition="'%(ProjectReference.KSPAssemblyName)' != ''">
<KSPAssemblyVersion Condition="'%(ProjectReference.KSPAssemblyVersion)' == ''">$(FileVersion)</KSPAssemblyVersion>
<KSPAssemblyVersionElementCount>$([System.String]::Copy('%(ProjectReference.KSPAssemblyVersion)').Split('.').Length)</KSPAssemblyVersionElementCount>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="KSPAssemblyDependency" Condition="'%(Reference.KSPAssemblyName)' != ''">
<_Parameter1>%(Reference.KSPAssemblyName)</_Parameter1>
<_Parameter1_TypeName>System.String</_Parameter1_TypeName>
<_Parameter2>$([System.String]::Copy('%(Reference.KSPAssemblyVersion)').Split('.')[0])</_Parameter2>
<_Parameter2_TypeName>System.Int32</_Parameter2_TypeName>
<_Parameter3>$([System.String]::Copy('%(Reference.KSPAssemblyVersion)').Split('.')[1])</_Parameter3>
<_Parameter3_TypeName>System.Int32</_Parameter3_TypeName>
<_Parameter4 Condition="%(Reference.KSPAssemblyVersionElementCount) > 2">$([System.String]::Copy('%(Reference.KSPAssemblyVersion)').Split('.')[2])</_Parameter4>
<_Parameter4_TypeName Condition="%(Reference.KSPAssemblyVersionElementCount) > 2">System.Int32</_Parameter4_TypeName>
</AssemblyAttribute>
<AssemblyAttribute Include="KSPAssemblyDependency" Condition="'%(ProjectReference.KSPAssemblyName)' != ''">
<_Parameter1>%(ProjectReference.KSPAssemblyName)</_Parameter1>
<_Parameter1_TypeName>System.String</_Parameter1_TypeName>
<_Parameter2>$([System.String]::Copy('%(ProjectReference.KSPAssemblyVersion)').Split('.')[0])</_Parameter2>
<_Parameter2_TypeName>System.Int32</_Parameter2_TypeName>
<_Parameter3>$([System.String]::Copy('%(ProjectReference.KSPAssemblyVersion)').Split('.')[1])</_Parameter3>
<_Parameter3_TypeName>System.Int32</_Parameter3_TypeName>
<_Parameter4 Condition="%(ProjectReference.KSPAssemblyVersionElementCount) > 2">$([System.String]::Copy('%(ProjectReference.KSPAssemblyVersion)').Split('.')[2])</_Parameter4>
<_Parameter4_TypeName Condition="%(ProjectReference.KSPAssemblyVersionElementCount) > 2">System.Int32</_Parameter4_TypeName>
</AssemblyAttribute>
</ItemGroup>
</Target>
<!-- Target to generate the KSP version json file for AVC/CKAN etc-->
<Target Name="KSPBT_GenerateVersionFile" AfterTargets="Build"
Inputs="@(KSPVersionFile);$(FileVersion)" Outputs="%(KSPVersionFile.destination)"
Condition=" '$(KSPBT_GenerateVersionFile)' == 'true' ">
<ItemGroup>
<KSPVersionFile Update="@(KSPVersionFile)">
<Name Condition="'%(KSPVersionFile.Name)' == ''">$(ProjectName)</Name>
<Version Condition="'%(KSPVersionFile.Version)' == ''">$(FileVersion)</Version>
</KSPVersionFile>
</ItemGroup>
<ReadLinesFromFile File="%(KSPVersionFile.identity)" Condition="Exists('@(KSPVersionFile)')">
<Output TaskParameter="Lines" ItemName="_JSONLines"/>
</ReadLinesFromFile>
<PropertyGroup>
<_JSON>@(_JSONLines, '%0a')</_JSON>
<_JSON Condition="'@(_JSONLines)' == ''">{}</_JSON>
</PropertyGroup>
<JsonPoke Content="$(_JSON)" Query="$.NAME" RawValue="'%(KSPVersionFile.Name)'">
<Output TaskParameter="Content" PropertyName="_JSON"/>
</JsonPoke>
<JsonPoke Content="$(_JSON)" Query="$.VERSION" RawValue="'%(KSPVersionFile.Version)'">
<Output TaskParameter="Content" PropertyName="_JSON"/>
</JsonPoke>
<JsonPoke Content="$(_JSON)" Query="$.URL" RawValue="'%(KSPVersionFile.URL)'" Condition="'%(KSPVersionFile.URL)' != ''">
<Output TaskParameter="Content" PropertyName="_JSON"/>
</JsonPoke>
<JsonPoke Content="$(_JSON)" Query="$.DOWNLOAD" RawValue="'%(KSPVersionFile.Download)'" Condition="'%(KSPVersionFile.Download)' != ''">
<Output TaskParameter="Content" PropertyName="_JSON"/>
</JsonPoke>
<JsonPoke Content="$(_JSON)" Query="$.KSP_VERSION" RawValue="'%(KSPVersionFile.KSP_Version)'" Condition="'%(KSPVersionFile.KSP_Version)' != ''">
<Output TaskParameter="Content" PropertyName="_JSON"/>
</JsonPoke>
<JsonPoke Content="$(_JSON)" Query="$.KSP_VERSION_MIN" RawValue="'%(KSPVersionFile.KSP_Version_Min)'" Condition="'%(KSPVersionFile.KSP_Version_Min)' != ''">
<Output TaskParameter="Content" PropertyName="_JSON"/>
</JsonPoke>
<JsonPoke Content="$(_JSON)" Query="$.KSP_VERSION_MAX" RawValue="'%(KSPVersionFile.KSP_Version_Max)'" Condition="'%(KSPVersionFile.KSP_Version_Max)' != ''">
<Output TaskParameter="Content" PropertyName="_JSON"/>
</JsonPoke>
<WriteLinesToFile File="%(KSPVersionFile.Destination)" Lines="$(_JSON)" Overwrite="true"/>
<Message Text="Writing JSON version file to %(KSPVersionFile.Destination)"/>
<Message Text="Contents:%0a$(_JSON)" Importance="low"/>
</Target>
<!-- Copy DLLs to mod GameData folder-->
<Target Name="KSPBT_CopyDLLsToPluginFolder" AfterTargets="CopyFilesToOutputDirectory"
Condition=" '$(KSPBT_CopyDLLsToPluginFolder)' == 'true'">
<ItemGroup>
<_BinariesToCopy Include="$(TargetDir)/**/*.dll"/>
<_BinariesToCopy Include="$(TargetDir)/**/*.pdb" Condition="'$(Configuration)' == 'Debug'"/>
</ItemGroup>
<MakeDir Directories="$(KSPBT_ModRoot)/$(KSPBT_ModPluginFolder)"/>
<Copy SourceFiles="@(_BinariesToCopy)" DestinationFolder="$(KSPBT_ModRoot)/$(KSPBT_ModPluginFolder)/%(RecursiveDir)"/>
</Target>
</Project>