Jump to content

Mod Adoption Tutorial


linuxgurugamer

Recommended Posts

AweUmd6.png?1

 

A forum user, @Murdabenne requested that I share how to do an adoption of a mod.

So, last week I showed an adoption while on Twitch Stream, and have finished writing up the steps here.  The video is available at the end of the OP.

These instructions and the files are available on Github: https://github.com/linuxgurugamer/KSP-Build-Scripts/

They are all licensed using the GPLv3

This process has evolved over time;  the first mods I adopted didn't use these, and each one was a customized setup.  As time went on I developed this process, with the following goals in mind:

  • Consistency
  • Repeatability
  • Ease of setup
  • Easy to follow

While not perfect, they do the job for me.  Occasionally I run into a mod which has an odd layout or setup, which  can usually be dealt with by rearranging folders, or some other minor changes.

This discussion will not be going into any issues about coding or bug fixing,etc.  

These scripts are based on the following directory layout:

modmaindir
   |-> GameData
          |-> ModDir
                 |-> Plugins
   |-> Sourcedir

The GameData should contain all files needed for a release

Abbreviations used

VS - Visual Studio

IDE - Integrated Development Environment

 

Overview and Dependencies

These scripts are based on the following directory layout:

modmaindir
   |-> GameData
          |-> ModDir
                 |-> Plugins
   |-> Sourcedir

The GameData should contain all files needed for a release

Overview and Dependencies

Dependencies

Overview

  • Part of the process involves adding a file, AssemblyVersion.tt, to the codebase.  This file is called a "Text Template", and is used to create the AssemblyVersion value which is then stored in the final DLL
  • There are two batch files, deploy.bat and buildRelease.bat.  The "deploy.bat" used to copy the DLL to the GameData directory, and  then to copy the complete release to a test install.  The "buildRelease.bat" is used to create the final zip file for release
  • While the packaging program can be changed to an alternative (with appropriate changes to the "buildRelease.bat" file, the JQ program is required and not replacable.
  • The assumption is also made that the mod is downloaded and ready to be worked on.

Instructions

1.  Create the GameData folder if it doesn't exist

  • If it doesn't exist, then copy the latest release of the mod into the GameData folder

2.  Find the .version file (if it exists) and copy it to the top level directory.

  • If it doesn't have a .version file, create one in the top level directory

3.  You can either copy the AssemblyVersion.tt to the main mod folder, or create a new TextTemplate in the project (using MS Studio) and do a copy/paste operation.  If you copy it over, you will need to add the file to the  project in the IDE

4.  Edit the AssemblyVersion.tt file, update the following line:

string versionfile =  @"CompletePathTo.version";

Replace the "CompletePathTo.version" with the path to the .version file.

5.  Remove or comment out the following line from the file AssemblyInfo.cs (usually located in the "Properties" folder inside your C# project):

[assembly: AssemblyVersion("1.0.0.0")]

6.  If there are any Pre-build steps in VS, copy them to a save place and delete them.  

7.  If there are an Post-build steps in VS, copy them as well


8.  Add the following to the Pre-build event command line.  This line is based on using Visual Studio 2017, installed on the X drive:

    set textTemplatingPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\IDE\texttransform.exe"

    %textTemplatingPath% "$(ProjectDir)AssemblyVersion.tt"


0.  Copy the two files, deploy.bat and buildRelease.bat to the main mod folder

10.  You need to update the deploy.bat and the buildRelease.bat with the following values:

H to point to your test KSP install:             set H=R:\KSP_1.3.1_dev
GAMEDIR to the name of the mod folder:           set GAMEDIR=xxxxx
GAMEDATA to point to the GameData folder:        GAMEDATA="GameData"
VERSIONFILE to the name of the .version file:    VERSIONFILE=%GAMEDIR%.version

In most cases, the VERSIONFILE is built from the GAMEDIR, but some mods use a different name

11.  For the buildRelease.bat, you have to update the following as well:

If existing, LICENSE to the license file:          set LICENSE=License.txt
If existing, README to the Readme file:            README=ReadMe.md
Set RELEASEDIR to where you want the zip file:     RELEASEDIR=d:\Users\jbb\release

12.  If you want to use a different program than 7z, change it in the next line.  If you do, you will have to change the options to the zip program at the end of the file:

set ZIP="c:\Program Files\7-zip\7z.exe"

13.  In the IDE, right-click on the Solution in the Solution Explorer, and select "Add -> New Solution Folder", give the folder a name SolutionItems

14.  Right-click on the SolutionItems folder, and select Add -> Existing item..., add the two files just copied and the .version file

15.  Add the following to the Post-build event command line, replace the "xxxxx" with the complete path to the top level directory of the mod:

    start /D xxxxx /WAIT deploy.bat  $(TargetDir) $(TargetFileName)

    if $(ConfigurationName) == Release (

        start /D xxxxx /WAIT buildRelease.bat $(TargetDir) $(TargetFileName)

    )

16.  Make sure the .version file has the correct values.

17.  Now, set the Visual Studio configuration to Debug, and do a test compile.  

18.  If all is correct, it will compile the code, copy the DLL to the destination folder, and then copy the complete release to your test KSP installation

19.  Finally, change the VS config to "Release" and rebuild the mod.  This time it will add the step to pack up the entire release and leave it in the RELEASEDIR

 

I did an online stream when I used most of this to adopt a small mod, you can watch it here:


      

Edited by linuxgurugamer
TOTM!
Link to comment
Share on other sites

35 minutes ago, dundun92 said:

Nice tutorial! Can it be used to compile 1.3.x mods to 1.2.2? Ive seen it done before, just dont know how.

Yes, except that many mods for 1.3.x will contain references to c# methods which don't exist in 1.2.2, so you will have to do some recoding around the missing methods

Link to comment
Share on other sites

2 hours ago, Supergamervictor said:

Hi @linuxgurugamer,

I'm completely inexperienced with KSP plugin development and I'm trying to compile a mod from 1.1.3 to 1.2.2 (01010101lzy's procedural wings, which has a larger limit for wing size). Looking through the source, it seems there are references not found in 1.2.2? In this case, what should I do?

Did you update the references in VS to the correct dlls?

there were lots of other changes going from 1.1.3 to 1.2.2, you should checkout the notes for that time 

Link to comment
Share on other sites

5 hours ago, linuxgurugamer said:

Did you update the references in VS to the correct dlls?

there were lots of other changes going from 1.1.3 to 1.2.2, you should checkout the notes for that time 

I did, and I also cross referenced Crzyrndm's commits to fix the errors. However one error seems to elude me: 

'PartResourceDefinitionList' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'PartResourceDefinitionList' could be found (are you missing a using directive or an assembly reference?)

Not sure if I can post the code here, but any guess on what reference or code I should be fixing here?

Link to comment
Share on other sites

8 hours ago, linuxgurugamer said:

You can PM me if you want, but I would need to see the code, if its on github, send me the link

Here's the source: https://github.com/01010101lzy/B9-PWings-Fork-old,

and this is the cross reference I used: https://github.com/Crzyrndm/B9-PWings-Fork/commit/63a4ad8dfafd2b61626386745f7748623d41badb

Link to comment
Share on other sites

1 hour ago, Supergamervictor said:

I need to see the code you have, not what you forked from

Link to comment
Share on other sites

On 13.10.2017 at 2:15 PM, linuxgurugamer said:

8.  Add the following to the Pre-build event command line.  This line is based on using Visual Studio 2017, installed on the X drive:


    set textTemplatingPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\IDE\texttransform.exe"

    %textTemplatingPath% "$(ProjectDir)AssemblyVersion.tt"

Great Tutorial, i could use some help

I get a error message if i try to build a solution for "assembly.version.tt" with the pre-build event. The output window shows Build: 1 failed and shows the error:

Spoiler

error MSB3073: The command "set textTemplatingPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\IDE\texttransform.exe"
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1274,5): error MSB3073:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1274,5): error MSB3073: %textTemplatingPath% "E:\Kerbal Space Program - Mods\Mods 1.3.0\RealismOverhaulCompile\RealismOverhaul-master\Source\AssemblyVersion.tt"" exited with code 1.

Do i have to change my directory path for the pre build event to work? or what does "installed on the X drive" mean?

Thanks for any help!

 

Link to comment
Share on other sites

I started over and tried compiling the maneuverqueue mod from fathand for 1.3.0, like you did in your video (for 1.3.1).

I create the .version file and update the version number and put the complete path into the assemblyversion.tt (->string versionfile = path). Everytime i put the path in assemblyversion.tt the assemblyversion.cs gets automaticly filled [assembly: AssemblyVersion("0.4.8.0")] with the correct version.
But i cant build a solution, i always get the error massage:
 

There is the exception that a file is not found(...\debug\EnvDTE), the file doesnt exist in fathands maneuverqueue master file....

Spoiler

1>------ Build started: Project: ManeuverQueue_Project, Configuration: Debug Any CPU ------
1>EXEC : error : An exception was thrown while trying to compile the transformation code. The following Exception was thrown:
1>  System.IO.FileNotFoundException: Die Datei "E:\Kerbal Space Program - Mods\Mods 1.3.0\ManeuverQueueCompile\ManeuverQueue_KSP1.2\bin\Debug\EnvDTE" konnte nicht gefunden werden.
1>  Dateiname: "E:\Kerbal Space Program - Mods\Mods 1.3.0\ManeuverQueueCompile\ManeuverQueue_KSP1.2\bin\Debug\EnvDTE"
1>     bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1>     bei System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
1>     bei System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
1>     bei Roslyn.Utilities.FileUtilities.OpenFileStream(String path)
1>     bei Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation)
1>     bei Microsoft.VisualStudio.TextTemplating.CompilerBridge.<>c.<.ctor>b__15_0(String x)
1>     bei System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
1>     bei System.Linq.Enumerable.<UnionIterator>d__66`1.MoveNext()
1>     bei System.Linq.Enumerable.<UnionIterator>d__66`1.MoveNext()
1>     bei System.Linq.Buffer`1..ctor(IEnumerable`1 source)
1>     bei System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
1>     bei System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
1>     bei Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
1>     bei Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
1>     bei Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(IEnumerable`1 references)
1>     bei Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonWithReferences(IEnumerable`1 newReferences)
1>     bei Microsoft.VisualStudio.TextTemplating.CompilerBridge.PrepareNewCompilation()
1>     bei Microsoft.VisualStudio.TextTemplating.CompilerBridge.Compile()
1>     bei Microsoft.VisualStudio.TextTemplating.TransformationRunner.Compile(String source, String inputFile, IEnumerable`1 references, Boolean debug, SupportedLanguage language, String compilerOptions)
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1274,5): error MSB3073: The command "set textTemplatingPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\IDE\texttransform.exe"
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1274,5): error MSB3073:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1274,5): error MSB3073: %textTemplatingPath% "E:\Kerbal Space Program - Mods\Mods 1.3.0\ManeuverQueueCompile\ManeuverQueue_KSP1.2\AssemblyVersion.tt"" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 


 

 

Link to comment
Share on other sites

  • 2 months later...

Im pretty new here still. But i see you take over a vast majority of dead mods and update em.  Do you have a list of mods not being maintained by original authors? Do you scour the forums for days on end? Hehe. I was gonna see if I could find an easy difficulty one and see what I could do. I find myself thinking of a good idea. Turns out its already a mod, and most the time you already took up the mantle lol. Feel like im in the Simpsons. And they already did it :)

Not to say I dont appreciate the hard work. I defiantly do. I think we all do.

Link to comment
Share on other sites

  • 6 months later...
On 10/26/2017 at 3:40 PM, linuxgurugamer said:

Everything needed for c#

I think I have that (enough to build CKAN, anyway), and I get that same EnvDTE exception when trying to msbuild KSPAddonVersionChecker:

EXEC : error : An exception was thrown while trying to compile the transformation code. The following Exception was thrown: [C:\Users\user\github\KSPAddonVersionChecker\KSP-AVC\KSP-AVC.csproj]
  System.IO.FileNotFoundException: Could not find file 'C:\Users\user\github\KSPAddonVersionChecker\Output\KSP-AVC\EnvDTE'.
  File name: 'C:\Users\user\github\KSPAddonVersionChecker\Output\KSP-AVC\EnvDTE'
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share,
  Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boo
  lean checkHost)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
     at Roslyn.Utilities.FileUtilities.OpenFileStream(String path)
     at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationP
  rovider documentation)
     at Microsoft.VisualStudio.TextTemplating.CompilerBridge.<>c.<.ctor>b__15_0(String x)
     at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
     at System.Linq.Enumerable.<UnionIterator>d__67`1.MoveNext()
     at System.Linq.Enumerable.<UnionIterator>d__67`1.MoveNext()
     at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
     at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
     at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
     at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
     at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
     at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(IEnumerable`1 references)
     at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonWithReferences(IEnumerable`1 newReferences)
     at Microsoft.VisualStudio.TextTemplating.CompilerBridge.PrepareNewCompilation()
     at Microsoft.VisualStudio.TextTemplating.CompilerBridge.Compile()
     at Microsoft.VisualStudio.TextTemplating.TransformationRunner.Compile(String source, String inputFile, IEnumerable`1 reference
  s, Boolean debug, SupportedLanguage language, String compilerOptions)

What is EnvDTE, anyway?

Link to comment
Share on other sites

1 minute ago, HebaruSan said:

I think I have that (enough to build CKAN, anyway), and I get that same EnvDTE exception when trying to msbuild KSPAddonVersionChecker:


EXEC : error : An exception was thrown while trying to compile the transformation code. The following Exception was thrown: [C:\Users\user\github\KSPAddonVersionChecker\KSP-AVC\KSP-AVC.csproj]
  System.IO.FileNotFoundException: Could not find file 'C:\Users\user\github\KSPAddonVersionChecker\Output\KSP-AVC\EnvDTE'.
  File name: 'C:\Users\user\github\KSPAddonVersionChecker\Output\KSP-AVC\EnvDTE'
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share,
  Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boo
  lean checkHost)
     at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
     at Roslyn.Utilities.FileUtilities.OpenFileStream(String path)
     at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationP
  rovider documentation)
     at Microsoft.VisualStudio.TextTemplating.CompilerBridge.<>c.<.ctor>b__15_0(String x)
     at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
     at System.Linq.Enumerable.<UnionIterator>d__67`1.MoveNext()
     at System.Linq.Enumerable.<UnionIterator>d__67`1.MoveNext()
     at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
     at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
     at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
     at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
     at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
     at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(IEnumerable`1 references)
     at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonWithReferences(IEnumerable`1 newReferences)
     at Microsoft.VisualStudio.TextTemplating.CompilerBridge.PrepareNewCompilation()
     at Microsoft.VisualStudio.TextTemplating.CompilerBridge.Compile()
     at Microsoft.VisualStudio.TextTemplating.TransformationRunner.Compile(String source, String inputFile, IEnumerable`1 reference
  s, Boolean debug, SupportedLanguage language, String compilerOptions)

What is EnvDTE, anyway?

Check the version of .net, it should be 3.5

See this for some info:

https://docs.microsoft.com/en-us/dotnet/api/envdte.property?view=visualstudiosdk-2017

Link to comment
Share on other sites

28 minutes ago, linuxgurugamer said:

Check the version of .net, it should be 3.5

No change, still getting the same exception.

EDIT: It didn't install. The installer for 3.5 that I found doesn't do anything. I'll try again with another one...

Quote

That doesn't seem to discuss why this textranslate tool is looking for a file or directory that doesn't exist in the Output folder, or how to get it to appear there. Are there other steps that need to be done before msbuild will work?

Edited by HebaruSan
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...