安装NuGet包而不在Visual Studio中添加任何引用

时间:2018-02-07 10:10:05

标签: visual-studio nuget nuget-package

我需要创建一个带有DLL的NuGet包,不应该在Visual Studio中直接引用。他们的想法是让它们在构建期间以某种bin文件夹结束,因为它们将在运行时由其他程序集隐式调用。

我能找到的最佳解决方案是在程序包中添加一个我计划引用的DLL,以便引用它而其他DLL不是(source):

<references>
    <reference file="OnlyTheFileIWantReferenced.dll" />
</references>

但理想情况下,我想在没有上述解决方法的情况下找到一种方法来做到这一点,我确定在.nuspec文件中必定会有某种指令我我失踪了。

1 个答案:

答案 0 :(得分:2)

  

安装NuGet包而不在Visual Studio中添加任何引用

要完成此操作,您可以将dll文件定位到tools文件夹中的lib文件夹而不是.nupsec文件夹:

  <files>
    <file src="bin\Debug\Unreference.dll" target="Tools\Unreference.dll" />
  </files>

以下是我的.nuspec文件:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>MyModels</id>
    <version>1.0.0</version>
    <authors>Tester</authors>
    <owners>Tester</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2018</copyright>
    <tags>Tag1 Tag2</tags>
  </metadata>
  <files>
    <file src="bin\Debug\MyModels.dll" target="lib\Net45" />
    <file src="bin\Debug\Unreference.dll" target="Tools\Unreference.dll" />
  </files>
</package>

打包此.nuspec后,我们将获得nuget包:

enter image description here

然后将此软件包安装到项目中,MyModels.dll将添加到Reference,但Unreference.dll不会,这个dll文件存在于packages文件夹中:packages\MyModels.1.0.0\Tools,你在那里可以隐式调用,也可以通过构建事件或msbuild复制任务将其复制到某种bin文件夹。

希望这有帮助。