gpt4 book ai didi

nuget - 如何仅针对特定目标框架从 NuGet 包还原程序集

转载 作者:行者123 更新时间:2023-12-03 18:04:45 27 4
gpt4 key购买 nike

我正在寻找一种方法来还原面向 的 NuGet 包的程序集正好一个框架,在本例中 net45 .

这是我的包配置:

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net45" />
</packages>

这是我的 NuGet 配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value=".\Nuget" />
</config>
</configuration>

版本为: NuGet Version: 5.2.0.6090
正在运行: nuget restore packages.config -ConfigFile nuget.config恢复所有 targetframework 的程序集可以通过以下方式看到版本:
E:\Tmp\NuGet\Nuget\Newtonsoft.Json.12.0.1>dir lib
Directory of E:\Tmp\NuGet\Nuget\Newtonsoft.Json.12.0.1\lib

2019-09-30 18:27 <DIR> .
2019-09-30 18:27 <DIR> ..
2019-09-30 18:27 <DIR> net20
2019-09-30 18:27 <DIR> net35
2019-09-30 18:27 <DIR> net40
2019-09-30 18:27 <DIR> net45
2019-09-30 18:27 <DIR> netstandard1.0
2019-09-30 18:27 <DIR> netstandard1.3
2019-09-30 18:27 <DIR> netstandard2.0
2019-09-30 18:27 <DIR> portable-net40+sl5+win8+wp8+wpa81
2019-09-30 18:27 <DIR> portable-net45+win8+wp8+wpa81

根据 docs.microsoft.com

When NuGet installs a package that has multiple assembly versions, it tries to match the framework name of the assembly with the target framework of the project.

If a match is not found, NuGet copies the assembly for the highest version that is less than or equal to the project's target framework, if available. If no compatible assembly is found, NuGet returns an appropriate error message.

For example, consider the following folder structure in a package:

\net45
\MyAssembly.dll
\net461
\MyAssembly.dll

When installing this package in a project that targets .NET Framework 4.6, NuGet installs the assembly in the net45 folder, because that's the highest available version that's less than or equal to 4.6.

If the project targets .NET Framework 4.6.1, on the other hand, NuGet installs the assembly in the net461 folder.



从上面的段落我了解到,当我设置目标框架时,我应该能够仅恢复该目标框架的程序集。就我而言,看起来 NuGet 完全忽略了 targetFramework属性并始终为所有目标框架安装 dll。从 更改它net45 net40 没有效果。

如何让 NuGet 恢复 特定目标框架的包中的dll?

最佳答案

我不认为你可以。

Fiddler

nuget (zip) 包含所有框架。

全部 Nuget.exe正在做的是下载文件并解压缩。
之后可以删除不想要的吗?

另外,为什么不直接使用 .\nuget.exe restore -Force -NoCache -Packagesdirectory .\Nuget而不是nuget配置文件?

您可以通过创建自己的仅包含您的框架的包来混淆人们!

关于nuget - 如何仅针对特定目标框架从 NuGet 包还原程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58172105/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com