问题
I'm using SlowCheetah for XML transforming a bunch of config files in a project.
However, this same solution is part of a load balanced setup, where some config values differ between the different servers (two, in this case).
I have the following build configs
- Debug
- Release
- Release.Test
- Release.Prod1
- Release.Prod2
Almost everything in Release.Prod1 and Release.Prod2 is identical, except for some values in one of the config files. Is there any way I can have a file like Something.Release.Prod.Config
to be used on both of these build configs instead of having two identical files (Something.Release.Prod1.Config
and Something.Release.Prod2.Config
)?
...and to elaborate: In this case I am deploying to two environments, so one duplicated file is not really a huge crisis. What if you have ten or a hundred servers? I see no reason why a setup with a CI-server (Specifically TeamCity in this case) should not be able to do this, even though I suppose more customized setups are common in such environments.
How is this usually handled?
I suppose I can do some magic copying of files back and forth as a build step before the actual transformation happens, but this seems like a messy and overly complicated solution.
回答1:
The configuration transformations are handled by the $(Configuration) variable in the TransformsFiles.targets file.
<TransformXml Source="@(_FilesToTransformNotAppConfig->'%(FullPath)')"
Transform="%(RelativeDir)%(Filename).$(Configuration)%(Extension)"
Destination="@(_FilesToTransformNotAppConfig->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)')"
Condition=" Exists('%(RelativeDir)%(Filename).$(Configuration)%(Extension)') " />
Here, you can change $(Configuration) to be any other value, like "Environment". Then just set the "Environment" variable in your MSBuild args -
/p:Environment=Prod
This should allow you to keep your build settings and do your transforms independently.
来源:https://stackoverflow.com/questions/12670498/can-multiple-build-configs-share-one-config-transformation