【发布时间】:2013-02-07 09:48:39
【问题描述】:
我正在使用 Nuget 创建包。我想创建一个不包含任何其他 NuGet 包的依赖项(在.nuspec 中)文件的包。我的项目确实在其packages.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 中。这是一个新的“功能”吗?我找不到任何描述此“功能”或何时实施的文档。
【问题讨论】:
-
删除 packages.config 文件或重命名。然后打包操作将忽略依赖项。这是我在 2.7 发布之前的临时解决方法。
-
有没有人用有效的答案回答这个问题。没有这种能力可能是我遇到过的最愚蠢的事情。
-
对我来说,我无法让它包含我的依赖项:(
-
我也无法包含我的依赖项。多年。我开始认为这是一个大谎言。
-
在你的 pack 命令中使用 -IncludeReferencedProjects 标志来自动包含依赖项,但删除它们并没有多大帮助。
标签: dependencies package nuget nuget-package nuspec