How to run SublimeText with visual studio environment enabled
<p><strong>OVERVIEW</strong></p>

<p>Right now I got these 2 programs on my windows taskbar:</p>

<ul>
<li><p>SublimeText3 target: </p>

<pre><code>"D:\software\SublimeText 3_x64\sublime_text.exe"
</code></pre></li>
<li><p>VS2015 x64 Native Tools Command Prompt target: </p>

<pre><code>%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"" amd64
</code></pre></li>
</ul>

<p>Goal here is running Sublime Text with vs2015 environment enabled.</p>

<ol>
<li>One option would be open the vs command prompt and then run sublime text from there, <code>&gt; sublime_text</code>  (this is not good one, I want it to be a <strong>non-interactive process</strong>)</li>
<li>Another option would be modifying somehow the sublimetext symlink target from the taskbar so I could open sublime with vs2015 environment enabled just clicking the icon</li>
</ol>

<p><strong>QUESTION</strong></p>

<p>How could I acomplish option 2?</p>

<p>NS: I want to get Sublime Text 3 to run vcvarsall.bat properly only <strong>once</strong> at startup (not at build time on any build system)</p>

<p><strong>ATTEMPTS</strong></p>

<p>My first attempt was trying to understand how bat files executed so I tested
some basic batch files:</p>

<ul>
<li><p>bat1.bat: It opens sublime text succesfully</p>

<pre><code>sublime_text
</code></pre></li>
<li><p>bat2.bat: It opens vs command prompt succesfully and it waits for user to type commands</p>

<pre><code>cmd /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"" amd64
</code></pre></li>
<li><p>bat3.bat: Open vs command prompt but it won't open ST, unless you type exit once the command prompt is shown</p>

<pre><code>%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"" amd64
sublime_text
</code></pre></li>
<li><p>bat4.bat: Open vs command prompt but it doesn't open ST, same case than bat3.bat</p>

<pre><code>%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"" amd64 &amp;&amp; sublime_text
</code></pre></li>
<li><p>bat5.bat: Open vs command prompt but it doesn't open ST, same case than bat{4,3}.bat</p>

<pre><code>%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"" amd64 &amp; sublime_text
</code></pre></li>
</ul>

<p>After these attempts I've decided to read some docs trying to find some hints about <a href="http://ss64.com/nt/cmd.html" rel="nofollow">cmd</a> but it didn't make any difference.</p>

<p>Another idea was using conemu customized tasks, something like:</p>

<pre><code>{vs2015}: cmd.exe /k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 &amp; sublime_text
</code></pre>

<p>and then having a bat file calling conemu like this:</p>

<pre><code>D:\software\ConEmuPack.151205\ConEmu64.exe /single -cmd {vs2015}
</code></pre>

<p>the result was +/- what I wanted, but 2 terminals and a new sublime session would be spawned. What I'm looking for is just opening a SublimeText session with the right environment, so I consider this not a good solution, plus, it requires to have conemu installed.</p>

<p>After all those attempts I thought maybe using python to open a command prompt and typing&amp;running "magically" some commands could be helpful but I don't know how to do it.</p>

<p>Conclusion: Till the date the problem remains unsolved... </p>

<ol start="2">
<li>exactly as stated is not possible directly but Sublime Text has options for running other programs.</li>
</ol>

<p>Make a batch file that goes to the directory that vcvarsall.bat wants (it looks at the directory it was run from, so it needs to be started from the proper dir) and runs vcvarsall.bat:</p>

<pre><code>@ECHO OFF
REM vcdir is the directory where you should be
set vcdir="c:\program files (x86)\Microsoft Visual Studio 14.0\VC"
REM go into that directory
push "%vcdir%"
REM Run vcvarsall.bat to set the env vars
call vcvarsall.bat amd64
REM Get back to the directory we were in initially
popd
</code></pre>

<p>If you're ok running this batch file during build (if you only need it for the build process and you don't mind rerunning it every time) then follow these instructions to <a href="http://stackoverflow.com/questions/23789410/how-to-edit-sublime-text-build-settings">add that batch file to your build settings in sublime text 3</a></p>

<p>A more elegant approach would be to find out how to get Sublime Text 3 to run a program just once on startup (rather than at build time). I'd bet money that's possible, but I need to get back to work now...</p>

python windows visual-studio-2015 environment-variables sublimetext3