Skip to content

Commit e26bf74

Browse files
authored
Check for KSPRoot based on Assembly-CSharp.dll (#34)
Instead of checking for buildID.txt or GameData, check for the Assembly-CSharp.dll. This search is skipped if KSPRoot or KSP_ROOT are declared in environment variables or a .user file, and that value taken as-is.
1 parent b8b6095 commit e26bf74

File tree

2 files changed

+49
-33
lines changed

2 files changed

+49
-33
lines changed

KSPCommon.props

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,67 @@
44
<KSPCommonPropsImported>true</KSPCommonPropsImported>
55
</PropertyGroup>
66

7-
<!-- import the csproj.user file. This might not be a good idea -->
7+
<!-- default CKAN compatibility versions -->
8+
<PropertyGroup>
9+
<CKANCompatibleVersions Condition="('$(CKANCompatibleVersions)' == '')">1.12 1.11 1.10 1.9 1.8</CKANCompatibleVersions>
10+
</PropertyGroup>
11+
12+
<!--Parse KSP platform-specific paths -->
13+
<!-- These can be overwritten by user and props files -->
14+
<PropertyGroup Condition=" '$(ManagedRelativePath)' == '' ">
15+
<ManagedRelativePath Condition="$([MSBuild]::IsOsPlatform('Windows'))">KSP_x64_Data\Managed</ManagedRelativePath>
16+
<ManagedRelativePath Condition="$([MSBuild]::IsOsPlatform('OSX'))">KSP.app\Contents\Resources\Data\Managed</ManagedRelativePath>
17+
<ManagedRelativePath Condition="$([MSBuild]::IsOsPlatform('Linux'))">KSP_Data\Managed</ManagedRelativePath>
18+
</PropertyGroup>
19+
<PropertyGroup>
20+
<KSPExecutable Condition="$([MSBuild]::IsOsPlatform('Windows'))">KSP_x64.exe</KSPExecutable>
21+
<KSPExecutable Condition="$([MSBuild]::IsOsPlatform('OSX'))">KSP.app/Contents/MacOS/KSP</KSPExecutable>
22+
<KSPExecutable Condition="$([MSBuild]::IsOsPlatform('Linux'))">KSP.x86_64</KSPExecutable>
23+
<SteamKSPRoot Condition="($([MSBuild]::IsOsPlatform('Windows')))">C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program</SteamKSPRoot>
24+
<SteamKSPRoot Condition="($([MSBuild]::IsOsPlatform('OSX')))">$(HOME)/Library/Application Support/Steam/steamapps/common/Kerbal Space Program</SteamKSPRoot>
25+
</PropertyGroup>
26+
27+
<!-- Calculate mod paths -->
28+
<!-- These can be overwritten by user, csproj, and props files -->
29+
<PropertyGroup>
30+
<!-- The root directory of the mod repository -->
31+
<RepoRootPath Condition=" '$(RepoRootPath)' == '' ">$(SolutionDir.TrimEnd([System.IO.Path]::DirectorySeparatorChar))</RepoRootPath>
32+
<BinariesOutputRelativePath Condition=" '$(BinariesOutputRelativePath)' == '' ">GameData/$(SolutionName)</BinariesOutputRelativePath>
33+
</PropertyGroup>
34+
35+
<!-- Import the csproj.user file. -->
36+
<!-- This can overwrite ManagedRelativePath and KSPExecutable,
37+
set KSPRoot and ReferencePath, and any other user-specific settings -->
838
<Import Project="$(MSBuildProjectFullPath).user" Condition="Exists('$(MSBuildProjectFullPath).user')"/>
939

10-
<!--import solution-wide props if it exists -->
40+
<!-- Import a props.user file -->
41+
<!-- serves the same role as the csproj.user file -->
42+
<Import Condition=" Exists('$(SolutionDir)$(SolutionName).props.user') " Project="$(SolutionDir)$(SolutionName).props.user"/>
43+
44+
<!-- Import solution-wide props if it exists -->
1145
<Import Condition=" Exists('$(SolutionDir)$(SolutionName).props') " Project="$(SolutionDir)$(SolutionName).props"/>
1246

13-
<!-- The following properties can be customized per-mod in SolutionName.props-->
1447
<PropertyGroup>
15-
<!-- The root directory of the mod repository -->
16-
<RepoRootPath Condition = " '$(RepoRootPath)' == '' ">$(SolutionDir.TrimEnd([System.IO.Path]::DirectorySeparatorChar))</RepoRootPath>
17-
<BinariesOutputRelativePath Condition = " '$(BinariesOutputRelativePath)' == '' ">GameData\$(SolutionName)</BinariesOutputRelativePath>
48+
<!-- Relative path that must exist for a path to be a valid KSP Install-->
49+
<KSPRootIdentifier>$(ManagedRelativePath)/Assembly-CSharp.dll</KSPRootIdentifier>
1850

1951
<!-- Default KSPRoot to the "KSP_ROOT" environment variable if it exists -->
20-
<KSPRoot Condition=" '$(KSPRoot)' == '' And '$(KSP_ROOT)' != ''">$(KSP_ROOT)</KSPRoot>
52+
<!-- Doing this skips any checks for a valid KSP install so be careful! -->
53+
<KSPRoot Condition=" '$(KSPRoot)' == '' And '$(KSP_ROOT)' != '' ">$(KSP_ROOT)</KSPRoot>
2154

22-
<!-- look for a KSP installation in SolutionDir -->
23-
<KSPRoot Condition = " '$(KSPRoot)' == '' And Exists('$(SolutionDir)KSP/GameData')">$(SolutionDir)KSP</KSPRoot>
55+
<!-- Look for KSP install in Solution dir -->
56+
<KSPRoot Condition=" '$(KSPRoot)' == '' And Exists('$(SolutionDir)KSP/$(KSPRootIdentifier)') ">$(SolutionDir)KSP</KSPRoot>
2457

25-
<!-- use ReferencePath if it exists and is a valid KSP install -->
26-
<KSPRoot Condition = " '$(KSPRoot)' == '' And Exists('$(ReferencePath)GameData')">$(ReferencePath.TrimEnd([System.IO.Path]::DirectorySeparatorChar))</KSPRoot>
58+
<!-- Look for KSP install in ReferencePath -->
59+
<KSPRoot Condition=" '$(KSPRoot)' == '' And Exists('$(ReferencePath)/$(KSPRootIdentifier)') ">$(ReferencePath)</KSPRoot>
2760

28-
<!--If the reference path isn't set, use the default steam location, but this will be incorrect in lots of cases-->
29-
<SteamKSPRoot Condition = "($([MSBuild]::IsOsPlatform('Windows')))">C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program</SteamKSPRoot>
30-
<SteamKSPRoot Condition = "($([MSBuild]::IsOsPlatform('OSX')))">$(HOME)/Library/Application Support/Steam/steamapps/common/Kerbal Space Program</SteamKSPRoot>
31-
<KSPRoot Condition = "'$(KSPRoot)' == '' And Exists('$(SteamKSPRoot)/GameData')">$(SteamKSPRoot)</KSPRoot>
61+
<!-- Look for KSP steam install-->
62+
<KSPRoot Condition=" '$(KSPRoot)' == '' And Exists('$(SteamKSPRoot)/$(KSPRootIdentifier)') ">$(SteamKSPRoot)</KSPRoot>
3263

33-
<!-- default CKAN compatibility versions -->
34-
<CKANCompatibleVersions Condition="('$(CKANCompatibleVersions)' == '')">1.12 1.11 1.10 1.9 1.8</CKANCompatibleVersions>
64+
<!-- Calculate ManagedPath -->
65+
<ManagedPath>$(KSPRoot)/$(ManagedRelativePath)</ManagedPath>
3566
</PropertyGroup>
3667

37-
<!--Import a props.user file if it exists, so that KSPRoot can be set globally for the whole mod if desired-->
38-
<Import Condition=" Exists('$(SolutionDir)$(SolutionName).props.user') " Project="$(SolutionDir)$(SolutionName).props.user"/>
39-
40-
<!--Parse KSP platform-specific paths -->
41-
<PropertyGroup Condition = " '$(ManagedRelativePath)' == '' ">
42-
<ManagedRelativePath Condition = "$([MSBuild]::IsOsPlatform('Windows'))">KSP_x64_Data\Managed</ManagedRelativePath>
43-
<ManagedRelativePath Condition = "$([MSBuild]::IsOsPlatform('OSX'))">KSP.app\Contents\Resources\Data\Managed</ManagedRelativePath>
44-
<ManagedRelativePath Condition = "$([MSBuild]::IsOsPlatform('Linux'))">KSP_Data\Managed</ManagedRelativePath>
45-
</PropertyGroup>
46-
<PropertyGroup>
47-
<KSPExecutable Condition = "$([MSBuild]::IsOsPlatform('Windows'))">KSP_x64.exe</KSPExecutable>
48-
<KSPExecutable Condition = "$([MSBuild]::IsOsPlatform('OSX'))">KSP.app/Contents/MacOS/KSP</KSPExecutable>
49-
<KSPExecutable Condition = "$([MSBuild]::IsOsPlatform('Linux'))">KSP.x86_64</KSPExecutable>
50-
<ManagedPath>$(KSPRoot)\$(ManagedRelativePath)</ManagedPath>
51-
</PropertyGroup>
52-
5368
<!-- set the start action so that you can launch directly from VS -->
5469
<PropertyGroup>
5570
<StartAction>Program</StartAction>

KSPCommon.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<Target Name="CheckForKSPRoot" BeforeTargets="ResolveReferences" Condition="'$(KSPRoot)' == ''">
1414
<Error Text="KSPBuildTools was unable to find a KSP installation. Please set the ReferencePath or KSPRoot property in your csproj.user file to a valid KSP installation directory (the one with GameData in it)"/>
15+
<Message Text="Found KSPRoot at $(KSPRoot)" Importance="low"/>
1516
</Target>
1617

1718
<!-- Copy output files to mod folder -->

0 commit comments

Comments
 (0)