[英]Dotnet Pack include nuget packages into output nuget package
So i'm encountering a very weird behavior with nuget packages.所以我在使用 nuget 包时遇到了一个非常奇怪的行为。
let's say i have a package called Framework
and this package is a dependency to Package A
and Package B
假设我有一个名为
Framework
的 package ,而这个 package 是Package A
和Package B
Now i have a Client 1
that has as dependencies the Framework
, Package A
, Package B
and it MUST be like this because for example a Client 2
might not need Package A
but need the other 2 or a client that only needs the framework.现在我有一个
Client 1
,它具有Framework
、 Package A
、 Package B
作为依赖项,它必须是这样的,因为例如Client 2
可能不需要Package A
的客户端,而只需要框架但需要其他客户端。
Now here's where things get weird.现在事情变得奇怪了。 If for testing purposes I create a local version of the
Framework
for Client 1
to test out some changes, but Package A/B
are still from the registry where they were published, it will complain that the older version of the framework is not found (which is the version Package A/B
were built with) so i would like to k now if there is any way to literally bundle a nuget package with all of it's dependencies as a standalone package?如果出于测试目的,我为
Client 1
创建了本地版本的Framework
来测试一些更改,但Package A/B
仍然来自发布它们的注册表,它会抱怨找不到旧版本的框架( which is the version Package A/B
were built with) so i would like to k now if there is any way to literally bundle a nuget package with all of it's dependencies as a standalone package?
Here is a sample.csproj这是一个sample.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<ItemGroup>
<Folder Include="Component\" />
<Folder Include="Model\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Package.A" Version="1.0.1-SNAPSHOT" />
<PackageReference Include="Framework" Version="[5.*,)" />
</ItemGroup>
</Project>
And my pack command is usually:我的打包命令通常是:
dotnet pack -p:PackageVersion=1.1.2-SNAPSHOT -o C:\Users\SomeUser\Desktop\Projects\NuGetPackages
if there is any way to literally bundle a nuget package with all of it's dependencies as a standalone package?
如果有任何方法可以将 nuget package 及其所有依赖项捆绑为独立的 package?
Not with the current tooling, but it is the highest upvoted issue on GitHub .不是使用当前的工具,但它是GitHub 上投票率最高的问题。
If it's something you really want, you could use PackagePath to include the dll in your package (for example <None Include="path\to\framework.dll" PackagePath="lib/<tfm>/" />
).如果这是您真正想要的东西,您可以使用PackagePath将 dll 包含在 package 中(例如
<None Include="path\to\framework.dll" PackagePath="lib/<tfm>/" />
)。 Alternatively, create a nuspec
file and specify all the assemblies to include .或者,创建一个
nuspec
文件并指定要包含的所有程序集。
There are several issues with this, however.然而,这有几个问题。 One is when the version of
framework.dll
that is bundled with Package.A
is different to the version bundled with Package.B
, which version will the app end up using?一种是当与
Package.A
捆绑的framework.dll
的版本与与Package.B
捆绑的版本不同时,应用程序最终将使用哪个版本File names must be unique, so both can't exist at the same time.文件名必须是唯一的,因此两者不能同时存在。 By keeping framework as a separate package which is a dependency of both other packages, it's clearer that only one is selected, and it's clear which version was selected.
通过将框架保持为单独的 package 这是两个其他包的依赖项,更清楚的是只选择了一个,并且很清楚选择了哪个版本。 Another issue is if there's a bug in Framework, if it's a dependency, the app can simply reference Framework as a direct dependency, using a version that fixes the bug.
另一个问题是,如果 Framework 中存在错误,如果它是依赖项,则应用程序可以简单地将 Framework 引用为直接依赖项,使用修复错误的版本。 If framework.dll is bundled inside the other packages, then not only does Framework need to be fixed, but then new versions of the other packages need to be published that include this new version.
如果 framework.dll 捆绑在其他包中,则不仅需要修复 Framework,而且还需要发布包含此新版本的其他包的新版本。 You're making servicing bug fixes more difficult when you bundle.
捆绑时,您使服务错误修复变得更加困难。
However, I don't believe any of this is going to solve your problem.但是,我不相信这会解决您的问题。 Your description that "it will complain that the older version of the framework is not found" lacks details to understand what the exact error was, but I assume that your framework dll is strong name signed and it fails at runtime with a file not found error about the version the packages were compiled against.
您对“它会抱怨找不到旧版本的框架”的描述缺乏了解确切错误的详细信息,但我假设您的框架 dll 是强名称签名的,它在运行时失败并出现文件未找到错误关于编译包的版本。 In this case you probably want to use binding redirects , although for SDK style projects I thought this should be done automatically when it detects multiple assemblies referencing different versions of the same assembly name.
在这种情况下,您可能希望使用绑定重定向,尽管对于 SDK 风格的项目,我认为这应该在检测到多个程序集引用相同程序集名称的不同版本时自动完成。
If this answer doesn't help, I think we need more information about what the actual error you got was, and how exactly you "create a local version of the Framework for Client 1 to test out some changes" (did you add a ProjectReference
to framework.csproj, or did you compile a framework.dll and add a reference to this dll in your test project, or something else?)如果这个答案没有帮助,我认为我们需要更多关于你得到的实际错误是什么的信息,以及你究竟是如何“为客户端 1 创建框架的本地版本来测试一些更改”(你添加了一个
ProjectReference
到framework.csproj,或者你编译了一个framework.dll并在你的测试项目中添加了对这个dll的引用,或者别的什么?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.