I'm getting an error saying that these two files are already referenced (presumably from Unity already). Should I remove them and replace with the ones from the KSP folder?
I've got things mostly working (I think?), but there is no logging happening in the console. In ksp.log, there's this line which is confusing me:
There's no reference to ContractDefs in my code, anyone know what gives?
Started from scratch a few times... oddly enough, the last iteration showed a similar problem as what I've seen consistently in my attempts to mod KSP, where I can access KSP assets but can't reference MonoBehaviour. I was trawling through many threads on the forums to figure it out, and when I looked back at my IDE, there were no more errors. I'm flabbergasted, but pleased. I will try again, to try to hammer down the exact process, and share when I have it.
As promised, a detailed walk-through of a repeatable mod dev setup. I'm using KSP 1.9, but I'm pretty sure 1.8 used the same unity version, so it should work for 1.8.x as well. I'm also using Visual Studio 2017 on Windows 10, though afaik the VS version matters less.
Start Visual Studio. Close any open projects, and create a new project as shown in the image:
(NOTE: I tested a few different options here, including .NET Standard and .NET Core class libraries, which did NOT work. Though I admit, I wasn't keeping very good track of what I had and hadn't tried when I was testing those options, so feel free to try them at your own risk.)
I suggest the location to be somewhere near you KSP dev folder, but it doesn't need to be.
.NET 4.0 is required, and .NET 4.5 is recommended for 1.8+, per the wiki
Hit OK, and VS will create the project. For some reason, I had to close VS and open the solution (.sln) file by double click because VS kept saying it was still building the project, but it obviously had finished. Regardless, once you have your project open and set up, you then need to select references. I've seen a few different variations on what dll's need referenced. After a lot of experimentation, it seems that the *minimum* to reference are:
Side note: I was shocked to find that UnityEngine.dll is *not* a requirement for the basic script in the OP, but you will need it to do a lot of things.
To add them, click on the Project tab, then Add Reference, then browse. Navigate to your KSP directory/KSP_x64_data/Managed folder, and select the above files:
(You can see how much testing I did in that pic with different versions, etc... to find that only those two little dlls are necessary)
Once you have your references, you should be good to go from the OP and other posts in the Add-On subforum.
Hope this helps other beginner modders!
As an aside, learning Unity outside of a mod dev environment is really helpful for modding. I've been using Unity for a couple years now, mostly just for messing around with building my own small games, but because of that I'm very confident in actually coding KSP mods - it was just setting up the environment that was tripping me up for so long.
Edit 4: I guess I should mention a bit about compiling - once you're ready to compile and test your code, it's useful (imo) to point your build directory to your mod's folder. Then hit build, and go to your mod folder. You'll have to delete all the other files the IDE generates, you only need YourMod.dll for the game to do its thing. Unfortunately that's something you''ll have to do every time you build it. I haven't tested it, but its possible they won't hurt anything being there for testing, but imo its best to test as closely to release as possible.