<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Luka Hedt on Medium]]></title>
        <description><![CDATA[Stories by Luka Hedt on Medium]]></description>
        <link>https://medium.com/@lhedt?source=rss-8095c013768f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CSDPyBF0iO4SCHmM9h_Wpw.jpeg</url>
            <title>Stories by Luka Hedt on Medium</title>
            <link>https://medium.com/@lhedt?source=rss-8095c013768f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:54:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lhedt/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Connecting to an SVN Server via SSH for the First Time with TortoiseSVN]]></title>
            <link>https://lhedt.medium.com/connecting-to-an-svn-server-via-ssh-for-the-first-time-with-tortoisesvn-7af24fb843e4?source=rss-8095c013768f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7af24fb843e4</guid>
            <category><![CDATA[tortoisesvn]]></category>
            <category><![CDATA[subversion]]></category>
            <category><![CDATA[svn]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[puttygen]]></category>
            <dc:creator><![CDATA[Luka Hedt]]></dc:creator>
            <pubDate>Mon, 03 May 2021 06:45:55 GMT</pubDate>
            <atom:updated>2021-05-03T06:45:55.022Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*AnSmqMlH3ivbm8DsDbhOgw.png" /></figure><p>This tutorial is designed for use in conjunction with the server setup tutorial I’ve written here: C<a href="https://lhedt.medium.com/creating-an-ssh-enabled-subversion-server-on-linux-7873f0aa5e4">reating An SSH-Enabled Subversion Server On Linux</a>.</p><p>For this tutorial, we will assume you are connecting using TortiseSVN on a windows machine.</p><h3>Required Downloads:</h3><ul><li><a href="https://tortoisesvn.net/downloads.html">TortoiseSVN</a></li><li><a href="https://www.puttygen.com/download.php?val=49">PuTTYgen</a></li></ul><h3>1. Generate SSH Keys using PuTTYgen</h3><p>You may skip this step if you have an existing RSA Key Pair you wish to use, but keep in mind that TortoiseSVN requires the private key to be in .ppk (putty private key) format. <a href="https://www.simplified.guide/putty/convert-ssh-key-to-ppk">You can covert an openSSH key pair using PuttyGen</a>.</p><ol><li>Install PuTTYgen on your local machine.</li></ol><p>2. Open PuTTYgen and ensure the settings are as follows:</p><ul><li>Number of bits &gt;= 2048</li><li>Key type = RSA</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*nIeHXrZtmN-72Ik4rlB7Hg.png" /></figure><p>Hit Generate</p><p>3. Move the mouse around a bit, as it says on the screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*gR9huwB0GZ0BRizoifsIdQ.png" /></figure><p>4. You will be greeted with a screen like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*JNuaKycEvq8zejk33sBhug.png" /></figure><p>Enter a Key Comment and optionally, a passphrase. <strong>If you enter a passphrase, it will ask you for it every time you connect to SVN</strong>.</p><p>5. Hit “Save public key” and save the key to a known location. I will save mine to C:\Users\&lt;USER&gt;\.ssh\SvnKey.pub as it is my public key, and should go in the folder with my other ssh keys.</p><p>6. Hit “Save private key” to save the private key. I will save mine to C:\Users\&lt;USER&gt;\.ssh\SvnKey.ppk.</p><p>7. Contact the SVN Administrator and give them a copy of your <strong>Public Key</strong> (ie, the .pub file, not the .ppk file). Once you&#39;ve done so, wait for them to give you the green light. They will provide you with an endpoint that will look like the following: svn+ssh://&lt;USER&gt;@&lt;HOSTNAME&gt;/&lt;(Optional) PathToRepo&gt;/&lt;RepoName&gt;. They may also give you a port number which we will set up below.</p><h3>2. Connecting to the Repo using TortoiseSVN</h3><p>We will set up the SVN Connection using TortoiseSVN with a custom port and the .ppk file we generated earlier.</p><ol><li>Download and Install TortoiseSVN.</li><li>Create a folder where the project will be stored. Mine will be at C:\Users\&lt;USER&gt;\Desktop\Projects\SampleProject</li><li>Right-Click to open the context menu, and go TortoiseSVN -&gt; Settings:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*GuLQAdU_mbsCizIknUuJBA.png" /></figure><p>4. Go to Network Settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*HL-scroTvGLw6boxzdPMcw.png" /></figure><p>5. We need to set the SSH Client up for SVN. We will use TortoisePLink as the client, and set the port and identification keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*OdY27E0zggJGfTml66-1pw.png" /></figure><p>In the box, type the following:</p><p>C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe -p 22 -i &#39;C:\Users\&lt;USER&gt;\.ssh\SvnKey.ppk&#39;</p><p>Where:</p><ul><li>C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe is the path to the PLink Executable (Should have been installed with TortoiseSVN.)</li><li>-p 22 is specifying the SSH port number (provided by the SVN Admin). 22 is the default port number, so if the admin doesn&#39;t give you a port, you can leave this part out.</li><li>-i &#39;C:\Users\&lt;USER&gt;\.ssh\SvnKey.ppk&#39; sets the path to the private key we generated above. Obviously your use won&#39;t be &lt;USER&gt;, so make sure to set this to your windows username.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*i9OTdksvGUVsNuIBt0P5Mw.png" /></figure><p>6. Hit Apply and OK to save your settings.</p><h3>3. Checkout the Repository</h3><ol><li>Right click again and select “SVN Checkout”</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*Ct1kqHT2fUFVnVwDTmNxQQ.png" /></figure><p>2. Enter the URL the admin provided you and hit “OK”. The clone should begin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*GVsT7DfQN28Sx29bpDjbvQ.png" /></figure><p>Hit “OK” once complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*AnSmqMlH3ivbm8DsDbhOgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*p9G2Elt49SvQ2nvJiGoqiQ.png" /></figure><p>Congrats! The project is now cloned, and you are set up to contribute.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7af24fb843e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an SSH-enabled Subversion Server on Linux]]></title>
            <link>https://lhedt.medium.com/creating-an-ssh-enabled-subversion-server-on-linux-7873f0aa5e4?source=rss-8095c013768f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7873f0aa5e4</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[svn]]></category>
            <category><![CDATA[subversion]]></category>
            <dc:creator><![CDATA[Luka Hedt]]></dc:creator>
            <pubDate>Mon, 03 May 2021 06:33:51 GMT</pubDate>
            <atom:updated>2021-05-03T06:48:09.209Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h_2bIGzHbp5wuHiFFh7oLg.png" /></figure><p>After messing around with various version control systems for Unity with on-premises hosting, our team has settled on using Subversion. Below I’ll detail how to set up the server with SSH password-less authentication, but first, here’s our findings for other VCSs.</p><ul><li>Unity Collaborate: It was mind-numbingly slow (updating single files could take 15 minutes plus to recompile), and we found we had very painful merge conflicts more often than not, especially in scenes. Also, it’s cloud-hosted in a mystery location, which makes it unsuitable for some projects where code must be kept in specific locations.</li><li>PlasticSCM: This worked okay, but it doesn’t come cheap, and the client seems to be somewhat buggy. It does branching and merging just fine, but the merge conflict resolution isn’t nearly as good as they make it out to be. Sometimes we’d just plain lose connection to the server for no apparent reason. It’s a workable solution for sure, but we became frustrated enough with it to try something different.</li><li>Git: Git is awesome, and would probably do the job just fine, except git-lfs is surprisingly hard to set up. Using it with Azure Repos, the upload speed was capped at about half a megabit per second (My network speed is 40x that), which is just too slow for our use. I tried to set up my Raspberry Pi as a remote, but git-lfs is not 100% ssh-authentication compatible, and there was little to no documentation on setting upyour own lfs remote.</li></ul><p>In this tutorial, we will set up a fresh Raspberry Pi 4 as a Subversion Server that allows authentication and transmission over SSH using the svn+ssh protocol.</p><p>Connection instructions from a remote client can be found in the tutorial here: <a href="https://lhedt.medium.com/connecting-to-an-svn-server-via-ssh-for-the-first-time-with-tortoisesvn-7af24fb843e4">Connecting To An SVN Server via SSH for the First Time with TortoiseSVN</a></p><h3>Disclaimer:</h3><p>I am not an SVN expert by any means, nor am I a security expert. Do not take my advice as gospel.</p><p>Instructions are based off the following: <a href="https://www.startupcto.com/server-tech/subversion/setting-up-svn">Setting Up Subversion (SVN) with SSH (svn+ssh) | StartupCTO</a>.</p><h3>Synopsis</h3><p>What we are creating here is a Subversion Server that stores the repositories on the Pi’s SD card, and that users connect to using the svn+ssh protocol. All connections will connect through the SSH port, meaning we only need to expose a single port to the internet.</p><p>Users will be able to connect password-lessly to their own unix user account using the RSA authentication method in SSH. These users will be added to a group which has read/write perms for the entire repository, which will prevent permission issues (described here: <a href="http://svnbook.red-bean.com/en/1.5/svn.serverconfig.multimethod.html">Supporting Multiple Repository Access Methods (red-bean.com)</a>).</p><h3>Instructions for Setting Up an SVN Server</h3><h3>0. Set up Raspberry Pi</h3><p>Install Raspberry Pi OS and create your pi user, etc.</p><p>From here on in, we will ssh into the pi as the pi user and configure everything from there, unless otherwise stated.</p><h3>1. Install Subversion</h3><p>SSH into the pi and run:</p><pre>sudo apt-get install subversion</pre><p>This will install all subversion tools required to run the server and the client locally.</p><h3>2. Create a repository</h3><p>This is where your files will be stored. We will create the repository root at /var/svn/repos because we can.</p><ol><li>Run the following to create the repository:</li></ol><pre>sudo mkdir -p /var/svn/repos</pre><p>2. Create a group to own the repos directory.</p><pre>sudo addgroup svn<br>sudo chown -R :svn /var/svn/repos/<br>sudo chmod -R 2775 /var/svn/repos/</pre><p>Note that using chmod -R 2775 will ensure all child directories in /var/svn/repos/ will be read/writable by the svn group. This is critical to prevent permission clashes.</p><p>3. Add the “pi” user to the svn group for testing. You can remove them later.</p><pre>sudo adduser pi svn</pre><p>Note that running “adduser” won’t create a new user if the user already exists.</p><p>4. Create the repository using the svnadmin command. This will initialise a fresh repo and being serving it. The name of the repo in this case will be &quot;TestRepo&quot;, and this will be the URL extension we use to get here later.</p><pre>sudo svnadmin create /var/svn/repos/TestRepo</pre><p>5. As a precaution, we need to check that the svn group we created earlier can write to the /var/svn/repos/TestRepo/db/ directory and all its children.</p><p>We will run the command</p><pre>ls -al /var/svn/repos/TestRepo/db/</pre><p>The output should look something like this:</p><pre>pi@raspberrypi:~ $ ls -al /var/svn/repos/TestRepo/db/<br>total 60<br>drwxrwsr-x 6 root svn 4096 Apr 23 12:14 .<br>drwxrwsr-x 6 root svn 4096 Apr 23 10:34 ..<br>-rwxrwxr-x 1 root svn 2 Apr 23 12:14 current<br>-rwxrwxr-x 1 root svn 41 Apr 23 10:34 format<br>-rwxrwxr-x 1 root svn 10835 Apr 23 10:34 fsfs.conf<br>-rwxrwxr-x 1 root svn 5 Apr 23 10:34 fs-type<br>-rwxrwxr-x 1 root svn 2 Apr 23 10:34 min-unpacked-rev<br>drwxrwsr-x 3 root svn 4096 Apr 23 10:34 revprops<br>drwxrwsr-x 3 root svn 4096 Apr 23 10:34 revs<br>drwxrwsr-x 2 root svn 4096 Apr 23 12:14 transactions<br>-rwxrwxr-x 1 root svn 2 Apr 23 12:14 txn-current<br>-rwxrwxr-x 1 root svn 0 Apr 23 10:34 txn-current-lock<br>drwxrwsr-x 2 root svn 4096 Apr 23 12:14 txn-protorevs<br>-rwxrwxr-x 1 root svn 74 Apr 23 10:34 uuid<br>-rwxrwxr-x 1 root svn 0 Apr 23 10:34 write-lock</pre><p>And not like this:</p><pre>pi@raspberrypi:~ $ ls -al /var/svn/repos/TestRepo/db<br>total 60<br>drwxr-sr-x 6 root svn 4096 Apr 23 17:26 .<br>drwxr-sr-x 6 root svn 4096 Apr 23 17:26 ..<br>-rw-r - r - 1 root svn 2 Apr 23 17:26 current<br>-r - r - r - 1 root svn 41 Apr 23 17:26 format<br>-rw-r - r - 1 root svn 10835 Apr 23 17:26 fsfs.conf<br>-rw-r - r - 1 root svn 5 Apr 23 17:26 fs-type<br>-rw-r - r - 1 root svn 2 Apr 23 17:26 min-unpacked-rev<br>drwxr-sr-x 3 root svn 4096 Apr 23 17:26 revprops<br>drwxr-sr-x 3 root svn 4096 Apr 23 17:26 revs<br>drwxr-sr-x 2 root svn 4096 Apr 23 17:26 transactions<br>-rw-r - r - 1 root svn 2 Apr 23 17:26 txn-current<br>-rw-r - r - 1 root svn 0 Apr 23 17:26 txn-current-lock<br>drwxr-sr-x 2 root svn 4096 Apr 23 17:26 txn-protorevs<br>-rw-r - r - 1 root svn 74 Apr 23 17:26 uuid<br>-rw-r - r - 1 root svn 0 Apr 23 17:26 write-lock</pre><p>In particular, most of the lines on the files should begin with the prefix -rwxrwxr-x, not -rw-r--r--. If this is not the case, you will receive permission denied errors when you try to import files.</p><p>To fix this, we simply run</p><pre>sudo chmod -R 2775 /var/svn/repos/TestRepo/db/</pre><p>and repeat step 5.</p><h3>3. Create a wrapper for svnserve</h3><p>When a user runs a command via the svn+ssh protocol, the subversion server runs the bash script svnserve to complete the action. Unfortunately, this would typically spawn a process from the subversion server, with its running user as the user. This will potentially cause permissions issues as it creates files as the subversion server user, not as the svn group.</p><p>Thankfully we can solve this by wrapping the svnserve command in our own baby .sh script that runs it with a umask call.</p><ol><li>Create a file somewhere like /var/svn/svnwrapper.sh with the following contents:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/938a7ba9682f44675f4a14209d0b3fb2/href">https://medium.com/media/938a7ba9682f44675f4a14209d0b3fb2/href</a></iframe><p>2. Make a symlink in usr/local/bin by running the following commands:</p><pre>cd /usr/local/bin<br>ln -s /var/svn/svnwrapper.sh svnserve<br>sudo chmod 755 /var/svn/svnwrapper.sh</pre><h3>4. Import some code into the repository</h3><p>Now we can import some sample files into the repo to test that everything works. Let’s create a file and import it:</p><ol><li>Run the following to create a file to import</li></ol><pre>cd<br>echo &quot;This is a test file!&quot; &gt;&gt; code/testfile.txt</pre><p>2. Run the following to import the “code” directory into the repo, and then delete the copy from the user’s home directory.</p><pre>svn import code svn+ssh://pi@localhost/TestRepo -m &#39;Inital import&#39;<br>rm -rf code</pre><p>That’s it, we now have a server set up!</p><h3>5. Test the checkout with the Pi user on your local machine</h3><p>Exit the ssh session using the command exit.</p><p>From your local machine with subversion installed, run the command:</p><pre>svn co svn+ssh://pi@&lt;raspberryPiAddress&gt;/TestRepo &lt;Path To Local Directory To Download To&gt;</pre><p>Alternatively, if you’re on Windows, you can use TortoiseSVN, entering svn+ssh://pi@&lt;raspberryPiAddress&gt;/TestRepo in the download URL.</p><p>Once completed, you should see your test file in the path provided.</p><h3>Instructions for Adding Users with Password-less SSH Authentication</h3><p>This section assumes you have access to RSA keys for the user. I’m going to create a user “luka” and use ssh-keygen on my local machine to create my rsa keys.</p><h3>0. Generate an ssh key on your local machine.</h3><p>Simply run ssh-keygen and fill in the prompts to get yourself a valid key. Take note of where it&#39;s saved (by default C:\Users\&lt;USER&gt;\.ssh\id_rsa(.pub) on windows.) Copy the public key contents somewhere you have easy access to it.</p><p>The key should follow the format: ssh-rsa AA....&lt;Rest of key&gt; &lt;Comment&gt;. If it doesn&#39;t, you will need to take the AA....&lt;Rest of key&gt; part and format it as such when importing it.</p><h3>1. Create a new Unix User on the Raspberry Pi</h3><p>SSH into the pi and run the command</p><pre>sudo adduser luka<br>sudo adduser luka svn</pre><p>where luka is the name of the new user. Input a password and whatever information you feel like putting in. This will create the user and add them to the svn group.</p><p><strong>Note</strong> that the svn group must have been created at this point.</p><h3>2. Set up their SSH Key</h3><p>What we want to do is add the key we created earlier (or a provided key from the user) to a file in their home directory called .ssh/authorized_keys. Effectively this will let them ssh in to the pi without using their password.</p><p><strong>OPTIONAL: Restrict the user from accessing the terminal via ssh</strong>: We can prevent the user from ssh’ing into a valid shell from their own computer by prepending their ssh key with the phrase no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty in the authorized_keys file. This is not a security guarantee but it might prevent some silliness if users get a little keen on probing the system. ie: where you&#39;d have &quot;ssh-rsa AA....&lt;Rest of the RSA Public Key&gt; &lt;Comment&gt;&quot; in the file, you want &quot;no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AA....&lt;Rest of the RSA Public Key&gt; &lt;Comment&gt;&quot;</p><p>Run the command:</p><pre>echo &quot;ssh-rsa AA....&lt;Rest of the RSA Public Key&gt; &lt;Comment&gt;&quot; &gt;&gt; /home/luka/.ssh/authorized_keys</pre><p>to append the given key to the list of users keys, where luka is the name of your user.</p><p>And you’re done! Provide the user with the URL of the server in the rough format svn+ssh://&lt;Their username&gt;@&lt;RaspberryPiAddress&gt;/&lt;NameOfRepository&gt;, and inform them if you are using a non-standard port. Make sure to open the port in your network firewall if necessary (recall 22 is the standard port for ssh, and the only port you need to open for this to work.)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7873f0aa5e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Standalone Unity Projects with FAKE and Unity Build Scripts]]></title>
            <link>https://lhedt.medium.com/building-standalone-unity-projects-with-fake-and-unity-build-scripts-ab82251d71b6?source=rss-8095c013768f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab82251d71b6</guid>
            <category><![CDATA[fsharp]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[build-script]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[fake]]></category>
            <dc:creator><![CDATA[Luka Hedt]]></dc:creator>
            <pubDate>Tue, 09 Mar 2021 21:33:01 GMT</pubDate>
            <atom:updated>2021-03-09T21:33:01.497Z</atom:updated>
            <content:encoded><![CDATA[<p>Unity’s build tools can be somewhat of a challenge to automate with CI/CD Tools. Unity Builds themselves can be quite slow, and if you have complicated build procedures with specific build settings, scripting the build process and letting it run on a dedicated build machine is a huge effort-saver.</p><p>Unity does offer CloudBuild as a solution for this problem, however it is far from perfect, and some of the projects I’ve worked on have required that the solution stays entirely on managed machines, so CloudBuild was not suitable.</p><p>The F# Language with its <a href="https://fake.build/">FAKE</a> library is a very neat solution that can streamline the entire unity build process, and run it in concert with CI/CD tools like Team City or Jenkins if required.</p><p>Upon completing this guide, you will have a template for a Unity Build solution that builds the project for Windows Standalone x86, Windows Standalone x64, and Linux, that runs Unit Tests with the Unity Test Runner, and packages all 3 applications in a ZIP file.</p><p>This guide is inspired by the wonderful guide by Jon Peppers at <a href="http://jonathanpeppers.com/Blog/automating-unity3d-builds-with-fake">Automating Unity3D Builds with FAKE | Jonathan Peppers’ Blog</a></p><h3>You Will Need</h3><ul><li><a href="https://dotnet.microsoft.com/download">Dotnet Core SDK 3.1+</a> for your host machine.</li><li>Unity 2019.4.x+ installed. This should run with earlier versions of Unity3D, however YMMV.</li><li>A text editor. I personally use <a href="https://code.visualstudio.com/">VSCode</a> with the <a href="https://ionide.io/">Ionide</a> extensions.</li></ul><h3>Directory Setup</h3><p>I have been using the Unity Go-Kart tutorial for testing of this environment, and naming the project <strong>Karter.</strong> You may replace any reference to this with your own project name.</p><p>I haven’t set this directory up with any CI/CD Tools yet, you may wish to restructure it as you see fit.</p><pre>Desktop<br>--&gt; UnityProjects<br>-- --&gt; Karter<br>-- -- --&gt; Karter (Unity Project File)<br>-- -- --&gt; KarterBuilds</pre><p>The build scripts and supporting <em>accoutrement</em> will be in the root Karter directory, and I&#39;ll assume this is the working directory (./) from here on in.</p><p>(Builds will be output into the KarterBuilds directory)</p><h3>Setting Up FAKE</h3><p>FAKE is a build tool used in the F# community for most everything. It runs on Dotnet, and can be deployed to almost any environment, including build agents. We will be following a section of their <a href="https://fake.build/fake-gettingstarted.html">Getting Started Guide</a>.</p><ol><li>Navigate to your root directory (Karter as above) in your chosen shell. (Powershell will work just fine)</li><li>Install FAKE as a local dotnet tool with the following commands:</li></ol><pre>dotnet new tool-manifest<br>dotnet tool install fake-cli</pre><p>3. Install and run the FAKE template to create a sample buildscript.</p><pre>dotnet new -i &quot;fake-template::*&quot;<br>dotnet new fake</pre><p>This will generate in your root directory the following file structure.</p><pre>.config<br>build.fsx<br>fake.cmd<br>fake.sh<br>Karter (Your Unity Project)<br>KarterBuilds</pre><p>build.fsx will be our build instruction file, and the sample they&#39;ve provided will generate a regular dotnet application&#39;s build. We can delete everything in here, we will create our own as we go.</p><h3>Creating a Unity Buildscript</h3><p>Unity kindly provides an option to run the build system from CommandLine using an editor script. Documentation is <a href="https://docs.unity3d.com/Manual/CommandLineArguments.html">here</a>, but for the sake of simplicity, I’ll assume we have installed Unity on our machine using Unity Hub, and have signed in with our license.</p><p>To actually build the application, we need an Editor Script with a number of static functions inside. We can call these using the commandline tools.</p><p>I’ll provide a simple sample that simply builds the project as Windows Standalone x64. A more complete version with build numbers and such will be available below.</p><p>This file should be created in in the path UnityProjectRoot/Assets/Editor/Buildscript.cs. The Editor directory is paramount, as if you don&#39;t put the file in here, the build system that goes through the unity editor will try and fail to compile it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52478c6c9b70ec99652840a40df5ab1e/href">https://medium.com/media/52478c6c9b70ec99652840a40df5ab1e/href</a></iframe><p>Let’s just dissect this file a little for first-timers before we move on to the fun stuff.</p><p>We have:</p><ul><li>Some Constants (The project name and some configuration variables for file name output)</li><li>A variable for the output directory</li><li>A Constructor that reads Environment Variables.</li><li>A Static Function that builds the application and exits with 0 on success, or 1 on failure. <br><strong>Note</strong> that the Windows build filename must end in .exe. This is the name of the launch file, and the supporting files will be named by Unity as normal.</li><li>A static function that gets all the enabled scenes from the EditorBuildSettings.</li></ul><p>The constructor will be run whenever the Unity application is started via command line, and then we will run the function BuildWindows_x64, and read the result from the shell.</p><h3>A Basic FAKE Script</h3><p>So now we need to run this buildscript from the commandline, using FAKE. FAKE files tend to look fairly confusing to begin with, so we’ll work from a blank build.fsx file and build up as we go.</p><p><strong>0. Loading Libraries</strong></p><p>We should begin by loading the FAKE supporting libraries from nuget. Let’s add the following to the very top of our script.</p><pre>#r “paket:<br>nuget Fake.DotNet.Cli<br>nuget Fake.IO.FileSystem<br>nuget Fake.Core.Target //”<br>#load “.fake/build.fsx/intellisense.fsx”</pre><p>The first directive will load some FAKE supporting libraries from nuget using the PAKET package manager (the preferred F# package tool).</p><p>The second will load intellisense for your script for use in vscode.</p><p>Note that these will only download these libraries once we actually run the script using the FAKE tool. Intellisense may be unhelpful until then.</p><ol><li><strong>Adding Project Constants</strong></li></ol><p>We should next add some constants that we can refer to elsewhere in the script, like the project name and paths.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b396744a6473a0d0671f90c508f421f/href">https://medium.com/media/0b396744a6473a0d0671f90c508f421f/href</a></iframe><p><strong>2. Getting the Unity Editor Installation Path</strong></p><p>To run unity via commandline, we need to know where the executable is. We can use FAKE’s environment sensing tool to get the right path for the right system.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddc08778caa3e451b0c13eb98640b30e/href">https://medium.com/media/ddc08778caa3e451b0c13eb98640b30e/href</a></iframe><p>Note that if you are not using 2019.4.21f, or if your installation folder is elsewhere, you will need to replace the strings with the appropriate path.</p><p><strong>3. Running Unity via shell script</strong></p><p>Now we have all the basics in place, we can create a function to run the buildscript inside Unity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d45c5e123290d232282dee57898f30c/href">https://medium.com/media/8d45c5e123290d232282dee57898f30c/href</a></iframe><p>Okay let’s break this down a smidge. We have a Shell command being run and writing it’s result to the result variable.</p><p>The command is a combination of UnityPath, the function that gets our Unity.exe file path, and the output of (sprintf &quot;-quit -batchmode -logFile Build.log -projectPath \&quot;%s\&quot; -executeMethod BuildScript.BuildWindows_x64&quot; UnitySolutionPath).</p><p>sprintf just formats the string, so we can just insert the Solution Path constant we defined where %s is.</p><p>The arguments passed to Unity are the interesting section.</p><ul><li>-quit quits the application when done.</li><li>-batchmode runs the script in an automation mode, supressing anything a human might need to click on.</li><li>-logFile Build.log creates the log file for the build at the current working directory. This can be helpful for debugging a build failure.</li><li>-projectPath &quot;&lt;Relative Path to Unity Solution Folder&gt;&quot; indicates to Unity which project to load.</li><li>-executeMethod BuildScript.BuildWindows_x64 runs the function we created earlier. Note that BuildScript was the name of the class.</li></ul><p><strong>Note</strong> that RunUnity needs to take some value as input. If this isn&#39;t set, for some reason the application won&#39;t read the environment variables. We will improve on this later.</p><p><strong>4. Setting the Output Directory</strong></p><p>We need to set the output directory so that Unity doesn’t do something inconvenient like put the build in the %AppData% folder. We can do this by setting Environment Variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14478cb340fa2fc6de33722900f2c14e/href">https://medium.com/media/14478cb340fa2fc6de33722900f2c14e/href</a></iframe><p>So now we have a function to create and log environment variables, and also a variable that corresponds to an Environment Variable Name. We are attaching the Project Name to the Environment Variable as it gives us more flexibility if you decide to use a single build agent for multiple projects at once.</p><p><strong>5. Creating FAKE Targets</strong></p><p>FAKE lets us define different “Targets”, which are small code snippets to run. We can input targets into the command line when we run the FAKE script, or we can set a default to run when there is no target provided.</p><p>We can also indicate a dependency tree — ie list which targets are required to complete a specific one.</p><p>I’m going to write 3 targets below that run when you run the fake script by default. First we will set up the environment (&quot;Setup&quot;), then run the build script (&quot;BuildWin64&quot;), then we will just print the finishing time, though we could do some further cleanup or packaging.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/281181a44e2de16dbf328a17dfdc9e81/href">https://medium.com/media/281181a44e2de16dbf328a17dfdc9e81/href</a></iframe><p><strong>6. Bring it all Together</strong></p><p>So now with all the pieces, we have a build.fsx file that looks like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3571677bcccbed3fd6bf8c4ce08865fd/href">https://medium.com/media/3571677bcccbed3fd6bf8c4ce08865fd/href</a></iframe><p>Note that I’ve added some open statements throughout the script. These are simply the same as using in C#, and open libraries for use.</p><p><strong>7. Running the FAKE Script</strong></p><p>Now you can run the script with the command</p><p>dotnet fake run</p><p>This will fetch all the Dotnet libraries required, and run the build script.</p><h3>Adding Versioning to the Application</h3><p>One of the bigger advantages of using CI/CD is to be able to name and version your builds. Most CI/CD tools can be set up to provide the version number to the build agent, and we will demonstrate one method below.</p><p>Our versioning will default to the format X.X.X.X_xxxxxxxx, where the left-hand-side uses Semantic Versioning, and the right-hand-side is the start of a GUID. eg: 1.0.1.1_efc09ga.</p><p>We will create a folder with this name under the KarterBuilds, and put the builds in it. We&#39;ll also move the Log files into this folder by adjusting the Unity Build Arguments.</p><p>Add the following lines under the open statements at the top of the build.fsx file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab0fb86c0dfc053c43e5c7ce7da2fa14/href">https://medium.com/media/ab0fb86c0dfc053c43e5c7ce7da2fa14/href</a></iframe><p>We should also adjust the Setup target to write environment variables for these values. We&#39;ll then adjust the BuildScript in Unity to read the Build&#39;s Full Name and write it to the player settings.</p><p>Replace the “Setup” Target with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44e2b3d3912ffd6dfaf8d76a29d55cb9/href">https://medium.com/media/44e2b3d3912ffd6dfaf8d76a29d55cb9/href</a></iframe><p>Note that for Build and Version number we are using the phrase (Environment.environVarOrDefault DefaultVersionNumber). This will allow us to define these variables using the command line like so:</p><pre>dotnet fake build -e KARTER_VERSION_NUMBER=1.1.1.1 -e KARTER_BUILD_NUMBER=ef8901hc</pre><p>We also should adjust the Unity Shell Command to push the build log to this folder.</p><p>Replace the RunUnity function with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba564bfccf71d5ba1fb1c1a41eaaf592/href">https://medium.com/media/ba564bfccf71d5ba1fb1c1a41eaaf592/href</a></iframe><p>Now we have versioning! In the Unity BuildScript, you can add the version number to the build by adding the following excerpt to the constructor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ad02b442867b396b772844a8d12e99f/href">https://medium.com/media/3ad02b442867b396b772844a8d12e99f/href</a></iframe><h3>Running Unity Unit Tests before the Build</h3><p>Game Developers don’t always write Unit Tests, however if you do have a number set up in the Unity Test Runner, they can be set up with an extra Target. They’re run quite similarly to the build, but we need to change some parameters.</p><p>Set up a new target like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98072ad54872b80f2bdffa66f62712f9/href">https://medium.com/media/98072ad54872b80f2bdffa66f62712f9/href</a></iframe><p>And add it to the dependency tree like so:</p><pre>(* *** Dependency Trees *** *)</pre><pre>&quot;Setup&quot;<br>==&gt; &quot;UnitTest&quot;<br>==&gt; &quot;BuildWin64&quot;<br>==&gt; &quot;Packaging&quot;</pre><pre>(* *** End Dependency Trees *** *)</pre><p>The Test Results.xml file will be output to the Build Folder, as well as the log file for the test run. You can set up your CI/CD Software to parse this xml file.</p><p>You can also run PlayMode tests in this manner if you have the set up by switching the tag -testPlatform editmode to -testPlatform playmode.</p><h3>Zipping the Output directory</h3><p>Now we should look into deployment. There are various ways one might wish to deploy the build or otherwise make it accessible to users. I will assume that we are simply going to zip the output directory. Moving it to another folder is trivial, and has been left as an exercise to the reader.</p><p>Let’s replace the “Packaging” stage with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd2484bf71b27e09b6f31b2ad1224514/href">https://medium.com/media/bd2484bf71b27e09b6f31b2ad1224514/href</a></iframe><p>Now the output file will also be zipped, and can be moved or uploaded at will.</p><h3>Adding Other Build Targets</h3><p>Let’s add the Linux and Windows x86 Build targets.</p><p>Add the following to the BuildScript.cs file to allow FAKE to target these formats.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63c7b31a5dd16d5fa793787d4ce1b8e3/href">https://medium.com/media/63c7b31a5dd16d5fa793787d4ce1b8e3/href</a></iframe><p><strong>Note</strong> that the Linux built file must end in .x86_64, and windows builds must end in .exe. This is the name of the launch file, and the supporting files will be named by Unity as normal.</p><p>Now we have added build functions for the different build targets, we need to add shell commands to execute them.</p><p>We also need to create FAKE targets for these items, as they cannot be run in parallel (as Unity won’t allow more than one instance to be open at any time).</p><p>Let’s add a type near the top of the script to give us some way of indicating which script we want to run to Unity nicely.</p><pre>type BuildTarget = WindowsX86 | WindowsX64 | Linux</pre><p>Now let’s refactor RunUnity to take this in and run a different script based on this value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81f6e5cd5b16340bb2bb976ae422f276/href">https://medium.com/media/81f6e5cd5b16340bb2bb976ae422f276/href</a></iframe><p>And we need to make sure we change the existing target to now take in WindowsX64 as the buildtarget. We can also add targets for Winx86 and Linux.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68e8c092b02924ab163c75c2ddd848c8/href">https://medium.com/media/68e8c092b02924ab163c75c2ddd848c8/href</a></iframe><p>Note we’ve changed the Target Name and the RunUnity parameter.</p><p>Finally, let’s update the dependency tree, and test what we have.</p><pre>(* *** Dependency Trees *** *)</pre><pre>&quot;Setup&quot;<br>==&gt; &quot;UnitTest&quot;<br>==&gt; &quot;BuildWin64&quot;<br>==&gt; &quot;BuildWinx86&quot;<br>==&gt; &quot;BuildLinux&quot;<br>==&gt; &quot;Packaging&quot;</pre><pre>(* *** End Dependency Trees *** *)</pre><p>Now we can run it using</p><p>dotnet fake run</p><p>And once complete, the output zip file should contain builds for all 3 targets!</p><h3>A Note on the Burst Compiler</h3><p>Unity’s Burst Compiler is still dependent on native compilation tools. As such, when compiling for Linux on Windows (or Vice Versa), you may find the build crashes for some reason that isn’t well described.</p><p>If required, you can turn the burst compiler off using the tag -burst-disable-compilation in the command line.</p><h3>Conclusion and Final Script</h3><p>So now we have created a full Build Pipeline for Unity!</p><p>Below are the final scripts I have created for reference.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebb5b0ffa3d09c1e69a1b2d9538fa9cb/href">https://medium.com/media/ebb5b0ffa3d09c1e69a1b2d9538fa9cb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab82251d71b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>