Azure DevOps-有条件的程序包还原 [英] Azure DevOps - conditional package restoration

查看:52
本文介绍了Azure DevOps-有条件的程序包还原的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Azure DevOps管道构建的解决方案包含一些使用条件包引用的项目,例如:

A solution that is built via Azure DevOps pipeline has some projects that use conditional package references such as:

<Choose>
    <When Condition="'$(Configuration)'=='Debug'">
      <ItemGroup>
         <PackageReference Include="Mock.MyPackage" Version="1.0.0" />
      </ItemGroup>
    </When>
    <Otherwise>
      <ItemGroup>
         <PackageReference Include="MyPackage" Version="1.2.0" />
      </ItemGroup>
    </Otherwise>
</Choose>

程序包源是一个私有的NuGet提要.

The package source is a private NuGet feed.

.dotnet还原任务不遵守条件包的选择.(还原Mock.MyPackage)
问题:
如何有条件地还原软件包(基于$ Configuration)?

The dotnet restore task does not respect the conditional package selection. (it restores Mock.MyPackage)
Question:
how can I conditionally restore packages (based on a $Configuration) ?

备注:
我还尝试通过指定MsBuild参数在Visual Studio Build任务期间进行还原:/t:restore.
在这种情况下,它会失败并显示一条消息:无法从远程源检索有关XX的信息.如果此命令可以还原软件包,如何为私有feed指定授权参数?

Remarks:
I have also tried restoring during Visual Studio Build task by specifying an MsBuild argument: /t:restore.
In that case it fails with a message: Failed to retrieve information about XX from remote source. If this command can restore packages how can I specify authorization args for the private feed ?

Github上存在一个问题: https://github.com/NuGet/Home/issues/5895 ,其中最后提到了此问题.

There is an issue on Github: https://github.com/NuGet/Home/issues/5895 where such issue is mentioned at the end.

推荐答案

我希望对部署配置进行最小的更改,因此可以接受以下内容.

I wanted minimal change in deployment configuration, so the following was acceptable.

  1. 将创建一个空项目,并在其中引用所有有条件恢复的软件包(无任何条件).

  1. An empty project is created and all packages which are restored conditionally are referenced there (without any conditions).

msbuild任务的附加参数已添加:'/t:restore'

Additional argument to msbuild task is added: '/t:restore'

在构建期间会发生以下情况:'dotnet restore'将恢复所有软件包,这要归功于1).
由于它不知道所选的配置,因此可能选择了错误的程序包(Mock.MyPackage而不是MyPackage).那就是2),msbuild任务将从"dotnet restore"创建的本地缓存中还原软件包.

During build the following will happen: 'dotnet restore' will restore all the packages thanks to 1).
Since it does not know a selected configuration it may pick a wrong package (Mock.MyPackage instead of MyPackage). That is where 2) comes, where msbuild task will restore packages from a local cache made by 'dotnet restore'.

备注:正如@(Leo Liu-MSFT)所写,dotnet还原可以进行身份​​验证,但不知道配置,而msbuild知道配置但不能进行身份验证,因此从私有feed还原AzDevOps中的程序包非常棘手.

Remarks: As @(Leo Liu-MSFT) wrote, dotnet restore can authenticate but it does not know configuration, and msbuild knows configuration but it can not authenticate, so package restoration in AzDevOps from private feeds is tricky.

这篇关于Azure DevOps-有条件的程序包还原的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆