简体   繁体   中英

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.

Example for this is Aspose .

I want to create a new library called AsposeTools that has our own helper functions.

AsposeTools references: Aspose.Cells and 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. 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. 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.

How can I tell the dependency to install from within the nuget it exists instead of a nuget source.

I've tried creating a libs folder within AsposeTools and added the extra dlls to that folder and added them as references. 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. The Aspose.Cells and Aspose.PDF are not actually placed in the projects references

EDIT: I use .csproj currently to build the 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 .

Note : it will miss any dependencies of the nuget packages and if you want, you can use the same way to add them automatically.

1) click these nuget packages on the Dependencies --> Properties and then set their Private Asserts to 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:

 <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 .

When you install the new AsposeTools package, it will not install the other two packages as nuget dependencies from 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. And this is the effect:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM