当< Compile>外部的文件不存在时,如何避免Visual Studio增量构建不运行.和< EmbeddedResource>被改变了吗? [英] How to avoid that Visual Studio incremental build does not run when files outside <Compile> and <EmbeddedResource> are changed?

查看:79
本文介绍了当< Compile>外部的文件不存在时,如何避免Visual Studio增量构建不运行.和< EmbeddedResource>被改变了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VS2017 csharp项目,.csproj文件如下所示:

I have a VS2017 csharp project and the .csproj file looks like the following:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <MyItem Include="file.dat" />
    </ItemGroup>

    <PropertyGroup>
        <PrepareResourcesDependsOn>
            $(PrepareResourcesDependsOn);
            MyCompileTarget
         </PrepareResourcesDependsOn>
        <CoreCompileDependsOn>
            $(CoreCompileDependsOn);
            MyCompileTarget
        </CoreCompileDependsOn>
    </PropertyGroup>

    <Target Name="MyCompileTarget" Inputs="@(MyItem)" Outputs="@(MyItem->'%(FileName).out')">
    ...
    </Target>
 </Project>

MyCompileTarget是从file.dat生成file.out的目标(在实际代码中,增量构建目标和属性位于通过NuGet软件包自动包含的目标文件中).

Where MyCompileTarget is a target that generates the file.out from file.dat (in the actual code the incremental build target and properties are in a target file automatically included via a NuGet package).

问题是,如果我更改file.dat并按 Build ,则完全没有执行目标,但 >已通过 Rebuild 或与msbuild一起运行时正确执行.我希望执行MyCompileTarget以便更新file.out文件.

The issue is that if I change file.dat and press on Build, no target is executed at all, (but MyTarget is correctly executed with Rebuild or when running with msbuild). I would expect the MyCompileTarget to be executed so that the file.out file is updated.

如果我使用BeforeBuildAfterBuild而不是PrepareResourcesDependsOn等,则会发生相同的问题.

The same issue occurs if I use BeforeBuild or AfterBuild instead of PrepareResourcesDependsOn etc.

除非更改@(Compile)@(EmbeddedResource)中的某些文件,否则Visual Studio增量构建似乎无法启动.确实,如果我添加以下内容

It seems that Visual Studio incremental build won't start unless some file in @(Compile) or @(EmbeddedResource) is changed. Indeed, if I add the following

<EmbeddedResource>file.dat</EmbeddedResource>

增量构建按预期工作(但显然我不想将file.dat嵌入到生成的程序集中).

the incremental build works as expected (but clearly I do not want to embeed the file.dat into the generated assembly).

如果修改了file.dat并且相应的生成文件早于file.dat或不存在,是否可以强制Visual Studio启用增量生成?

Is it possible to force Visual Studio to enable incremental build if file.dat is modified, and if the corresponding generated file is older than file.dat or it does not exist?

注意:使用VS2015和.NET CORE或.NET FRAMEWORK时,会发生相同的问题. 另外,如果我更改csharp文件,则将触发增量构建,因此它将触发MyTask,但仅当file.dat比生成的文件新(如预期的那样)时.

Note: the same issue occurs using VS2015, with .NET CORE or .NET FRAMEWORK. Also, incremental build will be triggered if I change a csharp file, and it will therefore trigger MyTask, but only if file.dat is newer than the generated file (as expected).

预先感谢, 法比奥.

推荐答案

如果file.dat被修改,是否可以强制Visual Studio启用增量构建

Is it possible to force Visual Studio to enable incremental build if file.dat is modified

您可以在项目文件中将属性DisableFastUpToDateCheck设置为true,以禁用Visual Studio构建管理器的FastUpToDateCheck:

You can set the property DisableFastUpToDateCheck to true in the project file to disable FastUpToDateCheck for Visual Studio build manager:

<PropertyGroup>
    <DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
</PropertyGroup>

检查有关DisableFastUpToDateCheck的 MSDN :

Check MSDN about DisableFastUpToDateCheck:

仅适用于Visual Studio的布尔值. Visual Studio 构建管理器使用名为FastUpToDateCheck的过程来确定 是否必须重建项目以保持最新状态.此过程是 比使用MSBuild确定速度更快. 设置 将DisableFastUpToDateCheck属性设置为true可让您绕过Visual Studio生成管理器,并强制其使用MSBuild来确定是否 该项目是最新的

A boolean value that applies to Visual Studio only. The Visual Studio build manager uses a process called FastUpToDateCheck to determine whether a project must be rebuilt to be up to date. This process is faster than using MSBuild to determine this. Setting the DisableFastUpToDateCheck property to true lets you bypass the Visual Studio build manager and force it to use MSBuild to determine whether the project is up to date

更新:

此外,我们可以将UpToDateCheckInput设置为以下项目:

Also, we can set the UpToDateCheckInput to the item:

<UpToDateCheckInput Include="file.dat" />

这篇关于当&lt; Compile&gt;外部的文件不存在时,如何避免Visual Studio增量构建不运行.和&lt; EmbeddedResource&gt;被改变了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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