Visual Studio 2012 - MSBuild 增量构建未检测到更改 [英] Visual Studio 2012 - MSBuild incremental build not detecting changes

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

问题描述

我已经自定义了一个 MSBuild 项目,因此默认目标是一个类似于BuildWithExternalReference"的新目标.这个新目标调用了另外两个目标;第一个是一个名为BuildExternalReference"的自定义目标,它使用外部工具构建 DLL.构建的 DLL 是对主项目的引用,它是使用普通的构建"目标构建的.我已经为BuildExternalReference"目标设置了输入和输出属性,因此输入引用源文件,输出引用生成的 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"目标输入属性引用),那么 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="..ExternalSourceExternal.dll" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)Microsoft.CSharp.targets" />
  <Target Name="BuildExternalTool" Inputs="@(ExternalSourceFiles);" Outputs="@(ExternalDll)">
    <Exec Command="C:ExternalPathToTool.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

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

This is a solution with one project. The MSBuildIssueExampleMSBuildIssueExample.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 目标会写出一些消息以确保其正常工作,还会将 MSBuildIssueExampleExternalToolInput.txt 文件的内容复制到 MSBuildIssueExampleExternalToolOutput.txt 文件上.

The custom ExternalTool target writes out some messages to make sure it's working, and also copies the contents of the MSBuildIssueExampleExternalToolInput.txt file over the MSBuildIssueExampleExternalToolOutput.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) 修改 MSBuildIssueExampleExternalToolInput.txt 使其内容与 Output.txt 不匹配

3) Modify MSBuildIssueExampleExternalToolInput.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.

但是,如果您执行 Rebuild(而不仅仅是 Build),那么 Visual Studio 的两个版本都可以按预期工作.

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

推荐答案

这个来自微软的反馈回答了这个问题:

This feedback from Microsoft answers the question:

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

"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天全站免登陆