[英]Can I work around adding these .dlls when installing NuGet package?
I started off by reading through this suggested question similar to mine, but there was no resolution: Why does MSTest.TestAdapter adds its DLLs into my NuGet package?我首先通读了这个与我类似的建议问题,但没有解决办法: Why does MSTest.TestAdapter adds its DLLs into my NuGet package?
Quick Problem Description快速问题描述
I wrote a NuGet package, and each time I install it, NUnit
and NUnit3TestAdapter
.dll
's get added to the project I installed on.我写了一个 NuGet 包,每次安装它时,
NUnit
和NUnit3TestAdapter
.dll
都会添加到我安装的项目中。 I want to find a solution that fixes this issue.我想找到解决此问题的解决方案。
Repro steps复制步骤
I have pushed two git repositories that reproduce the issue I am describing.我推送了两个重现我所描述问题的 git 存储库。
ClientLibrary
/ MainFramework
(project from which I generated NuGet package) - https://github.com/harbourc/client-library-repro-nuget-issue ClientLibrary
/ MainFramework
(我从中生成 NuGet 包的项目)- https://github.com/harbourc/client-library-repro-nuget-issue
TargetProject
(project that package is to be installed on) - https://github.com/harbourc/target-project-repro-nuget-issue TargetProject
(要安装包的项目)- https://github.com/harbourc/target-project-repro-nuget-issue
You can clone both repositories, restore their NuGet packages, and reproduce the issue as follows:您可以克隆这两个存储库,恢复它们的 NuGet 包,然后重现问题,如下所示:
Locate ClientLibrary.1.0.0.nupkg in client-library-repro-nuget-issue/ClientLibrary/在 client-library-repro-nuget-issue/ClientLibrary/ 中找到 ClientLibrary.1.0.0.nupkg
Open package manager console for target-project-repro-nuget-issue and run打开 target-project-repro-nuget-issue 的包管理器控制台并运行
Install-Package C:\Path\To\client-library-repro-nuget-issue\ClientLibrary\ClientLibrary.1.0.0.nupkg
NUnit
and NUnit3TestAdapter
.dll
's that are added into TargetProject
-- even though TargetProject
already has NUnit
and NUnit3TestAdapter
installed.TargetProject
中的NUnit
和NUnit3TestAdapter
.dll
即使TargetProject
已经安装了NUnit
和NUnit3TestAdapter
。 Longer Overview更长的概述
I have created my own NuGet package for internal use, called ClientLibrary
, and I am attempting to install it on to another project, called TargetProject
.我创建了自己的 NuGet 包供内部使用,称为
ClientLibrary
,我正试图将它安装到另一个项目,称为TargetProject
。 Here is a quick breakdown of the structure:这是结构的快速分解:
FullSolution.sln
MainFramework.csproj
ClientLibrary.csproj
--> .nupkg
generated from this ClientLibrary.csproj
--> .nupkg
生成Separate project:独立项目:
TargetProject.sln
TargetProject.csproj
--> install .nupkg
onto this TargetProject.csproj
--> 在此安装.nupkg
ClientLibrary
has a reference to MainFramework
, and uses many methods from MainFramework
. ClientLibrary
有对MainFramework
的引用,并使用MainFramework
中的许多方法。
When installing ClientLibrary.1.0.0.nupkg
onto TargetProject
, the following .dll
's are getting added to TargetProject
:将
ClientLibrary.1.0.0.nupkg
安装到TargetProject
时,以下.dll
将添加到TargetProject
:
nunit.engine.api.dll
nunit.engine.dll
NUnit3.TestAdapter.dll
NUnit3.TestAdapter.pdb
If I delete these .dll
's, everything works fine, because TargetProject
already has those packages installed anyway.如果我删除这些
.dll
的,一切正常,因为TargetProject
已经安装了这些包。 They are not necessary, it's just annoying to have to delete them when installing.它们不是必需的,安装时不得不删除它们很烦人。
Here is how I am adding ClientLibrary
NuGet package to TargetProject
:以下是我将
ClientLibrary
NuGet 包添加到TargetProject
的方式:
ClientLibrary
and MainFramework
projects to generate their.dllsClientLibrary
和MainFramework
项目以生成它们的.dllClientLibrary
folder and run nuget spec
ClientLibrary
文件夹并运行nuget spec
.nuspec
file is generated: .nuspec
文件生成:
<?xml version="1.0"?>
<package >
<metadata>
<id>ClientLibrary</id>
<version>1.0</version>
<title>Client Library</title>
<authors>Myself</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Client library for interacting with my application.</description>
<dependencies>
<group targetFramework=".NETFramework4.7.2" />
</dependencies>
</metadata>
</package>
Run nuget pack -IncludeReferencedProjects
-- Because ClientLibrary
has a dependency on MainFramework
(and several other packages used by MainFramework
)运行
nuget pack -IncludeReferencedProjects
因为ClientLibrary
依赖于MainFramework
(以及MainFramework
使用的其他几个包)
Navigate to TargetProject
, open Package Manager Console导航到
TargetProject
,打开包管理器控制台
Install-Package C:\Path\To\ClientLibrary.1.0.0.nupkg
Install-Package C:\Path\To\ClientLibrary.1.0.0.nupkg
Installation runs successfully, and then those .dll
's I am complaining about get added.安装成功运行,然后添加了我抱怨的那些
.dll
。
Problem:问题:
MainFramework
has NUnit
and NUnit3TestAdapter
NuGet packages installed. MainFramework
安装了NUnit
和NUnit3TestAdapter
NuGet 包。 ClientLibrary
does not. ClientLibrary
没有。 So, the .dll
's seem to be added because they are installed on MainFramework
, but NOT installed on ClientLibrary
.因此,似乎添加了
.dll
,因为它们安装在MainFramework
上,但未安装在ClientLibrary
上。 (Remember, ClientLibrary
references MainFramework.dll
.) (请记住,
ClientLibrary
引用MainFramework.dll
。)
There are other packages installed on both MainFramework
and ClientLibrary
, and these do not have .dll
's that get added to TargetProject
upon installation, so I am assuming issue is caused by having packages present in MainFramework
but NOT in ClientLibrary
. MainFramework
和ClientLibrary
上还安装了其他包,这些包没有在安装时添加到TargetProject
的.dll
,所以我假设问题是由于MainFramework
中存在包而不是ClientLibrary
中存在包引起的。
I believe I can "fix" this issue by installing NUnit
and NUnit3TestAdapter
onto ClientLibrary
, but ClientLibrary
doesn't actually use those packages at all, so it seems unnecessary.我相信我可以通过在
ClientLibrary
上安装NUnit
和NUnit3TestAdapter
来“解决”这个问题,但ClientLibrary
实际上根本不使用这些包,所以它似乎没有必要。
How can I install ClientLibrary
onto TargetProject
without including the NUnit
and NUnit3TestAdapter
.dll
's, and without having to install NUnit
and NUnit3TestAdapter
onto ClientLibrary
?如何在不包括
NUnit
和NUnit3TestAdapter
.dll
的情况下将ClientLibrary
安装到TargetProject
上,并且不必将NUnit
和NUnit3TestAdapter
安装到ClientLibrary
上? If possible, I would like to tell ClientLibrary.1.0.0.nupkg
to use the NUnit
and NUnit3TestAdapter
packages that are already installed on TargetProject
.如果可能的话,我想告诉
ClientLibrary.1.0.0.nupkg
使用已经安装在TargetProject
上的NUnit
和NUnit3TestAdapter
包。
If the answer is "Not possible", that is fine, but I would like an explanation -- my overall goal for this question is to gain a better understanding of how NuGet and dependencies work, and understand why this has been an issue in the first place.如果答案是“不可能”,那很好,但我想要一个解释——我对这个问题的总体目标是更好地理解 NuGet 和依赖项是如何工作的,并理解为什么这是一个问题第一名。 Thank you for reading.
感谢您的阅读。
In general, it's best practice to keep all of your tests and corresponding NuGet packages in their own project.通常,最佳做法是将所有测试和相应的 NuGet 包保存在它们自己的项目中。 Then make sure none of the projects reference the test project.
然后确保没有项目引用测试项目。
On the don't side, Client Library will include the NUnit dlls because they were added to a project that Client Library references.另一方面, Client Library 将包含 NUnit dll,因为它们已添加到 Client Library 引用的项目中。
Whereas on the do side, Client Library will not include the NUnit dlls because neither reference the test project.而在do方面,Client Library 将不包含 NUnit dll,因为它们都没有引用测试项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.