title: How to set a global environment variable in .NET Core (user-wide or system-wide)
body: <p>In full .NET we can pass <code>EnvironmentVariableTarget</code> enum to <code>Environment.SetEnvironmentVariable</code> call:</p>
  
  <pre><code>public enum EnvironmentVariableTarget
  {
      Process,
      User,
      Machine
  }
  </code></pre>
  
  <p>With <code>User</code> or <code>Machine</code> options we can set a user-wide or system-wide variable which stays live after application end:</p>
  
  <pre><code>Environment.SetEnvironmentVariable("foo", "bar", EnvironmentVariableTarget.User);
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&gt; echo %foo%
  bar
  </code></pre>
  
  <p>However, <code>Environment.SetEnvironmentVariable</code> doesn't accept the variable target in .NET Core. Even XML comment for this method says:</p>
  
  <blockquote>
    <p>Creates, modifies, or deletes an environment variable stored in the current <strong>process</strong>.</p>
  </blockquote>
  
  <p>How to set an user-wide or machine-wide environment variable in .NET Core-targeted app? Only a crossplatform solution makes sense (at least Windows and Linux).</p>