在 Visual Studio 中发布事件之后 [英] After Publish event in Visual Studio

查看:33
本文介绍了在 Visual Studio 中发布事件之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在发布事件后调用简单的任务.当我说发布"时,我的意思是在 Visual Studio 中发布,右键单击项目并按发布...".我在项目文件中包含了(导入的)目标文件,它工作正常,因为我已经在 Build 事件上对其进行了测试.我在 http://msdn.microsoft.com/en-us/library 找到/ms366724.aspx 有 AfterPublish 事件应该做我需要的,但它没有.我不确定这是否是应该在 Visual Studio 中发布时触发的同一事件,请有人澄清这一点.我的问题是如何从 Visual Studio 中发布的目标文件触发任何类型的任务?

I am trying to invoke simple task after publish event. When I say "publish", I mean publish in Visual Studio, right click on project and pressing "Publish...". I have included (Imported) targets file in project file which works fine because I have already tested it on Build event. I have found at http://msdn.microsoft.com/en-us/library/ms366724.aspx that there is AfterPublish event which should do what I need, but it doesn't. I am not sure if this is a same event which should trigger on Publish in Visual Studio, someone please clarify this. My question is how to trigger any kind of task from targets file on Publish in Visual Studio?

我在目标文件中试过这个:

I have tried this in targets file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="AfterPublish">
        <Message Label="Test"></Message>        
        <Warning Label="Test"></Warning>
    </Target>   
</Project>

我使用的是 Visual Studio 2010.

I am using Visual Studio 2010.

我实际上正在寻找任何方式来在 Visual Studio 中对发布执行某些操作.我也想添加构建事件,但我不知道如何确定它是否正在进行发布.

I am actually looking for any way to execute certain action on Publish in Visual Studio. I was also thinking of adding Build Events, but I have no idea how to determine whether it is Publish in progress or not.

@Alexey Shcherbak 感谢您的快速回复.我在我的 MSBuild 输出中得到了这个:

@Alexey Shcherbak thank you for your fast reply. I am getting this in my MSBuild output:

12/10/2012 12:29:40 AM:        Done executing task "CallTarget".
12/10/2012 12:29:40 AM:        Done building target "PipelinePreDeployCopyAllFilesToOneFolder" in project "PublishTestApp.csproj".
12/10/2012 12:29:40 AM:Done building project "PublishTestApp.csproj".
Deleting existing files...
Publishing folder /...
Publishing folder Account...
Publishing folder bin...
Publishing folder Scripts...
Publishing folder Styles...
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

所以我的任务将在 PipelinePreDeployCopyAllFilesToOneFolder 之后立即执行,但在实际处理文件之前,我认为此时尚未完成发布.当然,我确实对此进行了实际测试,因此在 MSBuild 任务中,我正在从文本文件中执行简单读取,该文件应该复制到 Publish 文件夹中,但失败了.

So my task will executes right after PipelinePreDeployCopyAllFilesToOneFolder but before actual coping of the files and I don't consider Publish being done yet at that point. Of course, I did actually test this, so in MSBuild task I was executing simple read from text file that is suppose to be copied in the Publish folder, and it failed.

推荐答案

发布上下文菜单未运行发布"目标(如果我们谈论的是发布网站,而不是发布 ClickOnce 包).

The Publish context menu isn't running "Publish" target (if we are speaking about publishing website, not publishing ClickOnce package).

如果您使用的是 VS2010 - 上下文菜单将运行PipelinePreDeployCopyAllFilesToOneFolder"目标,而在 VS2012 中(如果要切换请记住这一点)它将运行MSDeployPublish"目标.

If you are using VS2010 - context menu will run "PipelinePreDeployCopyAllFilesToOneFolder" target, and in VS2012 (keep this in mind if you are going to switch) it will run "MSDeployPublish" target.

我想你应该阅读这个问题和答案.Jez 和我提供了关于如何挂钩到 BeforeAfter 发布目标的非常全面的答案.

I suppose you should read this question and answer. Jez and I provided pretty comprehensive answer on how to hook to BeforeAfter publish target.

简而言之 - 对于 MSBuild 版本>=4.0,您可以使用这种方法

In short - for MSBuild version>=4.0 you could use this approach

<Target Name="Mytarget" AfterTargets="PipelinePreDeployCopyAllFilesToOneFolder" >
    <Message Label="Test"></Message>        
    <Warning Label="Test"></Warning>
</Target>

@Edit1:使用 CopyAllFilesToSingleFolderForPackage 而不是 PipelinePreDeployCopyAllFilesToOneFolder - 文件应在此目标之后复制.如果您只需要在 VS 上下文中启动目标时才触发目标 - 检查我发布的链接并添加更多条件 - 检查 Visual Studio 启动,如下所示 Condition="'$(BuildingInsideVisualStudio)'=='true' AND '$(VisualStudioVersion)'=='10.0'"如果您添加更多上下文,例如发布后要启动什么样的目标等 - 它可以添加更多上下文并帮助其他人理解问题

@ use CopyAllFilesToSingleFolderForPackage instead of PipelinePreDeployCopyAllFilesToOneFolder - the files should be copied after this target. If you need to fire your target only when it launched in VS context - check the link I posted and add some more conditions - to check for Visual studio launch like this Condition="'$(BuildingInsideVisualStudio)'=='true' AND '$(VisualStudioVersion)'=='10.0'" If you add more context like what kind of target do you want to launch after publishing etc. - it could add more context and help others to understand the issue

这篇关于在 Visual Studio 中发布事件之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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