views:

20

answers:

2

In Visual Studio 2008, can a the post build event be used with Click Once publishing? If so, how? Out of the box is looks like I can only use pre-build events and click once publishing seems to build the project to a different location, before the post build event is launched.

A: 

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.

Rory MacLeod
So my build event is to copy the correct app.config (I have a dev, test and prod version) and encrypt it. The post build event does fire (thank you) but I found does not copy this app.config into the publish manifest, it appears to select the original app.config from the project.
Brad
ClickOnce will publish anything in you project with a build action of "Content", so make sure your source app.config has a build action of None. That won't stop the app.config getting renamed to MyApp.exe.config by the build. ClickOnce will pick up the exe.config because the build lists it as an output. If you replace the exe.config in your Debug/Release folder in the BeforePublish target, ClickOnce should pick up your encrypted version.
Rory MacLeod
A: 

I think you will find this useful. It talks about having different app.config files for each type of deployment.

http://blogs.msdn.com/b/vsto/archive/2010/03/09/tricks-with-app-config-and-clickonce-deployment-saurabh-bhatia.aspx

RobinDotNet