0

我遵循这个指南设置athorization我的NuGet服务器: http://blog.fermium.io/nuget-server-with-basic-authentication/未能推nuget包。 “的NuGet推”命令授权之后,不工作添加的NuGet服务器

对于我使用你可以在这里找到完整的授权解决方案: https://github.com/devbridge/AzurePowerTools/tree/master/Devbridge.BasicAuthentication

它工作正常,当我冲浪到我的nuget-server时,我得到了促进登录,它迄今为止工作正常。我还可以通过在visual studio中输入用户名/密码来访问我现有的nuget包。

当试图从视觉工作室推出Nuget-package,在授权添加到nuget-server之前工作正常时,问题就出现了。

nuget.config(%APPDATA%\的NuGet \ NuGet.config)

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <packageSources> 
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" /> 
    <add key="mynuget" value="http://mynuget.azurewebsites.net/nuget" /> 
    </packageSources> 
    <activePackageSource> 
    <add key="All" value="(Aggregate source)" /> 
    </activePackageSource> 
    <packageSourceCredentials> 
    <mynuget> 
     <add key="Username" value="mynugetUsername" /> 
     <add key="ClearTextPassword" value="mynugetPassword" /> 
    </mynuget> 
    </packageSourceCredentials> 
</configuration> 

的NuGet推C:\ TEMP \包* .nupkg -s http://mynuget.azurewebsites.net/ apikey -Verbosity详细

请提供凭据for:http://mynuget.azurewebsites.net/

System.InvalidOperationException:无法在非交互模式下提示输入。

我该如何解决这个问题?

+0

您是否在web.config文件中将“requireApiKey”设置为“flase”? –

+0

在web.config中的nuget-server上没有,我将requireApiKey设置为true,并且工作得很好。 (并推动apiKey传递) – Sgedda

回答

0

我还没有找到一个最佳的解决方案,但我已经提出了一种解决方法,可能有助于某人。尽管如此,仍然在寻找更清洁更好的解决方案我最终没有授权就允许PUT命令,因为它仍然需要ApiKey来推送包。 (见下文)

public void AuthenticateUser(Object source, EventArgs e) 
    { 
     var context = ((HttpApplication)source).Context; 
     if (context.Request.HttpMethod != "PUT") 
     { 
      string authorizationHeader = context.Request.Headers[HttpAuthorizationHeader]; 

      // Extract the basic authentication credentials from the request 
      string userName = null; 
      string password = null; 
      if (!this.ExtractBasicCredentials(authorizationHeader, ref userName, ref password)) 
      { 
       return; 
      } 

      // Validate the user credentials 
      if (!this.ValidateCredentials(userName, password)) 
      { 
       return; 
      } 
     } 

     // check whether cookie is set and send it to client if needed 
     var authCookie = context.Request.Cookies.Get(AuthenticationCookieName); 
     if (authCookie == null) 
     { 
      authCookie = new HttpCookie(AuthenticationCookieName, "1") { Expires = DateTime.Now.AddHours(1) }; 
      context.Response.Cookies.Add(authCookie); 
     } 
    } 

从这: https://github.com/devbridge/AzurePowerTools/tree/master/Devbridge.BasicAuthentication

1

当我跑在Visual Studio程序包管理器控制台窗口中的同一个推出的命令,我得到了同样的错误。因为程序包管理器控制台窗口是非交互式模式窗口,所以在运行命令时我们不能输入任何参数。

所以我建议你用命令提示符窗口推包并运行nuget push命令。

+0

谢谢!我仍然认为我会在下面使用我的解决方案,直到我找到更简单的东西我喜欢在Visual Studio中使用复制粘贴(push/pack)命令来做到这一点。 (包管理器控制台) – Sgedda