Publishing a nuget package to Azure Artifacts using Nuget.exe prompts for signin from browser

大憨熊 提交于 2020-07-23 06:41:05

问题


I used Nuget.exe to push a package to Azure artifacts. But, below command always prompts for browser login. The package was pushed successfully after login. I cannot automate the build with this behavior. How can I workaround this issue?

nuget push ./out/MonoTorrent.1.0.39.nupkg -Source "https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json" -ApiKey "myapikey" -ConfigFile Nuget.config

Nuget.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="myfeed" value="https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json" />
  </packageSources>
    <myfeed>
      <add key="Username" value="myliveidemail" />
      <add key="ClearTextPassword" value="myapikey" />
    </myfeed>
</configuration>

回答1:


Please check Azure Artifacts Credential Provider. You need to install it and at first time when you push your package you will be asked to

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXXXX to authenticate.

Once you logged in at next run you won't be asked.

This is my nuget.config file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />

    <add key="devops-manual" value="my-feed-url" />

  </packageSources>
</configuration>

One remak: instead of nuget I was using dotnet pack and dotnet nuget push --source "devops-manual" --api-key az <package-path>. When in first push I added --interactive flag to be asked to login to Azure DevOps.

EDIT

I probably have missing tag:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="myfeed" value="https://pkgs.dev.azure.com/myacct/myproject/_packaging/myfeed/nuget/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <myfeed>
      <add key="Username" value="myliveidemail" />
      <add key="ClearTextPassword" value="myapikey" />
    </myfeed>
  </packageSourceCredentials>
</configuration>

EDIT2:

You can also run this command (from pipeline or login once to machine)

dotnet nuget add source your-source-url --name your-feed-name --username any-name-here --password PAT

This will add nuget source to list on your machine so later you can use this source without additional authentication.



来源:https://stackoverflow.com/questions/61672711/publishing-a-nuget-package-to-azure-artifacts-using-nuget-exe-prompts-for-signin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!