【问题标题】:How do I include dll as reference in nuget that also gets copied as reference when nuget added to project如何在 nuget 中包含 dll 作为参考,当 nuget 添加到项目时,它也会被复制为参考
【发布时间】:2020-09-23 18:44:43
【问题描述】:

我们试图控制正在使用的 nuget 版本,方法是将它们托管在我们自己的 Artifactory 上,而不是 nuget.org 上,同时尝试将多个 nuget 打包成一个。

这方面的例子是 Aspose。

我想创建一个名为 AsposeTools 的新库,它有我们自己的辅助函数。

AsposeTools 参考:Aspose.Cells 和 Aspose.PDF。

当我在我的项目中安装 AsposeTools 时,我想查看 AsposeTools、Aspose.Cells 和 Aspose.PDF 以便我可以调用以使用我的辅助函数和实际的 Aspose 函数。 但我希望 Apose.Cells 和 Aspose.PDF 由 AsposeTools “安装”,而不是从我们的工件或 nuget 复制下来的依赖项。组织。原因是我们需要在我们的工件和工具中使用的内容中维护单元格和 pdf 的版本。

如何告诉依赖项从存在的 nuget 而不是 nuget 源中安装。

我尝试在 AsposeTools 中创建一个 libs 文件夹,并将额外的 dll 添加到该文件夹​​中并将它们添加为引用。然后,我尝试了所有不同的构建操作选项,并将 复制到输出目录 设置为始终。我能得到的最好的结果是,根据文件大小,AsposeTools 包含了额外的 dll,但我实际上不能在代码中引用它们,只有我的辅助函数。 Aspose.Cells 和 Aspose.PDF 实际上并没有放在项目引用中

编辑:我目前使用 .csproj 来构建 nuget

【问题讨论】:

  • 您可能需要澄清是否使用 .csproj 的 .nuspec 来构建您的 nuget。
  • 您是否不想将Apose.Cells 和Aspose.PDF 作为AsposeTools 的nuget 依赖项,然后仅在主项目中引用程序集dll?
  • How can I tell the dependency to install from within the nuget it exists instead of a nuget source. 这是否意味着不应将依赖项安装为来自nuget.org 的nuget 包,而应直接从AsposeTools 本身引用它们的程序集dll?

标签: c# visual-studio nuget


【解决方案1】:

如果我的评论猜对了,您可以将这些 Apose.Cells.dll 和 Aspose.PDF.dll 设置为程序集引用,这样它就不会将它们安装为来自 nuget.org 的 nuget 包。

注意:它会遗漏任何 nuget 包的依赖关系,如果需要,您可以使用相同的方式自动添加它们。

1) 在 Dependencies -->Properties 上单击这些 nuget 包,然后将它们的 Private Asserts 设置为 All。

然后,右键单击项目-->卸载项目,然后单击重新加载项目以启用设置。

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) 重新打包你的项目,安装新版本时,你应该先clean nuget caches 或删除C:\Users\xxx(current user)\.nuget\packages 下的缓存文件。

当您安装新的 AsposeTools 包时,它不会将其他两个包安装为来自 nuget.org 的 nuget 依赖项。并且它们仅被主项目引用为Assembly reference,并且也被复制到输出文件夹中。

ConsoleApp2 是新的主项目,我已将新版本的 AsposeTools 包安装到我的项目中。这就是效果:

【讨论】:

  • 这正是我所需要的。我唯一遇到的问题是目标框架。为了拥有依赖项(不是引用),我必须创建一个 .net 标准包,而不是 .net 框架,它不能在我们的 4.5.2+ 应用程序上运行。但这是一个很好的开端!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-02
  • 2018-07-09
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
相关资源
最近更新 更多