views:

182

answers:

2

We copy our production build in a separate folder using post-build events, and replace the app.config file with our production app.config. However Clickonce reads the files in bin\Release folder.

I have also tried copying all files from our custom build location to bin\Release folder in the post-build event, but app.config is still overridden (I guess clickonce re-builds the project into bin\Release).

Is it possible to tell Clickonce to read from our custom folder? Or, if that's not the right way to go, how do you handle this kind of situation?

Edit: Additional info

The post-build event script:


del /s /q /f "$(SolutionDir)Build\Client"
rmdir /s /q "$(SolutionDir)Build\Client"

if $(ConfigurationName) == Debug goto :debug
if $(ConfigurationName) == Release goto :release

:release

xcopy "$(TargetDir)*.dll" "$(SolutionDir)Build\Client\Prod\" /Y /I /R
xcopy "$(TargetDir)*MyApp.UI.Win.exe" "$(SolutionDir)Build\Client\Prod\" /Y /I /R
copy "$(TargetDir)Configs\App.Production.config" "$(SolutionDir)Build\Client\Prod\$(TargetFileName).config" /Y 

REM for clickonce
copy "$(TargetDir)Configs\App.Production.config" "$(TargetDir)$(TargetFileName).config" /Y
copy "$(TargetDir)Configs\App.Production.config" "$(TargetDir)PostBuildEventWasHere.config" /Y
del /s /q /f "$(TargetDir)\*.pdb"

goto :exit

:debug

xcopy "$(TargetDir)*.dll" "$(SolutionDir)Build\Client\Dev\" /Y /I /R
xcopy "$(TargetDir)*MyApp.UI.Win.exe" "$(SolutionDir)Build\Client\Dev\" /Y /I /R
copy "$(TargetDir)Configs\App.Development.config" "$(SolutionDir)Build\Client\Dev\$(TargetFileName).config" /Y

goto :exit

:exit

And my publish output:


------ Build started: Project: MyApp.UI.Win, Configuration: Release Any CPU ------
(...builds all projects)
Compile complete -- 0 errors, 4 warnings
(...echoing the build event script here, and successful copy/delete messages)
Building MyApp.UI.Win...
(It must be rebuilding here!)
------ Publish started: Project: MyApp.UI.Win, Configuration: Release Any CPU ------
Connecting to '\\MyPublishLocation'...
Publishing files...
Publish success.
\\MyPublishLocation\publish.htm
========== Build: 8 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
A: 

We had a case where we had different licenses for one of our dll's for debug versus release configuration. We handled it by adding both licenses to the project, and putting in a post-build command to copy the right license to the output. This resulted in our ClickOnce deployment just picking up the file that was there. You could try this with your app.config file and see if it works. Here's how we did it:

  1. Add one of the app.config files to your project, doesn't matter which one (because it's going to be replaced by the post-build copy). This ensures that it shows up in Application Files and it gets deployed.

  2. Add a folder for each configuration you want to use. For us, we called these folders license_debug and license_release. We put the licenses in their respective folders. We ended up deploying both folders so the files would be there for the post-build command.

  3. Add a post-build command that basically copies the file from the folder into the top directory. So if we did a debug build, it would copy the debug license. If we did a release build, it would copy the release license.

Here's our post-build command:

COPY/Y "$(TargetDir)license_$(ConfigurationName)*.*" "$(TargetDir)"

I don't know if this will work with app.config files, but I don't know why it wouldn't.

RobinDotNet
Thank you for the detailed answer. We have an app.config file added to the project and 3 other config files in "Configs" folder. In the post-build event (in release mode), the production app.config file from this folder is copied to the top folder just as you described.However, when I right-click on the project and publish it, the production app.config is overridden with the app.config in the top folder. I'm guessing this is because clickonce does an additional build after my post-build events are executed. Pdb files also still exist, although I delete them in the post-build event.
henginy
Note: When I build the project without publishing, everything is ok. The app.config correctly gets replaced with my production app.config. After the publish it is overridden.
henginy
This is odd, and I'll ask the ClickOnce team about it. In my experience, it builds and then creates the deployment. For us, this worked fine, but maybe it's different for app.config files.
RobinDotNet
If you go into Application Files, what is the property for the app.config file? Is it Include? And if it shows up in solution explorer, what are the properties for Build Action and Copy-to-output-directory?
RobinDotNet
In the application files, the property for MyWinApp.exe.config is "Include (Auto)". For the app.config file; copy-to-output-dir is "Do not copy" and Build Action is "none".
henginy
Btw, it does build before publish, and I'm sure post-build events are executed. (I also put a PostBuildEventWasHere.config as a check=).I'm editing my question to include the script and output.
henginy
I'll still ask the C/O team about this. The config file is probably being created with it is published (obviously). If you wanted to include it as app.config, you could set the build action to 'content' and 'copy to output directory' to 'copy always'.
RobinDotNet
I'm not able to try it again since I've moved on with another solution, but again, thank you very much.
henginy
A: 

I solved this using MSBuild and mage, using the sample below. I didn't want to use MSBuild, but I couldn't find any other way.

http://blog.gatosoft.com/PermaLink,guid,d0a0dd1e-c9ac-4fa9-a408-615454d49702.aspx

henginy