Visual Studio 2012-MSBuild增量版本无法检测到更改 [英] Visual Studio 2012 - MSBuild incremental build not detecting changes

查看:96
本文介绍了Visual Studio 2012-MSBuild增量版本无法检测到更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经自定义了一个MSBuild项目,以便默认目标是一个新的目标,其名称类似于"BuildWithExternalReference".这个新目标调用了另外两个目标.第一个是名为"BuildExternalReference"之类的自定义目标,该目标使用外部工具构建DLL.生成的DLL是对主项目的引用,该项目是使用常规的"Build"目标生成的.我已经为"BuildExternalReference"目标设置了Inputs和Outputs属性,因此Inputs引用源文件,而Outputs引用生成的DLL.

I have customised an MSBuild project so that the default target is a new target named similarly to 'BuildWithExternalReference'. This new target calls two other targets; the first is a custom target called something like 'BuildExternalReference' which builds a DLL using an external tool. The DLL that is built is a reference for the main project, which is built using the normal 'Build' target. I have setup the Inputs and Outputs attributes for the 'BuildExternalReference' target so the Inputs reference the source files and the outputs reference the resulting DLL.

在Visual Studio 2012和Visual Studio 2010中,该构造在首次调用时均可以正常工作.但是,在后续版本中,如果我更改外部源文件(由"BuildExternalReference"目标Inputs属性引用),则Visual Studio 2012只会报告生成:0成功,0失败,1最新,跳过0". Visual Studio 2010继续完美运行.此外,使用MSBuild.exe从命令行进行构建也可以正常工作.

In both Visual Studio 2012 and Visual Studio 2010 the build works correctly the first time it is invoked. However, on subsequent builds if I change the external source files (referenced by the 'BuildExternalReference' target Inputs attribute) then Visual Studio 2012 simply reports 'Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped'. Visual Studio 2010 continues to work perfectly. In addition, building from the command line with MSBuild.exe works perfectly.

我知道Visual Studio 2012中的生成系统已更改,但是找不到有关执行增量生成方式的更改的信息.

I'm aware that the build system in Visual Studio 2012 has changed, but I can't find information about changes to the way incremental builds are performed.

在Visual Studio 2012中是否进行了任何更改以导致增量生成发生更改?

Has anything changed in Visual Studio 2012 to cause incremental builds to change?

这是我正在使用的csproj文件的简化版本:

Here's a cut down version of the csproj file I'm using:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="BuildWithExternalTool" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <ExternalSourceFiles Include="..\ExternalSourceFiles\\*\*.cs" />
    <ExternalDll Include="..\ExternalSource\External.dll" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Target Name="BuildExternalTool" Inputs="@(ExternalSourceFiles);" Outputs="@(ExternalDll)">
    <Exec Command="C:\External\Path\To\Tool.exe" />
  </Target>
  <Target Name="BuildWithExternalTool">
    <CallTarget Targets="BuildExternalTool" />
    <CallTarget Targets="Build" />
  </Target>
</Project>

2012年11月1日更新

这是一个完整的自包含示例,再现了该问题:

Here's a complete self contained example which reproduces the issue:

https://skydrive.live.com/redir?resid=EA1DD6ACA92F9EFF!155& authkey =!ANhuqF_rrCgxpLE

这是一个项目的解决方案. MSBuildIssueExample \ MSBuildIssueExample.csproj文件已自定义,因此有一个自定义默认目标.此默认目标调用一个自定义目标(称为"ExternalTool"),然后调用默认的Build目标.

This is a solution with one project. The MSBuildIssueExample\MSBuildIssueExample.csproj file has been customised so there is a custom default target. This default target calls a custom target (called 'ExternalTool') and then the default Build target.

自定义的ExternalTool目标会写出一些消息以确保其正常工作,并在MSBuildIssueExample \ ExternalTool \ Output.txt文件上复制MSBuildIssueExample \ ExternalTool \ Input.txt文件的内容.

The custom ExternalTool target writes out some messages to make sure it's working, and also copies the contents of the MSBuildIssueExample\ExternalTool\Input.txt file over the MSBuildIssueExample\ExternalTool\Output.txt file.

Input.txt文件是ExternalTool目标的输入,而Output.txt是输出.

The Input.txt file is a input of the ExternalTool target, and Output.txt is an output.

要重新创建问题,请按照以下步骤操作:

To recreate the issue follow these steps:

1)在指定版本的Visual Studio中打开解决方案

1) Open the solution in the designated version of Visual Studio

2)构建一次解决方案,以确保输出相对于输入是最新的

2) Build the solution once to make sure the outputs are up to date with respect to the inputs

3)修改MSBuildIssueExample \ ExternalTool \ Input.txt,使其内容与Output.txt不匹配

3) Modify MSBuildIssueExample\ExternalTool\Input.txt so its content does not match Output.txt

4)重新构建

在Visual Studio 2010中执行此过程时,将再次调用ExternalTool目标,并且Input.txt文件将复制到Output.txt.

When you go through this process in Visual Studio 2010 the ExternalTool target will be invoked again, and the Input.txt file will be copied over Output.txt.

在Visual Studio 2012中执行此过程时,即使输入比输出新,也不会调用ExternalTool目标,因此Input.txt的内容将不会写入Output.txt.

When you go through this process in Visual Studio 2012 the ExternalTool target will not be invoked, even though the inputs are newer than the outputs, and as a result the contents of Input.txt will not be written to Output.txt.

但是,如果您进行重建(而不只是构建),则两个版本的Visual Studio都可以正常工作.

However, if you do Rebuild (rather than just Build) then both versions of Visual Studio work as expected.

推荐答案

Microsoft的此反馈回答了以下问题:

This feedback from Microsoft answers the question:

这是由于VS 2012中的更改所致,C#/VB项目现在执行快速最新检查",这使他们可以跳过构建,而不是一直强制构建.一个缺点是,但是,快速更新检查没有考虑自定义目标,这就是为什么未检测到增量更改的原因.如果要禁用快速更新检查",请将"DISABLEFASTUPTODATECHECK"设置为在项目文件中作为MSBuild属性或在从中启动VS的环境中作为环境变量都为true."

"This is due to a change in VS 2012 where C#/VB projects now do a "fast up-to-date check" that allows them to skip the build, rather than forcing the build all the time. One downside, however, is that fast up-to-date check does not take into account custom targets, which is why your incremental change was not detected. If you wish to disable the "fast up-to-date check" please set "DISABLEFASTUPTODATECHECK" to true either as an MSBuild property in the project file or as an environment variable in the environment you launch VS from."

http://connect.microsoft.com/VisualStudio/feedback/details/770784/visual-studio-2012-msbuild-incremental-build-not-detecting-changes#details

因此,基本上,这是Visual Studio 2012中的一项重大更改,不幸的是,它似乎并没有得到很好的记录.

So basically this is a breaking change in Visual Studio 2012 that unfortunately does not seem to be documented very well.

这篇关于Visual Studio 2012-MSBuild增量版本无法检测到更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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