tag:help.appveyor.com,2012-11-13:/discussions/questions/1355-nuget-environment-using-windows-authenticationAppVeyor: Discussion 2018-08-25T01:57:05Ztag:help.appveyor.com,2012-11-13:Comment/370765272015-06-09T10:39:44Z2015-06-09T10:39:45ZNuget Environment using Windows Authentication<div><p>Hi,</p>
<p>Is it possible to create an environment for publishing nuget
packages to i.e. Nuget Provider and provide windows authentication
credentials instead or as well as an API key?</p>
<p>We want to publish to an internal proget server that is
configured with windows authentication.</p>
<p>Best regards<br>
Dave</p></div>David Bowntag:help.appveyor.com,2012-11-13:Comment/370765272015-06-09T17:05:35Z2015-06-09T17:05:35ZNuget Environment using Windows Authentication<div><p>Hi Dave,</p>
<p>Does nuget.exe allows publishing with Windows authentication or
you use some other client to do that?</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/370765272015-06-09T18:54:05Z2015-06-09T18:54:07ZNuget Environment using Windows Authentication<div><p>Hi,</p>
<p>Nuget.exe does support windows authentication and basic
authentication aside from using the api key.</p>
<p>The source can be set up with nuget source add -name -source
<source>-UserName username -Password password which will then
automatically authenticate with windows or basic auth credentials
as challenged.</source></p>
<p><source>If the UserName and Password aren't supplied then
nuget.exe prompts for credentials to use.</source></p>
<p><source>I would hope there would be a way to configure the
username and password to be used.</source></p>
<p><source>Cheers<br>
Dave</source></p></div>Dave Bowntag:help.appveyor.com,2012-11-13:Comment/370765272015-06-09T19:31:27Z2015-06-09T19:31:27ZNuget Environment using Windows Authentication<div><p>If the solution to support Windows auth for publishing is
registering NuGet feed with Windows credentials then you can run
this command in AppVeyor environment (say, during "Install" phase).
Put username and password into environment variables (or <a href="http://www.appveyor.com/docs/build-configuration#secure-variables">
secure variables</a> if you use appveyor.yml) and then:</p>
<pre>
<code>nuget source add -name <name of source> -source <source url> -UserName %var_with_username% -Password %var_with_password%</code>
</pre></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/370765272015-06-10T08:08:48Z2015-06-10T08:08:50ZNuget Environment using Windows Authentication<div><p>Hi,</p>
<p>I tried this as an init script, install script and
pre-deployment script and it doesn't work I get the following
output (i've obfuscated slightly) when using as a pre-deployment
script but it's the same effect with the other stages:</p>
<p>nuget source add -name myday -source <a href="https://">https://</a>************** -UserName %nuget_user%
-Password %nuget_password%<br>
Package Source with Name: myday added successfully.<br>
nuget list -source myday<br>
Using credentials from config. UserName: collabco\nugetpub<br>
myday.data 2.0.3.0<br>
myday.datasync 2.0.3.0<br>
myday.providers 2.0.3.0<br>
myday.security 2.0.3.0<br>
myday.utility 2.0.3.0<br>
Deploying using NuGet provider<br>
Publishing myday.utility.2.0.13.0.nupkg to <a href="https://">https://</a>***********************...<br>
Error publishing package. NuGet server returned 401:
Unauthorized</p>
<p>I put the nuget list step in to prove that the credentials being
stored were working and it correctly lists the packages
available.</p>
<p>I've also double checked the API key used in the NuGet
deployment step so I'm at a loss. It seems the NuGet deployment
provider doesn't work with the previously established source.</p>
<p>Next step would be to try and use a deployment PowerShell script
but I'm struggling to find any examples anywhere in particular how
I determine the path where the packages artefacts will be.</p>
<p>Cheers<br>
Dave</p></div>Dave Bowntag:help.appveyor.com,2012-11-13:Comment/370765272015-06-10T08:13:25Z2015-06-10T08:13:25ZNuget Environment using Windows Authentication<div><p>Hi Dave,</p>
<p>Built-in NuGet deployment provider doesn't support Windows
authentication yet (or any other authentication) except API
key.</p>
<p>Try using <code>nuget.exe</code> client with <code>nuget
push</code> command directly to publish your packages.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/370765272015-06-10T08:24:34Z2015-06-10T08:24:36ZNuget Environment using Windows Authentication<div><p>I think I'd deduced that would be necessary but I'm new to
appveyor and can't find any example deployment scripts.</p>
<p>I know PowerShell reasonably well and obviously I have the
packages as artefacts but how do I determine the path in which they
are located. Is there a parameter or environment variable
available?</p></div>Dave Bowntag:help.appveyor.com,2012-11-13:Comment/370765272015-06-10T08:26:46Z2015-06-10T08:26:46ZNuget Environment using Windows Authentication<div><p>Yeah, there is a hash with uploaded artifacts: <a href="http://www.appveyor.com/docs/packaging-artifacts#getting-information-about-uploaded-artifacts">
http://www.appveyor.com/docs/packaging-artifacts#getting-informatio...</a></p>
<p>Alternatively, you can just replace AppVeyor's auto-packaging
with your own <code>nuget pack ...</code> command and known output
dir.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/370765272015-06-10T18:43:52Z2015-06-10T18:43:53ZNuget Environment using Windows Authentication<div><p>Thanks for this, did as you suggested with the hash table and it
works a treat.</p>
<p>My deployment script is as follows:</p>
<p>$pushSource = "" $apiKey = $env:nuget_apiKey $user =
$env:nuget_user $password = $env:nuget_password</p>
<p>if ($apiKey -eq "")<br>
{ Write-Host "No NuGet server api key provided - so not pushing
anything up." return; }</p>
<p>if ($artifacts.Count -eq 0)<br>
{<br>
Write-Host "**** No nupkg files found in artefacts" throw; }</p>
<p>NuGet sources add -Name myday -Source $pushSource -UserName
$user -Password $password</p>
<p>foreach($artifactName in $artifacts.keys)<br>
{ NuGet push ($artifacts[$artifactName].path) -Source $pushSource
-apiKey $apiKey }</p></div>Dave Bowntag:help.appveyor.com,2012-11-13:Comment/370765272015-06-11T01:59:43Z2015-06-11T01:59:43ZNuget Environment using Windows Authentication<div><p>Great, thanks for the update.</p>
<p>Interesting case though - maybe we should add Windows auth
support in our built-in NuGet provider...</p></div>Feodor Fitsner