简体   繁体   English

如何将 dll 作为引用包含在 nuget 中,当 nuget 添加到项目时,该引用也被复制为引用

[英]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.CellsAspose.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时,我想看到AsposeToolsAspose.CellsAspose.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.CellsAspose.PDFAsposeTools “安装”,不是从我们的 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.CellsAspose.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.dllAspose.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.

相关问题 添加项目引用和 nuget 提要时,Docker 构建失败 - Docker build fails when project reference and nuget feed added 具有NuGet依赖项的参考DLL - Reference DLL with NuGet dependencies 我应该使用NuGet还是DLL参考? - Should I use NuGet or DLL reference? 什么在构建期间优先? nuget参考或项目参考 - What gets precedence during build? nuget reference or project reference 如何强制将 nuget package 参考 dll 复制到 output 目录? - How to force nuget package reference dlls to be copied to output directory? NuGet包无法为lib目录中的DLL添加对项目的引用 - NuGet Package fails to add reference to project for DLL inside lib directory 如何引用 NuGet 包? - How to reference NuGet packages? 如何在nuget包中包含单独添加的system.configuration dll - how to include separately added system.configuration dll in nuget package 如何将SQLite.Interop.dll添加到Nuget包中,这样不会出现“无法添加引用”错误? - How do I add SQLite.Interop.dll to a Nuget package so I don't get a 'Failed to add reference' error? 在项目中“添加为链接”时如何引用dll? - How do I reference dlls when “added as link” in project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM