创建NuGet包时不要包含packages.config文件中的依赖关系

我使用Nuget来创建包。我想创建一个不包含任何依赖(.nuspec)文件到任何其他NuGet包的包。我的项目确实有在package.config文件中定义的NuGet包依赖。

首先我创建.nuspec文件

C:\code\MySolution>.nuget\nuget.exe spec MyProject\MyProject.csproj

我编辑生成的.nuspec文件是最小的,没有依赖。

<?xml version="1.0"?>
<package >
  <Metadata>
    <id>MyProject</id>
    <version>1.2.3</version>
    <title>MyProject</title>
    <authors>Example</authors>
    <owners>Example</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Example</description>
    <copyright>copyright 2013 Example</copyright>
    <tags>example</tags>
    <dependencies />
  </Metadata>
</package>

然后我构建解决方案并创建一个NuGet包…

C:\code\MySolution>.nuget\nuget.exe pack MyProject\MyProject.csproj -Verbosity detailed

这是该命令的输出

Attempting to build package from 'MyProject.csproj'.
Packing files from 'C:\code\MySolution\MyProject\bin\Debug'.
Using 'MyProject.nuspec' for Metadata.
Found packages.config. Using packages listed as dependencies

Id: MyProject
Version: 1.2.3
Authors: Example
Description: Example
Tags: example
Dependencies: Google.ProtocolBuffers (= 2.4.1.473)

Added file 'lib\net40\MyProject.dll'.

Successfully created package 'C:\code\MySolution\MyProject.1.2.3.nupkg'.

创建的.nupkg包有一个包含在其中的.nuspec文件,但它包括一个依赖项部分,我在原来的.nuspec文件中没有…

<dependencies>
  <dependency id="Google.ProtocolBuffers" version="2.4.1.473" />
</dependencies>

我相信这是发生,因为这…(从上面的输出)

Found packages.config. Using packages listed as dependencies

如何使NuGet不会自动解决依赖关系并将它们插入到从pack命令生成的.nuspec文件

我目前使用NuGet 2.2。另外,我不认为这种行为发生在旧版本的NuGet;这是一个新的“功能”吗?我找不到任何文档描述这个“功能”或当它被实现。

在版本2.7中有一个名为developmentDependency的选项,可以将其设置为package.config以避免包含依赖性。

Excluding development dependencies when creating packages

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...