【发布时间】:2019-12-06 05:41:18
【问题描述】:
作为 NuGet 包创建的 CI 过程的一部分,是否可以将新创建的包安装到项目中,驻留在存储库中?这样就可以安装测试了。 使用 Visual Studio UI 很容易做到,但是如何在新创建的 Azure 管道工作者上自动完成呢?
【问题讨论】:
标签: visual-studio powershell azure-devops nuget azure-pipelines
作为 NuGet 包创建的 CI 过程的一部分,是否可以将新创建的包安装到项目中,驻留在存储库中?这样就可以安装测试了。 使用 Visual Studio UI 很容易做到,但是如何在新创建的 Azure 管道工作者上自动完成呢?
【问题讨论】:
标签: visual-studio powershell azure-devops nuget azure-pipelines
在 Azure Pipeline 中的项目上安装 NuGet 包
恐怕无法在 Azure Pipeline 中的项目上安装 NuGet 包。
因为NuGet CLI install 命令行只是将包安装到当前项目中,但不修改项目或参考文件(packages.config)。:
类似于命令行nuget restore,只下载包不安装。
要将包安装到项目中,我们需要通过访问visual studio objects来修改项目文件:
https://github.com/NuGet/Home/issues/1512
所以应该不可能从 Visual Studio 中安装 NuGet 包,请查看my another thread 了解一些详细信息。
此外,我们也不建议在 Azure Pipeline 中安装 NuGet 包。如果我们自动将新创建的包安装到项目中,它将使用脚本来修改我们的 Repos,这是不推荐的,也是安全的。
个人认为正确的流程是:
希望这会有所帮助。
【讨论】:
NuGet.Client repo 有一堆测试,可以将包安装到测试项目中并断言各种事情。我知道很多PackageReference 测试,但不记得任何packages.config 测试。使用 .NET CLI 可以轻松编写大量脚本,但根据您想要执行的操作,您可能需要编写一些代码来操作 XML 文件。
这里有一堆有用的命令完全是从内存中编写的,因此可能无法按原样工作,但它会让你开始:
# create a new .NET Core console app. You'll need to edit the csproj to test different frameworks
dotnet new console
# create nuget.config file
dotnet new nugetconfig
# add a local folder as a package source
nuget sources add -configfile nuget.config -name local -source ..\newPackages
# set the global packages folder to a empty/temporary directory, so the test package
# doesn't pollute the agent's global packages folder
nuget config set -configfile nuget.config globalPackagesFolder gpf
# add the latest version of the package to the project in the current directory.
# use --version to specify a version
dotnet add package MyTestPackage
由于 SDK 风格的项目如此简短和简单,您最好将代码中的内容硬编码,然后将它们写入磁盘进行测试。这就是我们 (NuGet.Client) 所做的。
我们计划最终将配置选项移至 dotnet cli,这样您就不需要下载 nuget.exe,但它的优先级非常低,因为它很容易解决。 nuget.exe 适用于 Linux 和 Mac 上的单声道,或者只是在测试中将配置的内容硬编码到字符串中并在运行时编写。
仅当您要测试的内容不受 package compatibility issues 的 PackageReference 与 packages.config 影响时,这才会对您有用。但是,鉴于 .NET 的未来是 SDK 风格的项目,而 SDK 风格的项目不支持 packages.config,您可以尝试通过说它是未来来证明它的合理性。
【讨论】: