覆盖.nuspec中的依赖项

时间:2015-05-17 08:36:31

标签: visual-studio nuget nuget-spec

我想通过打包项目文件.nuspec而不是<dependencies>来打包我的项目。但我也想明确指定依赖项。

问题在于,在打包项目文件时(以便我可以使用项目中的道具),.nuspec文件中的AssemblyInfo.cs未被使用。

我这样做是为了让我可以在一个地方(.nuspec)更改道具,而不必在每个版本中更改.nuspec。我知道我可以打包.nuspec我可以完全控制的地方,但这已经失败了。 (我实际上现在正在做这个,直到我可以覆盖依赖关系)

有没有办法在developmentDependency中明确覆盖依赖关系?

修改

合并<dependencies> <group> <dependency id="Some.Core" version="0.1.0" /> </group> <group targetFramework="net4"> <dependency id="Microsoft.Bcl.Async" version="1.0.168" /> </group> <group targetFramework="net45"> <dependency id="Some" version="0.1.0" /> </group> </dependencies> 几乎有效。我在nuspec中使用依赖组,由于某些原因,nuget在打包后将其展平(当然只有在打包csproj时)。所以这个:(仅用于演示)

<dependencies>
  <dependency id="Some.Core" version="0.1.0" />
  <dependency id="Microsoft.Bcl.Async" version="1.0.168" />
  <dependency id="Some" version="0.1.0" />
</dependencies>

成为这个:

An item with the same key has already been added.

正因为如此,当在不同的组中使用相同的包作为依赖时,在打包时会出现错误:

int maxSpaceLength = 0; int currentSpaceCount = 0; for (int i = 0; i < charArray.length; i++) { if (charArray[i] == ' ') { currentSpaceCount++; } else { if(maxSpaceLength < currentSpaceCount) maxSpaceLength = currentSpaceCount; currentSpaceCount = 0; } } return maxSpaceLength;

1 个答案:

答案 0 :(得分:2)

如果csproj和nuspec文件具有完全相同的名称并且位于同一目录中,则它们应该在打包时协同工作,例如:

  • ProjectDirectory
    • MyProject.csproj
    • MyProject.nuspec

所以打电话

nuget pack MyProject.csproj

应该从csproj / assemblyInfo / packages.config等获取所有隐式数据,然后将该元数据与nuspec中指定的内容组合。当涉及到依赖关系时,您可以使用nuspec文件中的常规语法包含非隐式依赖关系,如下所示

<dependencies>
  <dependency id="RouteMagic" version="1.1.0" />
  <dependency id="RouteDebugger" version="1.0.0" />
</dependencies>

您可以在项目packages.config

中使用此语法排除某些隐式依赖项

“通过在packages.config中的包中添加developmentDependency =”true“属性,nuget.exe pack将不再包含该包作为依赖项。”

来源

相关问题