[英]Run pre-build event in Visual Studio C# on every build without always triggering target rebuild
I have an .exe that may or may not update one of my .cs files in a VS C# project.我有一个 .exe,它可能会或可能不会更新 VS C# 项目中的一个 .cs 文件。
I would like to run this .exe before every build (I am attempting with pre-build events), even if the project is up-to-date.我想在每次构建之前运行这个 .exe(我正在尝试使用预构建事件),即使项目是最新的。
When changing a project file on disk, the changes my not be taken into account until the next build, since VS caches the files in RAM.更改磁盘上的项目文件时,在下一次构建之前不会考虑这些更改,因为 VS 将文件缓存在 RAM 中。 The code below is supposed to prevent this, by always reading files from the disk (code should be added to first PropertyGroup in .csproj file)
下面的代码应该通过始终从磁盘读取文件来防止这种情况(代码应该添加到 .csproj 文件中的第一个 PropertyGroup)
<PropertyGroup>
<UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
</PropertyGroup>
In order to trigger pre-build events on every build, you can disable FastUpToDateCheck like so:为了在每次构建时触发预构建事件,您可以像这样禁用 FastUpToDateCheck:
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
When I do DisableFastUpToDateCheck true , the target is rebuild even when it is up to date, even with an empty pre-build event.当我执行DisableFastUpToDateCheck true 时,即使目标是最新的,目标也会重建,即使是空的预构建事件。 I would like my pre-build event to always run, potentially change a file and only if the file was change, or if the project was already not-up-to-date, to have the target rebuilt.
我希望我的预构建事件始终运行,可能会更改文件,并且仅当文件已更改,或者项目已经不是最新的时,才重新构建目标。
Turns out there was no issues, because VS will not actually rebuild the target (.dll) when it is up-to-date, but I've got confused by the compilation outputs:结果证明没有问题,因为 VS 不会在目标 (.dll) 处于最新状态时实际重建它,但我对编译输出感到困惑:
project -> long/path/to.dll项目 -> 长/路径/to.dll
========== Build: 1 succeeded, 0 failed, 2 up-to-date, 0 skipped ========== ========== 构建:1 成功,0 失败,2 最新,0 跳过 ==========
This message always appears, even if the resulting file is not changed (same last modified date).即使结果文件未更改(上次修改日期相同),此消息也会始终出现。
Another important note is that when building a project that is not the startup project (let's call them myproject and mystartup), the output of myproject will be written to myproject/bin as needed, but it will only be copied to mystartup/bin when you run the startup project (or rebuild).另一个重要的注意事项是,当构建一个不是启动项目的项目时(我们称它们为 myproject 和 mystartup),myproject 的输出将根据需要写入 myproject/bin,但只有在您创建时才会将其复制到 mystartup/bin运行启动项目(或重建)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.