如何在 Visual Studio 中暂时禁用构建事件?
有没有办法暂时禁用构建前和构建后事件?
即在没有构建事件的情况下进行构建(这需要一些时间,但运行并不总是至关重要)
目前,我有缩小和其他一些事情正在进行,但我并不总是需要它。
Is there a way to temporarily disable pre and post build events?
i.e. build without build events (which are taking a bit of time but arent always crucial to run)
At the moment, I have minification and a couple of other things going on and I don't always need that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
禁用构建事件的最简单方法是传递空值:
The simplest way to disable the build events is passing empty values:
像最小化这样的东西只对发布版本重要。所以你可以这样跳过它:
还有一些其他的宏你可以使用,点击编辑按钮,然后宏>>按钮来查看它们。环境变量也可以测试,使用%varname%。但设置起来要困难得多。
Stuff like minimization only matters for the Release build. So you could skip it like this:
There are some other macros you can use, click the Edit button and the Macro>> button to see them. Environment variables can be tested as well, use %varname%. But are much harder to set.
我还玩了一点
msbuild foo.vcxproj /p:PreBuildEvent= /p:PostBuildEvent=
,但对我来说它不起作用,可能是因为我正在使用自定义道具文件。然而,我发现有效的是
/p:PostBuildEventUseInBuild=false
I also played a little with
msbuild foo.vcxproj /p:PreBuildEvent= /p:PostBuildEvent=
, but for me it didn't work, probably because I am using custom props files.What I found to work however was
/p:PostBuildEventUseInBuild=false
检查您的构建后事件设置。在“构建事件”选项卡上,将“运行构建后事件”组合框值更改为“当构建更新项目输出时”。仅当更新输出程序集时才会执行构建后事件。
或者
使用 MSBuild 命令构建您的解决方案(这对于多解决方案项目很有用)。
在电脑上的某个位置创建“DisableBuildEvents.msbuild”文件。
DisableBuildEvents.msbuild 内容:
在命令行中设置 CustomAfterMicrosoftCommonTargets 属性来执行 MsBuild:
注意:CustomAfterMicrosoftCommonTargets 值应该是完整路径名。
Check your post build event settings. On the "Build Events" tab change the "Run the post-build event" combo box value to "When the build updates project output". Post build events will be executed only when output assembly is updated.
OR
Use MSBuild command to build your solution (this is useful for multi-solution projects).
Create "DisableBuildEvents.msbuild" file somehere on your PC.
DisableBuildEvents.msbuild content:
Execute MsBuild with CustomAfterMicrosoftCommonTargets property set in the command line:
Note: CustomAfterMicrosoftCommonTargets value should be full path name.
通过用户设置文件禁用构建事件
此处尚未提及的另一个选项涉及修改
.vcxproj.user
文件。要禁用构建事件,请将此文件放在.vcxproj
旁边:这会将消息打印到控制台,而不是运行项目中定义的预/构建后事件。使用
标记使其正常工作非常重要。正如其他答案中提到的,还可以使用以下属性完全禁用自定义构建事件:(
请注意,此处应使用
而不是
.)这种方法的优点
Custom.After.Microsoft.Common.Targets
方法).vcxproj.user
文件放入项目目录中.user
文件)Disabling build events via the User Settings file
Another option not yet mentioned here involves modifying the
.vcxproj.user
file. To disable build events, put this file next to your.vcxproj
:This will print a message to the console instead of running pre/post-build events defined in your project. It is important to use
<ItemDefinitionGroup>
tag for it to work.As mentioned in other answers, one can also use the following properties to disable custom build events completely:
(note a
<PropertyGroup>
should be used here instead of<ItemDefinitionGroup>
.)Advantages of this approach
Custom.After.Microsoft.Common.Targets
approach).vcxproj.user
file in the project directory.user
files by default)