title: How to set nuget server apikey in TFS build server
body: <h2>Question</h2>
  
  <p>How to set nuget source api key, so it works with TFS Build running "Network Service"?</p>
  
  <h2>Scenario</h2>
  
  <p>I have TFS build server and Build Definition that executes as "Network Service".</p>
  
  <p>during the build i'm trying to publish nuget packages:</p>
  
  <pre><code>&lt;Exec Command='"nuget.exe" push "mypackages\*.nupkg" -source http://mynugetserver/'/&gt;
  </code></pre>
  
  <p>however, I don't know how to set apikey for my nuget server.</p>
  
  <h2>What have I tried</h2>
  
  <pre><code>nuget setapi "myapikey" -source http://mynugetserver/
  </code></pre>
  
  <p>when I log in to build server and runthis command It saves the apikey for current user and it is ignored in TFS build that runs as network service. build.proj publishes the packages when executed manually since the key is saved for current user, but it doesn't work when I queue new tfs build.</p>
  
  <p>I have tried to create custom nuget.config in the root directory for my TFS project builds 'C:\Builds\1\MyProject\nuget.config` and run</p>
  
  <pre><code>nuget setapi "myapikey" -source http://mynugetserver/ -ConfigFile "C:\Builds\1\MyProject\nuget.config"
  </code></pre>
  
  <p>but the build ends with message:</p>
  
  <p><strong>"Key not valid for use in specified state"</strong></p>