的NuGet:请勿包括包

的NuGet:请勿包括包

问题描述:

摘要的NuGet:请勿包括包

参考当我用NuGet包库,而在另一个项目中涉及的项目将拉动到build目录产生额外的文件引用它。

工作案例

 

Project: ReferenceLibrary 
    Output: ReferenceLibrary.dll 

Project: DerivedLibrary 
    Output: DerivedLibrary.dll 
    References: ReferenceLibrary (Copy Local = False) 

Project: ConsoleApplication 
    Output: ConsoleApplication.exe 
    References: DerivedLibrary 

编辑:参照库是不可复制的,因为它在运行时解决。有几个版本取决于目标。在派生项目中的参考。是这样我可以对它进行编码。

如果我构建它,那么只有DerivedLibrary.dll被复制到ConsoleApplication构建文件夹(即bin/Release)。

不能工作的情况

Project: ConsoleApplication 
    Output: ConsoleApplication.exe 
    Package: DerivedLibrary.nupkg (depends on ReferenceLibrary.nupkg) 

一个项目引用添加到DerivedLibray.dll。 DerivedLibrary.dll和ReferenceLibrary.dll都从它们的包中复制而来。

我可以看到它被复制到MSBUILD日志中。

_CopyFilesMarkedCopyLocal: 
    Copying file from "c:\...\ReferenceLibrary.dll" to "bin\Debug\ReferenceLibrary.dll" 

即使它没有在任何地方的.csproj中引用。

我不能告诉如果这是一个NuGet问题(由于它如何解包的东西)或Visual Studio项目(它如何复制引用的程序集和编码其他程序集中的需求)。

+2

如果派生库依赖于Reference库,您真的很惊讶使用Derived库的应用程序也需要Reference库来运行吗?还是我误解了这个问题? – mason 2014-09-05 13:52:11

+0

对不起,我试图消除这个复杂性,因为问题变得非常不自信。参考库在运行时解析(因此我不希望它复制到输出文件夹)。我将把它重新加入。 – Karle 2014-09-05 13:53:31

+1

如果它在运行时被引用,那么当应用程序手动将其放入'bin'文件夹或GAC时,您的应用程序是否会运行?这有什么用途? – ashes999 2014-09-05 14:10:45

我发现一个可能的解决方案是使用后期构建目标来删除违规引用。

在派生库中添加一个DerivedLibrary.targets文件。

<?xml version="1.0" encoding="utf-8" ?> 
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <Target Name="RemoveUnwantedReferences" AfterTargets="Build"> 
     <Message Text="Removing unwanted references"/> 
     <Delete Files="$(OutputPath)ReferenceLibrary.dll"/> 
    </Target> 
</Project> 

然后在.nuspec包括它

<package> 
    ... 
    <files> 
    <file src="Targets/DerivedLibrary.targets" target="/build/DerivedLibrary.targets" /> 
    </files> 
</package> 

然后当有人安装包后生成挂钩将被添加。当他们构建被复制的文件时,它们将被自动删除。