Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 295
Michael Avatar asked Apr 25 '13 21:04

Michael


People also ask

How do I enable transformation in web config?

Release. config transformation files that are created by default for the two default build configurations. You can create transformation files for custom build configurations by right-clicking the Web. config file and choosing Add Config Transforms from the context menu.

How does web config transform work?

Switching configuration based on configuration is a perfect use of transformations. Web. config transformations are implemented using a markup language called XML Document Transform - XDT for short. XDT is an XML-based document format invented by Microsoft and used to describe changes to a Web.

What is difference between web config and app config?

You can have a web. config for each folder under your web application. app. config is used for windows applications.


2 Answers

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>
like image 188
Michael Avatar answered Nov 09 '22 20:11

Michael


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>
like image 44
Vasyl Boroviak Avatar answered Nov 09 '22 19:11

Vasyl Boroviak