无法推动nuget包。授权添加到nuget服务器

时间:2016-12-07 15:06:31

标签: visual-studio-2015 authorization nuget nuget-package nuget-server

我按照本指南设置了对我的nuget-server的athorization: http://blog.fermium.io/nuget-server-with-basic-authentication/

对于我正在使用的完整授权解决方案,您可以在此处找到它: 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 push c:\ temp \ Packages * .nupkg -s http://mynuget.azurewebsites.net/ apikey -Verbosity detail

请提供以下内容的凭据:http://mynuget.azurewebsites.net/

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

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

当我在Visual Studio包管理器控制台窗口中运行相同的推送命令时,我得到相同的错误。因为Package Manager Console窗口是非交互模式窗口,我们在运行命令时无法输入任何参数。

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

答案 1 :(得分: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