[英]How do I include dll as reference in nuget that also gets copied as reference when nuget added to project
We are trying to control versions of nugets being used by hosting them on our own Artifactory and not on nuget.org while trying to package multiple nugets into one.我们正在尝试通过将它们托管在我们自己的 Artifactory 而不是在nuget.org 上来控制正在使用的 nuget 版本,同时尝试将多个 nuget 打包成一个。
Example for this is Aspose .这方面的例子是Aspose 。
I want to create a new library called AsposeTools that has our own helper functions.我想创建一个名为AsposeTools的新库,它具有我们自己的辅助函数。
AsposeTools references: Aspose.Cells and Aspose.PDF . AsposeTools参考: Aspose.Cells和Aspose.PDF 。
When I install AsposeTools in my project, I want to see AsposeTools , Aspose.Cells and Aspose.PDF so that I can call to use both my helper functions and the actual Aspose functions.当我在我的项目中安装AsposeTools时,我想看到AsposeTools 、 Aspose.Cells和Aspose.PDF以便我可以调用以使用我的辅助函数和实际的 Aspose 函数。 But I want Apose.Cells and Aspose.PDF to be "installed" by AsposeTools not dependencies that get copied down from our artifactory or nuget.org.
但我希望Apose.Cells和Aspose.PDF由AsposeTools “安装”,而不是从我们的 artifactory 或 nuget.org 复制下来的依赖项。 The reason being cause then we need to maintain version of cells and pdf in both our artifactory and what's being used in tools.
原因是因为我们需要在我们的人工制品和工具中使用的东西中维护单元格和 pdf 的版本。
How can I tell the dependency to install from within the nuget it exists instead of a nuget source.如何告诉依赖项从它存在的 nuget 中安装,而不是从 nuget 源中安装。
I've tried creating a libs folder within AsposeTools and added the extra dlls to that folder and added them as references.我尝试在AsposeTools 中创建一个 libs 文件夹,并将额外的 dll 添加到该文件夹中,并将它们添加为引用。 I then tried all the different options for build actions with Copy to Output Directory set to always.
然后,我尝试了所有不同的构建操作选项,并将“复制到输出目录”设置为“始终”。 The best I could get is that, telling by file size, AsposeTools has the extra dlls included, but I cant actually refence them in code, only my helper functions.
我能得到的最好结果是,从文件大小来看, AsposeTools包含了额外的 dll,但我实际上无法在代码中引用它们,只有我的辅助函数。 The Aspose.Cells and Aspose.PDF are not actually placed in the projects references
Aspose.Cells和Aspose.PDF实际上并未放置在项目引用中
EDIT: I use .csproj currently to build the nuget编辑:我目前使用 .csproj 来构建 nuget
If my comment's guess is right, you can just set these Apose.Cells.dll
and Aspose.PDF.dll
as assembly reference so that it will not install them as nuget packages from nuget.org
.如果我的评论的猜测是正确的,您可以将这些
Apose.Cells.dll
和Aspose.PDF.dll
设置为程序集引用,这样它就不会将它们安装为来自nuget.org
nuget 包。
Note : it will miss any dependencies of the nuget packages and if you want, you can use the same way to add them automatically.注意:它会丢失 nuget 包的任何依赖项,如果需要,您可以使用相同的方式自动添加它们。
1) click these nuget packages on the Dependencies --> Properties and then set their Private Asserts
to All
. 1)在Dependencies --> Properties上单击这些 nuget 包,然后将它们的
Private Asserts
Asserts 设置为All
。
Then , right-click on the project--> Unload project and then click reload Project to enable the settings.然后,右键单击项目-->卸载项目,然后单击重新加载项目以启用设置。
2) enter the xxx.csproj
file of the project and then add these: 2)进入项目的
xxx.csproj
文件,然后添加这些:
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<None Include="$(OutputPath)Aspose.Cells.dll" Pack="true" PackagePath="lib\$(TargetFramework)"></None>
<None Include="$(OutputPath)Aspose.PDF.dll" Pack="true" PackagePath="lib\$(TargetFramework)"></None>
// you can add any dependency dlls of the output folder in this way as you want
</ItemGroup>
3) repack your project and when you install the new version, you should first clean nuget caches or just delete caches files under C:\\Users\\xxx(current user)\\.nuget\\packages
. 3)重新打包你的项目,当你安装新版本时,你应该首先清理 nuget 缓存或者只是删除
C:\\Users\\xxx(current user)\\.nuget\\packages
下的缓存文件。
When you install the new AsposeTools package, it will not install the other two packages as nuget dependencies from nuget.org
.当您安装新的AsposeTools包时,它不会将其他两个包安装为来自
nuget.org
nuget 依赖nuget.org
。 And they are only referenced by the main project only as Assembly reference and also copied into output folder.并且它们仅被主项目引用,仅作为程序集引用并复制到输出文件夹中。
ConsoleApp2 is the new main project, and I have installed the new version of AsposeTools package into my project. ConsoleApp2是新的主项目,我已经在我的项目中安装了新版本的AsposeTools包。 And this is the effect:
这是效果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.