Visual Studio:即使项目是最新的,也运行 C++ 项目生成后事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1937702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio: Run C++ project Post-Build Event even if project is up-to-date
提问by user200783
In Visual Studio (2008) is it possible to force the Post-Build Event for a C++ project to run even if the project is up-to-date?
在 Visual Studio (2008) 中,即使项目是最新的,是否可以强制运行 C++ 项目的构建后事件?
Specifically, I have a project which builds a COM in-process server DLL. The project has a post-build step which runs "regsvr32.exe $(TargetPath)". This runs fine on a "Rebuild", but runs on a "Build" only if changes have been made to the project's source.
具体来说,我有一个构建 COM 进程内服务器 DLL 的项目。该项目有一个运行“regsvr32.exe $(TargetPath)”的构建后步骤。这在“重建”上运行良好,但仅当对项目的源进行了更改时才在“构建”上运行。
If I do a "Build" without making any changes, Visual Studio simply reports that the project is up-to-date and does nothing - the Post-Build Event is not run. Is there any way that I can force the Event to run in this situation? This is necessary since although the DLL itself is up-to-date, the registration information may not be.
如果我在不做任何更改的情况下执行“构建”,Visual Studio 只会报告该项目是最新的并且什么都不做——构建后事件不会运行。有什么办法可以强制事件在这种情况下运行?这是必要的,因为尽管 DLL 本身是最新的,但注册信息可能不是。
回答by Tarydon
You can use the Custom Build Stepproperty page to set up a batch file to run. This runs if the File specified in the Outputssetting is not found, or is out-of-date. Simply specify some non-existent file there, and the custom build step will always run. It will run even if your project is up-to-date, since the Output file is never found.
您可以使用自定义构建步骤属性页来设置要运行的批处理文件。如果未找到在输出设置中指定的文件或已过期,则此操作会运行。只需在那里指定一些不存在的文件,自定义构建步骤将始终运行。即使您的项目是最新的,它也会运行,因为从未找到输出文件。
回答by diegoapereza
Use this DisableFastUpToDateCheck
使用此 DisableFastUpToDateCheck
See an example:
看一个例子:
<PropertyGroup>
<PostBuildEvent>IF EXIST C:\Projects\Copy_Files_To_Instance.ps1 ( powershell -file C:\Projects\Copy_Files_To_Instance.ps1)</PostBuildEvent>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
回答by BRebey
In Visual Studio 2017 (perhaps other versions as well), for C# projects (haven't checked for C++ projects per OP's actual question) there is an option for "Run the post-build event:", and one option is "Always", which will run the Post-Build even if nothing has changed, rather than simply reporting that the project is up to date:
在 Visual Studio 2017(也许还有其他版本)中,对于 C# 项目(尚未根据 OP 的实际问题检查 C++ 项目)有一个“运行构建后事件:”选项,一个选项是“始终” ,即使没有任何更改,它也会运行 Post-Build,而不是简单地报告项目是最新的:
回答by Igor Zevaka
The registration information is determined largely by what's in the .rgs
file. If that file changes the project will get built. I am not sure how else COM registration can change without making the project dirty. Do you mind providing more details about your particular situation?
注册信息很大程度上取决于.rgs
文件中的内容。如果该文件更改,则项目将被构建。我不确定如何在不使项目变脏的情况下更改 COM 注册。您介意提供有关您的特定情况的更多详细信息吗?