Mariano
Mariano

Reputation: 3018

How can ClickOnce change the app.config from development to deployment one?

I have a development app.config and a deployment app.config. I need clickonce to change it on deployment.Is this posible to be done automatically?

Upvotes: 5

Views: 8750

Answers (4)

sinelaw
sinelaw

Reputation: 16553

If you don't want to re-build your application, you can try this approach that works on the deployed files directly.

As part of our testing workflow, we often setup multiple deployments of the same application with only differences in the .config file. We really don't want to have to re-publish every time we want to add a new deployment with a different config file. Since ClickOnce demands that everything will be signed and hashed, it's not possible to just change the myapp.exe.config.deploy file contents and expect everything to work. So what you can do is use mage.exe to update your manifests after you make the change.

As mentioned here, what you basically need to do is:

First, go to the "Application Files\MyApp_1_2_3_4\" directory in your deployment dir

You have to rename all the files from something.extension.deploy to something.extension

Then Run:

mage -Update "Application Files\MyApp_1_2_3_4\myapp.exe.manifest"
mage -Sign "Application Files\MyApp_1_2_3_4\myapp.exe.manifest" -CertHash my_ceritficate_thumbnail

Then rename the files back to their original names (add the .deploy extension)

Finally, run:

mage -Update MyApp.xbap -appmanifest "Application Files\MyApp_1_2_3_4\myapp.exe.manifest"
mage -Sign MyApp.xbap -CertHash my_certificate_thumbnail

Alternatively, to avoid renaming the files you can tell Visual Studio to not add the .deploy extension when publishing (go to Publish...Options in the visual studio project) and next time, when you publish, the files won't get that extension. My only guess at the danger of that is hitting firewall problems with certain users when they try to download .exe or .dll files.

Upvotes: 3

andyhammar
andyhammar

Reputation: 1443

An easy way would be to copy the app.config file in the pre-build script that you can define in the app's property page Build events.

You could do either:

1) Create a solution config used only for deploying to production, and switch on that in the script, e.g.

if  ($(ConfigurationName)) == (PublishConfig) call ReplaceAppConfig.cmd

or, if you only build the publish config on a specific machine:

2) Always run the script in the pre-build event:

call CheckAndReplaceAppConfig.cmd

and the CheckAndReplaceAppConfig.cmd would in this case have:

IF (%MACHINENAME%)==(PUBLISH_SERVER) ReplaceAppConfig.cmd

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1062745

If you are using the VS tools, then the config files are all part of the signed portion of the deployment. As such, the best way to do this is via your build tools - i.e. build a different version with dev/live/etc config files.

With 3.5SP1 you can opt out of the signing; I don't know if you can do this via the IDE - presumably you can do it if you do it manually (via mage), but this is a lot more work...

Upvotes: 0

Related Questions