简体   繁体   English

在每次构建时在 Visual Studio C# 中运行预构建事件,而不总是触发目标重建

[英]Run pre-build event in Visual Studio C# on every build without always triggering target rebuild

What I need我需要的

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(我正在尝试使用预构建事件),即使项目是最新的。

What I know so far:到目前为止我所知道的:

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>

The problem问题

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.

相关问题 将 C# 文件作为预构建事件运行 Visual Studio (.NET Core) - Run a C# file as a pre-build event Visual Studio (.NET Core) Visual Studio C#不会生成因预生成事件而更改的文件 - visual studio c# does not build files that were change by pre-build event 在Visual Studio 2010中预构建 - Pre-build in Visual Studio 2010 如何使用Visual Studio 2013预构建事件从构建中排除脚本? - How do i use Visual Studio 2013 Pre-Build event to exclude a script from build? 如何在C#项目中以编程方式(例如在预生成事件中)以编程方式设置Visual Studio 2015的OutDir属性? - How can I set Visual Studio 2015's OutDir property programatically, e.g. in a pre-build event, in a C# project? 有没有办法从C#中的代码中修改Visual Studio 2008或2010项目预构建事件? - Is there a way to modify Visual Studio 2008 or 2010 project pre-build events from within your code in C#? 如何以编程方式将AssemblyInfo.cs更新为预生成事件(Visual Studio / msbuild) - How to programatically update AssemblyInfo.cs as a Pre-Build event (Visual Studio / msbuild) 在 Visual Studio 的预构建中使用 webpack - Using webpack in Visual Studio's pre-build C#-在预构建事件期间注册第三方COM DLL - C# - Register a third party COM DLL during a pre-build event C#预构建事件似乎没有扩展宏符号? - C# pre-build event doesn't appear to be expanding macro symbols?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM