Using SlowCheetah Config Transforms on Web.config in a 3.5 Web Forms app
I downloaded SlowCheetah into an old .Net 3.5 web forms application in order to add transforms to web.config.
I've used SlowCheetah with Windows Services and Console Applications to transform app.config with success in the past. In those cases, the config gets transformed and placed in the bin as ApplicationName.exe.config.
However, with this web forms application, the config file never ends up in the bin, as web forms sites are built with just .dll's dropped in the bin and IIS points to the root directory to run the site. So instead of the web.config getting included in the build process and packaged up in the bin, it's just left alone in the root location.
No transforms are being applied to the web.config in the root, which is a good thing, since the web.config in the root directory is in source control and is the file which we perform the transform on.
I would be happy with getting the web.config to be included in the build so that slowCheetah transforms it and then drops it in the bin. We would then have to manually take it out of the bin and put it back in the root level on our servers, but it would be worth it to have the transforms.
Does anyone know how to get the transforms to run against my web.config or get it included in the build process so slowCheetah can work its magic?
Thanks!
Update
I modified the properties of the web.config and it is now included in the build, however, the transformations are still not being applied to it.
Build Action: Embedded Resource
Copy to Output Director: Copy Always
Solution
I renamed the Web.config in our source control to Web.template.config and added transforms Web.template.Debug.config and Web.template.Release.config
Next, unload the project file and edit the .csproj xml adding the following elements
This creates a new Web.config file in the root directory. Woot!
<PropertyGroup>
<PrepareForRunDependsOn>
$(PrepareForRunDependsOn);
WebConfigTransform;
</PrepareForRunDependsOn>
</PropertyGroup>
<Target Name="WebConfigTransform">
<Message Text="Configuration: $(Configuration): Web.template.$(Configuration).config" />
<TransformXml Source="Web.template.config"
Transform="Web.template.$(Configuration).config"
Destination="Web.config" />
</Target>
Found a better solution - one without renaming files to .template.config.
Paste the following into your Web Forms .csproj file.
<Target Name="BeforeBuild">
<Delete Files="$(TEMP)Web.TEMP.config" />
<Copy SourceFiles="Web.config" DestinationFiles="$(TEMP)Web.TEMP.config" />
<TransformXml
Source="$(TEMP)Web.TEMP.config"
Transform="Web.$(Configuration).config"
Destination="Web.config" />
</Target>
链接地址: http://www.djcxy.com/p/62444.html