Visual Studio 不会触发 MSBuild [英] Visual studio doesn't trigger MSBuild

查看:60
本文介绍了Visual Studio 不会触发 MSBuild的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自己的目标文件,在构建过程中运行自定义工具生成一些 C# 代码,然后将这些代码包含在 .csproj 中.

I've created my own targets file which during the build process runs a custom tool generates some C# code which are then included in the .csproj.

我有类似的东西.

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

  <Import Project="MyTargetsFile.targets" />

  <ItemGroup>
    <XYZ Include="**\*.xyz" />
  </ItemGroup>

</Project>

如果我更改 .xyz,我遇到的问题 visual studio 确实会触发重建,因为它认为它是最新的.另一方面,如果我运行 msbuild Systems.csproj/v:diag >Build.log 它检测更改并重建项目.

The problem I encounter if that if I change the .xyz visual studio does trigger a rebuild because it considers it up to date. On the other hand if i run msbuild Systems.csproj /v:diag > Build.log it detects the changes and it rebuilds the project.

经过更多的研究,我得出的结论是,在这种情况下,VS 甚至不会触发 MSBuild.在我看来,visual studio 只检查 .cs 文件的更改并忽略其余文件.

After a bit more research I've reached the conclusion that VS doesn't not even trigger MSBuild in this case. Is seems to me that visual studio just checks just .cs files for changes and ignores the rest.

现在我的问题是,如果我对 .xyz 文件进行了更改,我该如何让 VS 触发 msbuild?

Now my question is how do I make VS trigger msbuild if I've made a change in my .xyz file?

我使用的是 Visual Studio Enterprise 2017 版本 15.6.6

更新

我知道我可以将文件的构建操作设置为 Compile 但它们包含 .xml 并且会导致错误.

I know I can set the build action for the files to Compile but they contain .xml and that causes an error.

我也知道我可以清理项目并构建,但我对增量构建感兴趣,而不是完整构建.

I also know that I can clean the project and build, but I'm interested in an incremental build not a full one.

推荐答案

经过大量的谷歌搜索后,我找到了一个解决方案,虽然不一定是最好的,但似乎可以解决问题.

After a lot of googling I've been able to find a solution, not necessarily the best, but it seems to do the job.

正如问题中所述,我的问题是 vs 没有触发 msbuild.看起来为了让 msbuild 始终运行(这并不意味着您每次都能获得完整的构建,这只是意味着您让 msbuild 决定要做什么而不是做什么),您必须添加

As stated in the question my problem was the vs was not triggering msbuild. Looks like in order to let msbuild always run (this does not mean that you get a full build eveytime, it just means you let msbuild decide what to do and not vs) you have to add

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

MSDN 说以下关于DisableFastUpToDateCheck:

仅适用于 Visual Studio 的布尔值.视觉工作室构建管理器使用称为 FastUpToDateCheck 的过程来确定是否必须重建项目才能保持最新状态.这个过程是比使用 MSBuild 来确定这一点更快.设置DisableFastUpToDateCheck 属性设置为 true 可让您绕过 VisualStudio 构建管理器并强制它使用 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.

另一种解决方法,虽然我不确定它是否适合所有人,它将构建操作设置为 嵌入式资源.

Another way to solve it although I'm not sure it's suitable for everyone, it to set the build action to Embedded resource.

这篇关于Visual Studio 不会触发 MSBuild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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