简体   繁体   English

用于TFS持续集成的NuGet包

[英]NuGet pack for TFS Continuous Integration

I'm trying to make our TFS Build process to generate NuGet packages from our solution's projects. 我正在努力使我们的TFS Build流程从我们的解决方案项目中生成NuGet包。 We aim to create a private package source, so all other internal products may download/update the framework using NuGet. 我们的目标是创建一个私有包源,因此所有其他内部产品可以使用NuGet下载/更新框架。

So far we've got the build process running (for a long time) and versioning our libraries, and the only thing that's left is to " nuget pack " all the projects. 到目前为止,我们已经运行了构建过程(很长一段时间)并对我们的库进行了版本控制,唯一剩下的就是“ nuget pack ”所有项目。


What i have tryed so far: 到目前为止我尝试了什么:

  1. nuget spec *.csproj, then nuget pack *.nuspec; nuget spec * .csproj,然后是nuget pack * .nuspec;
  2. nuget spec *.dll, then nuget pack *.nuspec; nuget spec * .dll,然后是nuget pack * .nuspec;
  3. nuget pack *.csproj directly (no .nuspec file); nuget pack * .csproj直接(没有.nuspec文件);

All of them seem to work, but all of them seem to fail on the steps I actually need them to succeed. 所有这些似乎都有效,但所有这些似乎都失败了我实际需要它们成功的步骤。

What I actually get from doing the mentioned steps: 我通过上述步骤实际得到的结果:

  1. No dependency¹ listed, no reference² listed; 列出没有依赖¹, 没有列出参考²;

  2. No dependency¹ listed, no reference² listed, all dlls from the directory are packed on the same .nupkg (whitout using -IncludeReferencedProjects); 没有列出依赖关系¹, 没有列出引用²,目录中的所有dll都打包在同一个.nupkg上(whitout使用-IncludeReferencedProjects);

  3. (The best so far) Some dependencies¹ listed, no reference² listed, only the actual project dll is inside the lib folder on the .nupkg. (目前为止最好的)列出了一些依赖项¹, 没有列出引用,只有实际的项目dll在.nupkg上的lib文件夹中。

¹: By dependency I mean NuGet dependencies, the packages from NuGet ¹: 依赖于我的意思是NuGet依赖,来自NuGet的包
²: By reference I mean solution project references. ²: 参考我的意思是解决方案项目参考。


Sample scenario: 示例场景:

Solution1.sln Solution1.sln
-- ProjectA - ProjectA
-- ProjectB - ProjectB

ProjectA has a Project Reference to ProjectB. ProjectA有ProjectB的项目参考 What I expect to happen on the .nuspec generated: 希望在生成的.nuspec上发生什么:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>ProjectA <- OK</id>
    <version>1.2.0.0 < - OK</version>
    <title>ProjectA <- OK</title>
    <authors>My Company <- OK</authors>
    <owners>My Company <- OK</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
    <copyright>OK</copyright>
    <dependencies>
        <dependecy id="ProjectB" Version="1.2.0.0" /> <<<<<<---- NOT HAPPENING!
    </dependencies>
  </metadata>
</package>    

Some nuget dependencies are listed, but not all of them (even when they are inside the packages.config from the refeered project). 列出了一些nuget依赖项,但不是所有这些依赖项(即使它们位于refeered项目的packages.config中)。 For example: I have a project that dependends on 4 other NuGet packages, only 2 are listed as dependencies on the generated .nuspec file. 例如:我有一个项目依赖于其他4个NuGet包,只有2个被列为生成的.nuspec文件的依赖项。


Important information: 重要信息:

  • Every project has its own packages.config, the way NuGet builds it; 每个项目都有自己的packages.config,NuGet构建它的方式;
  • The solution folder contains the packages folder, with all referenced packages; 解决方案文件夹包含packages文件夹,包含所有引用的包;
  • Already tryed Nugetter (XAML broken on VS 2012.3 and TFS 2012, cannot open it) 已经尝试过Nugetter(XAML打破VS 2012.3和TFS 2012,无法打开它)
  • Already tryed this , also does not include the dependencies and references properly; 已经尝试过这个 ,也没有正确地包含依赖关系和引用;
  • Solution package restore is turned ON (we need this to avoid storing the packages on TFS). 解包还原 (我们需要这样可避免储存在TFS的包)。

What I need: 我需要的:

  • Automate the pack process to pack each csproj including all references and dependencies on the .nuspec file, so all of them will be properly loaded when installing it. 自动化打包过程以打包每个csproj,包括.nuspec文件上的所有引用和依赖项,因此在安装它们时将正确加载它们。

Similar questions I've looked into: 我研究过的类似问题:

NuGet: pack command is NOT including nuget dependencies NuGet:pack命令不包括nuget依赖项
Nuget pack only including dependencies for some projects Nuget pack仅包含某些项目的依赖项
Why doesn't nuget include the referenced project when packing? 为什么包装时nuget不包括引用的项目?

It turns out to be a simple path problem. 事实证明这是一个简单的路径问题。 The references and dependencies were not being properly added because I was executing the command from a different working directory. 由于我是从不同的工作目录执行命令,因此未正确添加引用和依赖项。

On top of that, the use of -IncludeReferencedProjects was necessary to properly add everything needed. 最重要的是,使用-IncludeReferencedProjects是正确添加所需内容所必需的。

After that the build process using Powershell completed successfully and everything is worked as expected =) 之后,使用Powershell的构建过程成功完成,一切都按预期工作=)

The pack command has an option for including project references that must be specified: http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command_Options . pack命令有一个选项,用于包含必须指定的项目引用: http//docs.nuget.org/docs/reference/command-line-reference#Pack_Command_Options

You'll need to target the csproj file, and I recommend creating a nuspec file manually. 您需要定位csproj文件,我建议您手动创建一个nuspec文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM