Nuget软件包的增量构建 [英] Incremental Build of Nuget Packages

查看:112
本文介绍了Nuget软件包的增量构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一个msbuild项目,该项目使用批处理来确定已经重新构建了一个或多个csproj项目,因此需要新的nuget打包.到目前为止,我编写的脚本似乎是一个合理的开始,但是它的增量构建机制无法正常工作. MainBuild目标无论何时都将执行.

I want to execute an msbuild project which uses batching to determine that one or more csproj projects have been freshly-built, and therefore require fresh nuget packaging. The script I've made so far seems like a reasonable start, but it the incremental-build mechanism isn't working. The MainBuild target executes every time, no matter what.

这就是我所拥有的:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="MainBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)'=='' ">Debug</Configuration>
    <Content>content\plugins\</Content>
  </PropertyGroup>
  <ItemGroup>
    <Nuspec Include="$(MSBuildProjectDirectory)\plugins\*\*.nuspec" />
  </ItemGroup>

<Target Name="MainBuild"
        Inputs="%(Nuspec.RootDir)%(Nuspec.Directory)bin\$(Configuration)\*.dll"
        Outputs="%(Nuspec.RootDir)%(Nuspec.Directory)%(FileName).pkg" >
  <ItemGroup>
    <Inputs Include="%(Nuspec.RootDir)%(Nuspec.Directory)bin\$(Configuration)\*.dll" />
    <Outputs Include="%(Nuspec.RootDir)%(Nuspec.Directory)%(FileName).pkg" />
  </ItemGroup>
  <Message Text="INPUTS: %(Inputs.FullPath)" />
  <Message Text="OUTPUTS: @(Outputs->'%(FullPath)')" />

  <Copy SourceFiles="@(Inputs)" DestinationFiles="@(Outputs->'%(FullPath)')" />

</Target>
</Project>

Copy任务只是一个调试占位符,用于调出nuget并创建一个新包.

The Copy task is just a debugging placeholder for calling-out to nuget and creating a new package.

这个想法是,如果bin\Debug目录中的任何文件比相应的.nuspec文件(在bin\Debug上方的两个文件夹中)都新,则MainBuild目标应执行.

The idea is that if any files in the bin\Debug directory are newer than the corresponding .nuspec file (found two folders above bin\Debug), then the MainBuild target should execute.

有什么想法吗?

p.s.假定TargetInputsOutputs属性各自创建一个项目.我认为创建的项目无法在目标内部引用很奇怪.在上面的示例中,我必须创建一个target-interna动态ItemGroup来重新创建项目,以便可以访问它们.有办法解决吗?

p.s. The Inputs and Outputs attributes of the Target presumably each create an item. I think it strange that the items created can't be referenced inside the target. In the above example, I had to make a target-interna dynamic ItemGroup to re-create the items, just so that I could access them. Is there a way around that?

推荐答案

我在

如果目标内部的任务使用批处理,则MSBuild需要确定 如果每批物料的输入和输出是最新的. 否则,每次击中目标都会执行一次.

If a task inside of a target uses batching, MSBuild needs to determine if the inputs and outputs for each batch of items is up-to-date. Otherwise, the target is executed every time it is hit.

可能是其中的一个.尝试将复制目标更改为使用批处理而不是ite转换(我认为在项目组中使用项目元数据不能满足上述要求).

Which may be the cuprit. Try changing your copy target to use batching instead of an ite transform (I don't think using item metadata in an item group satisfies the above requirement).

<Target Name="MainBuild"
        Inputs="%(Nuspec.RootDir)%(Nuspec.Directory)bin\$(Configuration)\*.dll"
        Outputs="%(Nuspec.RootDir)%(Nuspec.Directory)%(FileName).pkg" >
    <ItemGroup>
        <Inputs Include="%(Nuspec.RootDir)%(Nuspec.Directory)bin\$(Configuration)\*.dll" />
        <Outputs Include="%(Nuspec.RootDir)%(Nuspec.Directory)%(FileName).pkg" />
    </ItemGroup>
    <Message Text="INPUTS: %(Inputs.FullPath)" />
    <Message Text="OUTPUTS: @(Outputs->'%(FullPath)')" />

    <Copy SourceFiles="@(Inputs)" DestinationFiles="%(Outputs.FullPath)" />

</Target>

看起来输入的数量可能与输出的数量不同(我怀疑每个项目的输出目录中都有多个.dll文件),这也会导致目标执行.

It looks like the number of inputs may be different than the number of outputs (I suspect there is more than one .dll files in the output directory for each project), which will also cause the target to execute.

这篇关于Nuget软件包的增量构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆