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 launched.
In the Publish wizard, select Folder. In the Specific target page, select ClickOnce. Enter a path or select Browse to select the publish location. In the Install location page, select where users will install the application from.
To access this wizard, on the Build menu, choose Publish SolutionName. You can also access the Publish Wizard from Solution Explorer. Open the shortcut menu for the project node, and then choose Publish.
In Solution Explorer, right-click the application project and click Properties. The Project Designer appears. Click the Publish tab to open the Publish page in the Project Designer, and click the Publish Wizard button. The Publish Wizard appears.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With