- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用下面的代码在 CI 进程中安装 nuget 包,
Cake.Common.Tools.NuGet.NuGetAliases.NuGetInstall(context, packageid, new NuGetInstallSettings { NoCache = true, OutputDirectory = "../Packages", });
问题:
如何下载没有依赖的nuget包?
最佳答案
底层工具 NuGet.exe 目前不支持只下载包,有一个 GitHub 问题跟踪这个 https://github.com/NuGet/Home/issues/5919
也就是说,您可以使用其他 Cake 别名或仅使用普通 C# 在 Cake 脚本中实现它。
一个量身定制的例子是 Cake 自己的网站,它直接从 NuGet.org 下载插件,只获取所需的 dll 和 xmldoc 文件,可以在以下位置找到: https://github.com/cake-build/website/blob/9a7bf2fbf8b485488517175376cf11baa3817098/nuget.cake#L33
如果您对定制的 NuGetInstall 等价物感兴趣,我可以用它来更新这个答案。
更新添加了“DownloadLatestPackage”示例
这是一个示例,说明如何在 Cake 脚本中从 V3 NuGet 源下载 NuGet 包。
#load "nugetinstall.cake"
await context.DownloadLatestPackage(
"PackageId",
"../Packages"
);
#load "nugetinstall.cake"
Task("DownloadPackages")
.Does(
async context => {
foreach(var packageId in new [] { "Cake.Core", "Cake.Common", "Cake.Git" })
{
await context.DownloadLatestPackage(
packageId,
"../Packages"
);
}
}
);
Task("Default")
.IsDependentOn("DownloadPackages");
RunTarget(Argument("target", "Default"));
会输出类似的东西
========================================
DownloadPackages
========================================
Downloading package ../Packages/Cake.Core.1.0.0-rc0002...
Downloading package ../Packages/Cake.Common.1.0.0-rc0002...
Downloading package ../Packages/Cake.Git.0.22.0...
========================================
Default
========================================
Task Duration
--------------------------------------------------
DownloadPackages 00:00:03.3939241
--------------------------------------------------
Total: 00:00:03.3946443
并导致 packages 文件夹如下所示
Packages
+---Cake.Common.1.0.0-rc0002
|
+---Cake.Core.1.0.0-rc0002
|
\---Cake.Git.0.22.0
#addin nuget:?package=System.Text.Json&version=4.6.0&loaddependencies=true
#load "nugetmodel.cake"
using System.Net.Http;
using System.Text.Json;
public static async Task<T> GetAsync<T>(this HttpClient client, string uri)
{
using (var stream = await client.GetStreamAsync(uri))
{
return await JsonSerializer.DeserializeAsync<T>(
stream,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true }
);
}
}
public static async Task<bool> DownloadLatestPackage(this ICakeContext context, string packageId, DirectoryPath outputDirectory, string nuGetSource = "https://api.nuget.org/v3/index.json")
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (string.IsNullOrWhiteSpace(packageId))
{
throw new ArgumentNullException(nameof(packageId));
}
if (string.IsNullOrWhiteSpace(nuGetSource))
{
throw new ArgumentNullException(nameof(nuGetSource));
}
if (outputDirectory == null)
{
throw new ArgumentNullException(nameof(outputDirectory));
}
if (!context.DirectoryExists(outputDirectory))
{
throw new DirectoryNotFoundException($"{nameof(outputDirectory)} ({outputDirectory}) not found.");
}
using(var client = new HttpClient())
{
client.DefaultRequestHeaders.UserAgent.ParseAdd($"Cake NuGet Client/{context.Environment.Runtime.CakeVersion.ToString(3)}");
var nuGetIndex = await client.GetAsync<NuGetIndex>(nuGetSource);
var cakeBaseUrl = string.Concat(
nuGetIndex
?.Resources
?.Where(type => type.Type?.Length == 20
&& type.Type == "RegistrationsBaseUrl"
&& type.Id?.Length > 8 == true
&& type.Id.StartsWith("https://"))
.Select(url => url.Id)
.FirstOrDefault()
?? throw new Exception($"Failed to fetch RegistrationsBaseUrl from {nuGetSource}."),
$"{packageId.ToLowerInvariant()}/index.json"
);
var cakeNuGetIndex = await client.GetAsync<NuGetContainer<NuGetContainer<NuGetPackageEntry>>>(cakeBaseUrl);
var packageEntry = (
from item in cakeNuGetIndex.Items
from version in item.Items
orderby SemVersion.TryParse(
version.CatalogEntry.Version,
out var semVersion
)
? semVersion
: SemVersion.Zero
descending
select version.CatalogEntry
).FirstOrDefault();
if (string.IsNullOrWhiteSpace(packageEntry?.PackageContent))
{
throw new Exception($"Failed to found package uri for {packageId} on source {nuGetSource}");
}
var packageDirectory = outputDirectory.Combine($"{packageEntry.PackageId}.{packageEntry.Version}");
if(context.DirectoryExists(packageDirectory))
{
context.Information("Package {0} already downloaded.", packageDirectory);
return true;
}
context.Information("Downloading package {0}...", packageDirectory);
using (var stream = await client.GetStreamAsync(packageEntry?.PackageContent))
{
using (var zipStream = new System.IO.Compression.ZipArchive(stream))
{
foreach (var entry in zipStream.Entries)
{
var entryPath = packageDirectory.CombineWithFilePath(entry.FullName);
var directory = entryPath.GetDirectory();
context.EnsureDirectoryExists(directory);
using (System.IO.Stream source = entry.Open(),
target = context.FileSystem.GetFile(entryPath).OpenWrite())
{
source.CopyTo(target);
}
}
}
}
return context.DirectoryExists(packageDirectory);
}
}
#addin nuget:?package=System.Text.Json&version=4.6.0&loaddependencies=true
using System;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
public class NuGetIndex
{
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("resources")]
public NuGetResource[] Resources { get; set; }
}
public class NuGetResource
{
[JsonPropertyName("@id")]
public string Id { get; set; }
[JsonPropertyName("@type")]
public string Type { get; set; }
}
public class NuGetCommit
{
[JsonPropertyName("@id")]
public string Id { get; set; }
[JsonPropertyName("commitId")]
public Guid CommitId { get; set; }
[JsonPropertyName("commitTimeStamp")]
public DateTimeOffset CommitTimeStamp { get; set; }
}
public class NuGetContainer<T> : NuGetCommit
{
[JsonPropertyName("count")]
public int Count { get; set; }
[JsonPropertyName("items")]
public T[] Items { get; set; }
}
public class NuGetPackageEntry: NuGetCommit
{
[JsonPropertyName("catalogEntry")]
public NuGetCatalogEntry CatalogEntry { get; set; }
}
public class NuGetCatalogEntry: NuGetResource
{
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("packageContent")]
public string PackageContent { get; set; }
[JsonPropertyName("id")]
public string PackageId { get; set; }
}
public struct SemVersion : IComparable, IComparable<SemVersion>, IEquatable<SemVersion>
{
public static SemVersion Zero { get; } = new SemVersion(0,0,0, null, null, "0.0.0");
static readonly Regex SemVerRegex =
new Regex (
@"(?<Major>0|(?:[1-9]\d*))(?:\.(?<Minor>0|(?:[1-9]\d*))(?:\.(?<Patch>0|(?:[1-9]\d*)))?(?:\-(?<PreRelease>[0-9A-Z\.-]+))?(?:\+(?<Meta>[0-9A-Z\.-]+))?)?",
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase
);
public int Major { get; }
public int Minor { get; }
public int Patch { get; }
public string PreRelease { get; }
public string Meta { get; }
public bool IsPreRelease { get; }
public bool HasMeta { get; }
public string VersionString { get; }
public SemVersion (int major, int minor, int patch, string preRelease = null, string meta = null) :
this (major, minor, patch, preRelease, meta, null)
{
}
private SemVersion (int major, int minor, int patch, string preRelease, string meta, string versionString)
{
Major = major;
Minor = minor;
Patch = patch;
IsPreRelease = !string.IsNullOrEmpty (preRelease);
HasMeta = !string.IsNullOrEmpty (meta);
PreRelease = IsPreRelease ? preRelease : null;
Meta = HasMeta ? meta : null;
if (!string.IsNullOrEmpty (versionString)) {
VersionString = versionString;
} else {
var sb = new StringBuilder ();
sb.AppendFormat (CultureInfo.InvariantCulture, "{0}.{1}.{2}", Major, Minor, Patch);
if (IsPreRelease) {
sb.AppendFormat (CultureInfo.InvariantCulture, "-{0}", PreRelease);
}
if (HasMeta) {
sb.AppendFormat (CultureInfo.InvariantCulture, "+{0}", Meta);
}
VersionString = sb.ToString ();
}
}
public static bool TryParse (string version, out SemVersion semVersion)
{
semVersion = Zero;
if (string.IsNullOrEmpty(version)) {
return false;
}
var match = SemVerRegex.Match (version);
if (!match.Success) {
return false;
}
if (!int.TryParse (
match.Groups["Major"].Value,
NumberStyles.Integer,
CultureInfo.InvariantCulture,
out var major) ||
!int.TryParse (
match.Groups["Minor"].Value,
NumberStyles.Integer,
CultureInfo.InvariantCulture,
out var minor) ||
!int.TryParse (
match.Groups["Patch"].Value,
NumberStyles.Integer,
CultureInfo.InvariantCulture,
out var patch)) {
return false;
}
semVersion = new SemVersion (
major,
minor,
patch,
match.Groups["PreRelease"]?.Value,
match.Groups["Meta"]?.Value,
version);
return true;
}
public bool Equals (SemVersion other)
{
return Major == other.Major
&& Minor == other.Minor
&& Patch == other.Patch
&& string.Equals(PreRelease, other.PreRelease, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Meta, other.Meta, StringComparison.OrdinalIgnoreCase);
}
public int CompareTo (SemVersion other)
{
if (Equals(other))
{
return 0;
}
if (Major > other.Major) {
return 1;
}
if (Major < other.Major) {
return -1;
}
if (Minor > other.Minor) {
return 1;
}
if (Minor < other.Minor) {
return -1;
}
if (Patch > other.Patch) {
return 1;
}
if (Patch < other.Patch) {
return -1;
}
switch(StringComparer.InvariantCultureIgnoreCase.Compare(PreRelease, other.PreRelease)) {
case 1:
return 1;
case -1:
return -1;
default:
return StringComparer.InvariantCultureIgnoreCase.Compare (Meta, other.Meta);
}
}
public int CompareTo (object obj)
{
return (obj is SemVersion semVersion)
? CompareTo (semVersion)
: -1;
}
public override bool Equals (object obj)
{
return (obj is SemVersion semVersion)
&& Equals (semVersion);
}
public override int GetHashCode ()
{
unchecked {
var hashCode = Major;
hashCode = (hashCode * 397) ^ Minor;
hashCode = (hashCode * 397) ^ Patch;
hashCode = (hashCode * 397) ^ (PreRelease != null ? StringComparer.OrdinalIgnoreCase.GetHashCode (PreRelease) : 0);
hashCode = (hashCode * 397) ^ (Meta != null ? StringComparer.OrdinalIgnoreCase.GetHashCode (Meta) : 0);
return hashCode;
}
}
public override string ToString ()
=> VersionString;
// Define the is greater than operator.
public static bool operator > (SemVersion operand1, SemVersion operand2)
=> operand1.CompareTo (operand2) == 1;
// Define the is less than operator.
public static bool operator < (SemVersion operand1, SemVersion operand2)
=> operand1.CompareTo (operand2) == -1;
// Define the is greater than or equal to operator.
public static bool operator >= (SemVersion operand1, SemVersion operand2)
=> operand1.CompareTo (operand2) >= 0;
// Define the is less than or equal to operator.
public static bool operator <= (SemVersion operand1, SemVersion operand2)
=> operand1.CompareTo (operand2) <= 0;
}
作为引用,完整的工作解决方案可以在下面的要点中找到 https://gist.github.com/devlead/ca566f58457f558dd33484a73f1352ed#file-build-cake
关于c# - 如何下载没有依赖项的nuget包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65575720/
我在 gobject 上阅读了一个维基百科页面,上面写着, Depending only on GLib and libc, GObject is a cornerstone of GNOME and
如何注册一个依赖属性,其值是使用另一个依赖属性的值计算的? 由于 .NET 属性包装器在运行时被 WPF 绕过,因此不应在 getter 和 setter 中包含逻辑。解决方案通常是使用 Proper
我一直在尝试将 ActionbarSherlock maven 依赖项添加到我的项目中 com.actionbarsherlock library 4.2.0 在我的 po
http://tutorials.jenkov.com/ood/understanding-dependencies.html#whatis说(强调我的): Whenever a class A us
我对所有这些魔法有点不清楚。 据我了解,依赖属性是从 DependencyObject 继承的,因此存储值: 如果分配了值(在本地字典中),则在实例本身中 或者如果未指定值,则从指向父元素的链接中获取
我刚刚更新了在 ASP.NET Framework 4.5.2 版上运行的 MVC Web 应用程序。我正在使用 Twilio 发送 SMS 消息: var twilio = new TwilioRe
我刚刚发现了一件令人生畏的事情。 spring 依赖坐标有两个版本。 项目依赖于 spring mvc 和 spring flow。有两组并行的依赖项。 Spring MVC 具有以下方案的依赖项
我正在尝试包含 的 maven 依赖项 org.jacorb jacorb 2.3.1 依赖已解决,但它导致另一个依赖 picocontainer 出现问题: [ERROR
我正在尝试在 Haskell 项目中包含特定版本的库。该库是住宿加早餐型的(用于 martix 操作),但我需要特定的 0.4.3 版本,该版本修复了乘法实现的错误。 所以,我的 stack.yaml
有谁知道如何制作依赖的 UIPickerView.例如,当我选择组件一的第 2 行时,组件二的标题会发生变化吗? 我在互联网上查找过,没有真正的答案,我尝试过使用 if 和 switch 语句,但它们
我正在编写一个用于验收测试的项目,由于各种原因,这依赖于另一个打包为 WAR 的项目。我已成功使用 maven-dependency-plugin 解压 WAR,但无法让我的项目包含解压的 WEB-I
或多或少我在 session 上大量构建我的网站(特别是重定向用户等),我很好奇这是否是一种危险的做法。禁用浏览器 cookie 保存的用户的大致比例是多少?我愿意接受任何建议:) 谢谢 最佳答案 s
开始玩 Scala futures,我被依赖的 futures 困住了。 让我们举个例子。我搜索地点并获得 Future[Seq[Place]]。对于这些地点中的每一个,我搜索最近的地铁站(该服务返回
或多或少我在 session 上大量构建我的网站(特别是重定向用户等),我很好奇这是否是一种危险的做法。禁用浏览器 cookie 保存的用户的大致比例是多少?我愿意接受任何建议:) 谢谢 最佳答案 s
我有一个二进制文件,需要一些 *.so 文件才能执行。现在,当我尝试在一些旧机器上执行它时,它会显示 /lib/libc.so.6: version `GLIBC_2.4' not found 如何将
我尝试使用 Dygraph 来表示图表,我在 https://github.com/danvk/dygraphs 中找到了代码,但是它有太多的依赖文件,我觉得很烦人。是否有一个文件可以容纳所有必需的
我正在处理一个 javascript 文件,该文件 a) 声明一个具有函数的对象,并且 b) 使用它期望在外部声明的散列调用该对象的 init 函数。我的 Jasmine 规范提示它找不到哈希,因为它
最近我一直在学习 Angular 并且进展顺利,但是关于依赖注入(inject)的一些事情我仍然不清楚。 是否有任何理由在我的 app.js 文件中声明我的应用程序的其他部分(服务、 Controll
考虑一个名为 foo 的表,它有 id (PRIMARY & AUTO_INCREMENT) 列。我正在向该表中插入一行,挑战从此时开始。 $db->query("INSERT INTO `foo`
我正在使用级联下拉 jquery 插件。 (https://github.com/dnasir/jquery-cascading-dropdown) 我有两个下拉菜单。 “客户端”和“站点”。 根据您
我是一名优秀的程序员,十分优秀!