Can Visual Studio post build events be used with ClickOnce publishing?
In Visual Studio 2008, can a post-build event be used with ClickOnce publishing? If so, how?
Out of the box, it looks like I can only use pre-build events and ClickOnce publishing seems to build the project to a different location, before the post build event is开发者_Python百科 launched.
Looking at the MSBuild files Visual Studio uses, the post build event is run by the Build target. If you run msbuild from the command-line and call the Publish target directly, it definitely calls Build first. If you right-click on the project in VS and click Publish, a trimmed-down target called PublishOnly gets run, on the assumption that VS has already done a build.
Your post build event should be run by Visual Studio when it automatically builds your project prior to publishing. In the Build Events tab of your project's properties, did you set the event to "run always"?
If you want to be more explicit about what happens prior to publishing, there's a BeforePublish target that Publish always looks for, whether it's run by MSBuild or Visual Studio. Edit your project file by hand, and at the bottom you'll see a couple of commented-out Target elements. Add one of your own like this:
<Target Name="BeforePublish">
<Exec Condition="'$(PostBuildEvent)' != ''"
WorkingDirectory="$(OutDir)" Command="$(PostBuildEvent)" />
</Target>
That will run the same post build event you defined in your project, but you could put any MSBuild tasks inside those Target elements.
I think you will find blog post Tricks with app.config and ClickOnce deployment useful. It talks about having different app.config
files for each type of deployment.
精彩评论