title: Unity5 project does not build for PC Standalone, on Windows with external Visual Studio version (2017)
body: <p>Although it's only remotely related to programming, here it goes:</p>
  
  <p>Since last week, I've been playing with <em>Unity (5.6.0f3 <strong>Community</strong> x64)</em> on <em>Win 10 (x64)</em> - using <em>Visual Studio (2017 <strong>Community</strong>)</em> as attached editor, as <em>Unity</em> "requires" -, and started with the <a href="https://unity3d.com/learn/tutorials" rel="nofollow noreferrer">[Unity]: Tutorials</a> (first of them). For a few days everything went just fine, but then, building for <em>PC Standalone</em> target, stopped working. <em>Google</em>ing and checking the forums, didn't help finding information about this exact behavior:</p>
  
  <p><a href="https://i.stack.imgur.com/CDLY5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CDLY5.jpg" alt="PC Standalone build"></a></p>
  
  <p>As seen on the <em>Build Settings</em> dialog (moved to the right), there are no (<em>Target Platform</em> or <em>Architecture</em>) combo-boxes allowing to specify build parameters. Errors are on the left side.</p>
  
  <p><strong>Notes</strong> (about the current behavior):</p>
  
  <ul>
  <li>First guess was that the tutorial project became somehow messed up, so I created a new one from scratch (a dummy / simple one containing one <em>Sphere</em> having attached a <em>Rigidbody</em> and a <em>C#</em> script that applies forces based on user input), but it behaves the same (this is the project build output in the above image)</li>
  <li><em>WebGL</em> build runs just fine (loads in browser); this is the workaround currently used, but it takes ages to complete</li>
  <li><em>Play</em>ing (obviously) also works (needless to say that things are <em>OK</em> in <em>VStudio</em>, no complains from <em>csc</em>), <strong>!!!but!!!</strong> after trying (and failing) to build, <em>Play</em>ing no longer works (reloading the project is the only way to fix it)</li>
  </ul>
  
  <p>To rule out any possible doubts, here's a <em>DownloadAssistant</em> screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/2iUet.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2iUet.jpg" alt="Download Assistant"></a></p>
  
  <p>Everything is checked, there are 2 items (not very relevant to this case) that are not showing (because the window is not sizeable), but they are checked (and <strong>installed</strong>).</p>
  
  <p><strong>Background info</strong>:</p>
  
  <ul>
  <li>When first installing <em>Unity</em>, there was no <em>VStudio 2017</em> version present on the computer, so it (<em>Community Edition</em>) was installed as part of <em>Unity</em> install process (I remember (at least) one <em>VStudio</em> related combo-box in the <em>Assistant</em>)</li>
  <li>Then, a <em>VStudio</em> patch was available; when preparing to install it, I realized that <em>VStudio</em> was installed on the default path (on <em>%SYSTEMDRIVE%</em>), which doesn't work for me, since it's a large product, so:
  
  <ul>
  <li>Uninstalled it</li>
  <li>Reinstalled it (directly from <a href="https://www.visualstudio.com/downloads" rel="nofollow noreferrer">[VisualStudio]: Visual Studio Downloads</a>) on a different drive (and yes, I am aware that changing the install path, still installs a pretty big part like <em>Windows SDK</em> on <em>%SYSTEMDRIVE%</em>)</li>
  <li>Since I thought that the above 2 steps would break the link between <em>Unity</em> and the new <em>VStudio</em>, I also reinstalled <em>Unity</em>. This time, there were no <em>VStudio</em> related check-boxes in the <em>Assistant</em> (seems normal to check if any piece of software that it needs to install, isn't already installed <sup><strong>1</strong></sup>). Later on, I also found a persistent (meaning that it's not wiped out at <em>Unity</em> uninstall time) <em>RegValue</em> (<em>HKEY_CURRENT_USER\SOFTWARE\Unity Technologies\Installer\Select_VisualStudio</em>) with a value of <strong><em>0</em></strong> (as opposed to a bunch of other values under the same key with values of <em>1</em>)</li>
  </ul></li>
  <li>After that, I reinstalled <em>Unity</em> several times, including reboots (not required) between uninstall / install, but no result (I also took a long shot of enabling the <em>RegVaue</em> above before starting <em>Assistant</em>)</li>
  </ul>
  
  <p>A little debugging revealed that when trying to build (<em>PC Standalone</em>), <em>Unity</em> does something like this (don't mind the paths, it's how they're on my machine), that can be reproduced from <em>cmdline</em>:</p>
  
  <p><em>build_win.bat</em>:</p>
  
  <blockquote>
  <pre><code>"E:\Install\x64\Unity\5.6.0f3\Editor\Data\MonoBleedingEdge\bin\mono.exe" "E:\Install\x64\Unity\5.6.0f3\Editor\Data\MonoBleedingEdge\lib\mono\4.5\mcs.exe" "@args-win.txt"
  </code></pre>
  </blockquote>
  
  <p><em>args_win.txt</em>:</p>
  
  <pre><code>-debug
  -target:library
  -nowarn:0169
  -langversion:4
  -out:Temp/Assembly-CSharp.dll
  -unsafe
  -optimize
  -r:E:/Install/x64/Unity/5.6.0f3/Editor/Data/UnityExtensions/Unity/GUISystem/Standalone/UnityEngine.UI.dll
  -r:E:/Install/x64/Unity/5.6.0f3/Editor/Data/UnityExtensions/Unity/Networking/Standalone/UnityEngine.Networking.dll
  -r:E:/Install/x64/Unity/5.6.0f3/Editor/Data/UnityExtensions/Unity/UnityAnalytics/UnityEngine.Analytics.dll
  -define:UNITY_5_3_OR_NEWER
  -define:UNITY_5_4_OR_NEWER
  -define:UNITY_5_5_OR_NEWER
  -define:UNITY_5_6_OR_NEWER
  -define:UNITY_5_6_0
  -define:UNITY_5_6
  -define:UNITY_5
  -define:UNITY_ANALYTICS
  -define:ENABLE_AUDIO
  -define:ENABLE_CACHING
  -define:ENABLE_CLOTH
  -define:ENABLE_DUCK_TYPING
  -define:ENABLE_GENERICS
  -define:ENABLE_PVR_GI
  -define:ENABLE_MICROPHONE
  -define:ENABLE_MULTIPLE_DISPLAYS
  -define:ENABLE_PHYSICS
  -define:ENABLE_RUNTIME_NAVMESH_BUILDING
  -define:ENABLE_SPRITERENDERER_FLIPPING
  -define:ENABLE_SPRITES
  -define:ENABLE_TERRAIN
  -define:ENABLE_RAKNET
  -define:ENABLE_UNET
  -define:ENABLE_LZMA
  -define:ENABLE_UNITYEVENTS
  -define:ENABLE_WEBCAM
  -define:ENABLE_WWW
  -define:ENABLE_CLOUD_SERVICES_COLLAB
  -define:ENABLE_CLOUD_SERVICES_ADS
  -define:ENABLE_CLOUD_HUB
  -define:ENABLE_CLOUD_PROJECT_ID
  -define:ENABLE_CLOUD_SERVICES_UNET
  -define:ENABLE_CLOUD_SERVICES_BUILD
  -define:ENABLE_CLOUD_LICENSE
  -define:ENABLE_EDITOR_METRICS
  -define:ENABLE_EDITOR_METRICS_CACHING
  -define:ENABLE_NATIVE_ARRAY
  -define:INCLUDE_DYNAMIC_GI
  -define:INCLUDE_GI
  -define:PLATFORM_SUPPORTS_MONO
  -define:RENDER_SOFTWARE_CURSOR
  -define:INCLUDE_PUBNUB
  -define:ENABLE_PLAYMODE_TESTS_RUNNER
  -define:ENABLE_SCRIPTING_NEW_CSHARP_COMPILER
  -define:ENABLE_VIDEO
  -define:UNITY_STANDALONE_WIN
  -define:UNITY_STANDALONE
  -define:ENABLE_SUBSTANCE
  -define:ENABLE_RUNTIME_GI
  -define:ENABLE_MOVIES
  -define:ENABLE_NETWORK
  -define:ENABLE_CRUNCH_TEXTURE_COMPRESSION
  -define:ENABLE_UNITYWEBREQUEST
  -define:ENABLE_CLOUD_SERVICES
  -define:ENABLE_CLOUD_SERVICES_ANALYTICS
  -define:ENABLE_CLOUD_SERVICES_PURCHASING
  -define:ENABLE_CLOUD_SERVICES_CRASH_REPORTING
  -define:ENABLE_EVENT_QUEUE
  -define:ENABLE_CLUSTERINPUT
  -define:ENABLE_VR
  -define:ENABLE_WEBSOCKET_HOST
  -define:ENABLE_MONO
  -define:NET_2_0_SUBSET
  Assets/_Scripts/x.cs
  -r:E:\Install\x64\Unity\5.6.0f3\Editor\Data\Mono\lib\mono\unity\System.Runtime.Serialization.dll
  -r:E:\Install\x64\Unity\5.6.0f3\Editor\Data\Mono\lib\mono\unity\System.Xml.Linq.dll
  -r:E:\Install\x64\Unity\5.6.0f3\Editor\Data\Mono\lib\mono\unity\UnityScript.dll
  -r:E:\Install\x64\Unity\5.6.0f3\Editor\Data\Mono\lib\mono\unity\UnityScript.Lang.dll
  -r:E:\Install\x64\Unity\5.6.0f3\Editor\Data\Mono\lib\mono\unity\Boo.Lang.dll
  -sdk:unity
  </code></pre>
  
  <p><em>args_win.txt</em> is a copy of one of the <em>${PROJECT_ROOT}\Temp\UnityTempFile-*</em>s (I'm going to refer to such a file as <em>utfile</em>), more precisely of the one that gets created when starting the build. The funky thing is that it's created from another (one of the 10+ identical created at project load time) <em>utfile</em> by (didn't do a through check, maybe there are additional lines as well) striping (and shuffling (<em>amestecating</em>)) some lines.</p>
  
  <p>The obvious one (don't even have to check the source <em>utfile</em>) is: <code>-r:E:/Install/x64/Unity/5.6.0f3/Editor/Data/Managed/UnityEngine.dll</code>, which inserted in the above file, works perfectly. But I don't know how to instruct <em>Unity</em> not to strip it.</p>
  
  <p><strong>Other facts</strong> (more or less relevant):</p>
  
  <ul>
  <li>There are several other <em>VStudio</em> versions installed (<em>2010</em>, <em>2013</em>, <em>2015</em>), and more <em>VCRedist</em>s, but I seriously doubt that any of this would make a difference, since <em>VStudio</em> is only used for editing (e.g. launched by <em>Unity</em> when dblclicking a script)</li>
  <li>My computer also "suffers" from <a href="http://home.bt.com/tech-gadgets/computing/has-your-windows-10-start-menu-stopped-working-here-are-four-ways-to-fix-it-11364000314532" rel="nofollow noreferrer">[BT]: Has your Windows 10 Start menu stopped working? How to fix it</a> (I restart it ~once a week; after ~3-4 days the problem reappears), but this is happening for weeks before installing <em>Unity</em></li>
  </ul>
  
  <p><strong>Possible solutions</strong>:</p>
  
  <ul>
  <li>Uninstall <em>Unity</em> and <em>VStudio</em>, and restore the original setup (if it still works) - not desirable</li>
  <li>Get an answer (here or on <em>Unity</em> forums, where I'm going to post the same question right away), and hopefully get to the bottom of it</li>
  <li>Start the painful process of debugging/monitoring (<a href="https://docs.microsoft.com/en-gb/sysinternals/downloads/procmon" rel="nofollow noreferrer">[MS.Docs]: Process Monitor</a> (<em>ProcMon</em>) is an excellent tool) also, might involve disassembling <em>UnityDownloadAssistant-5.6.0f3.exe</em>, but there are no guarantees that it would yield a (favorable) result. Anyway, I think there is a (hidden for now) link between:
  
  <ul>
  <li><em>VStudio</em> check-box not being present in <em>Assistant</em>, when <em>VStudio</em> already installed</li>
  <li>Lack of the build parameters combo-boxes for <em>PC Standalone</em></li>
  <li>Stripping the <em>UnityEngine.dll</em> dependency when building</li>
  </ul></li>
  <li>A possible work plan / algorithm for fixing this would be (just theory):
  
  <ul>
  <li>Debugging the <em>Assistant</em> and identifying the resource (registry value, file, ...) queried for <em>VStudio</em> installation status</li>
  <li>Tweak that resource to make <em>Assistant</em> "think" that <em>VStudio</em> is not installed; that would trigger the <em>VStudio</em> installer (and also make <em>Assistant</em> "mark" that this installation as suitable for <em>PC Standalone</em> builds), which would detect a previous installation (of course before this, the resource (if the same) needs to be untweaked) and would fail (another long shot here would be that <em>Assistant</em> doesn't check the return codes)</li>
  <li>Let <em>Assistant</em> finish and hopefully everything will be fine</li>
  </ul></li>
  </ul>
  
  <p>Any ideas are welcome.</p>
  
  <p><strong>Side note <sup>1</sup></strong> (not related to question): While uninstalling/installing <em>Unity</em>, I noticed smth; if it's <em>Community Edition</em> specific, I can (sort of) understand it, but if not, then it's a quite <strong>lame</strong> bug / behavior:</p>
  
  <ul>
  <li>Have <em>Unity</em> installed (fully as above)</li>
  <li>Run the <em>Assistant</em> and don't change anything from previous installation (the parent <em>RegKey</em> of the <em>RegValue</em> that I mentioned above, makes sure of that by default). It will:
  
  <ul>
  <li>Download (and <strong>overwrite</strong> ???) any sub pkg (e.g. <em>UnitySetup-Linux-Support-for-Editor-5.6.0f3.exe</em>, <em>FacebookGamesArcade.msi</em>, ...); for me it was ~3GB+ (even if the <strong>files were already there</strong>)</li>
  <li>Run every specified("checked") pkg / file</li>
  <li>Remove (<em>UnitySetup64.exe</em>) any existing installation before installing (???)</li>
  </ul></li>
  </ul>